This is an automated email from the ASF dual-hosted git repository.

shenyi pushed a commit to branch test-autorun
in repository https://gitbox.apache.org/repos/asf/incubator-echarts.git


The following commit(s) were added to refs/heads/test-autorun by this push:
     new d4ad0f9  test: Add tests select and run control in dashboard
d4ad0f9 is described below

commit d4ad0f92c54dab356e7b4b45f4d81b0b64fdcdd6
Author: pissang <[email protected]>
AuthorDate: Thu Aug 29 22:36:32 2019 +0800

    test: Add tests select and run control in dashboard
---
 test/runTest/cli.js            | 25 +++++++++--------
 test/runTest/client/client.js  | 62 ++++++++++++++++++++++++++++++++----------
 test/runTest/client/index.html |  7 +++--
 test/runTest/serve.js          |  3 --
 4 files changed, 66 insertions(+), 31 deletions(-)

diff --git a/test/runTest/cli.js b/test/runTest/cli.js
index 69d3188..104bf5f 100644
--- a/test/runTest/cli.js
+++ b/test/runTest/cli.js
@@ -227,15 +227,15 @@ async function runTest(browser, testOpt) {
     sortScreenshots(actualShots);
 
     const results = [];
-    expectedShots.forEach(async (shot, idx) => {
+    let idx = 0;
+    for (let shot of expectedShots) {
         let expected = shot;
-        let actual = actualShots[idx];
+        let actual = actualShots[idx++];
         let {diffRatio, diffPNG} = await compareScreenshot(
             expected.screenshotPath,
             actual.screenshotPath
         );
 
-
         let diffPath = `${path.resolve(__dirname, 
getScreenshotDir())}/${shot.testName}-diff.png`;
         diffPNG.pack().pipe(fs.createWriteStream(diffPath));
 
@@ -247,7 +247,7 @@ async function runTest(browser, testOpt) {
             desc: actual.desc,
             diffRatio
         });
-    });
+    }
 
     testOpt.results = results;
     testOpt.status = 'finished';
@@ -289,19 +289,15 @@ async function start() {
     // Start a static server for puppeteer open the html test cases.
     let {broadcast, io} = serve();
 
-    open(`${origin}/test/runTest/client/index.html`);
-
     const browser = await puppeteer.launch({ /* headless: false */ });
 
     const tests = await getTestsList();
 
-    broadcast({tests});
-
     io.on('connect', socket => {
-        broadcast({tests});
+        socket.emit('update', {tests});
         // TODO Stop previous?
         socket.on('run', async testsNameList => {
-            console.log(testsNameList);
+            console.log(testsNameList.join(','));
 
             const pendingTests = tests.filter(testOpt => {
                 return testsNameList.includes(testOpt.name);
@@ -313,21 +309,26 @@ async function start() {
                 testOpt.results = [];
             }
 
-            broadcast({tests});
+            socket.emit('update', {tests});
 
             try {
                 for (let testOpt of pendingTests) {
+                    console.log('Running Test', testOpt.name);
                     await runTest(browser, testOpt);
-                    broadcast({tests});
+                    socket.emit('update', {tests});
                     writeTestsToCache(tests);
                 }
             }
             catch(e) {
                 console.log(e);
             }
+
+            socket.emit('finish');
         });
     });
 
+    console.log(`Dashboard: ${origin}/test/runTest/client/index.html`);
+    // open(`${origin}/test/runTest/client/index.html`);
 
     // runTests(browser, tests, tests);
 }
diff --git a/test/runTest/client/client.js b/test/runTest/client/client.js
index 716fdad..2b302b9 100644
--- a/test/runTest/client/client.js
+++ b/test/runTest/client/client.js
@@ -1,8 +1,9 @@
 const socket = io();
 
-function processTestsData(tests) {
-    tests.forEach(test => {
+function processTestsData(tests, oldTestsData) {
+    tests.forEach((test, idx) => {
         let passed = 0;
+        test.index = idx;
         test.results.forEach(result => {
             // Threshold?
             if (result.diffRatio < 0.001) {
@@ -19,7 +20,14 @@ function processTestsData(tests) {
         else {
             test.summary = 'warning'
         }
-        test.selected = false;
+
+        // Keep select status not change.
+        if (oldTestsData && oldTestsData[idx]) {
+            test.selected = oldTestsData[idx].selected;
+        }
+        else {
+            test.selected = false;
+        }
     });
     return tests;
 }
@@ -35,7 +43,8 @@ socket.on('connect', () => {
             searchString: '',
             running: false,
 
-            allSelected: false
+            allSelected: false,
+            lastSelectedIndex: -1
         },
         computed: {
             tests() {
@@ -60,13 +69,16 @@ socket.on('connect', () => {
                 return currentTest;
             },
 
-            isSelectAllIndeterminate() {
-                if (!this.tests.length) {
-                    return true;
-                }
-                return this.tests.some(test => {
-                    return test.selected !== this.tests[0].selected;
-                });
+            isSelectAllIndeterminate: {
+                get() {
+                    if (!this.tests.length) {
+                        return true;
+                    }
+                    return this.tests.some(test => {
+                        return test.selected !== this.tests[0].selected;
+                    });
+                },
+                set() {}
             }
         },
         methods: {
@@ -83,14 +95,33 @@ socket.on('connect', () => {
                 });
                 this.isSelectAllIndeterminate = false;
             },
+            handleSelect(idx) {
+                Vue.nextTick(() => {
+                    this.lastSelectedIndex = idx;
+                });
+            },
+            handleShiftSelect(idx) {
+                if (this.lastSelectedIndex < 0) {
+                    return;
+                }
+                let start = Math.min(this.lastSelectedIndex, idx);
+                let end = Math.max(this.lastSelectedIndex, idx);
+                let selected = !this.tests[idx].selected;   // Will change
+                for (let i = start; i < end; i++) {
+                    this.tests[i].selected = selected;
+                }
+            },
+            refreshList() {
+
+            },
             runSelectedTests() {
-                this.running = true;
                 const tests = this.fullTests.filter(test => {
                     return test.selected;
                 }).map(test => {
                     return test.name
                 });
                 if (tests.length > 0) {
+                    this.running = true;
                     socket.emit('run', tests);
                 }
             },
@@ -102,8 +133,11 @@ socket.on('connect', () => {
     });
     app.$el.style.display = 'block';
 
-    socket.on('broadcast', msg => {
-        app.fullTests = processTestsData(msg.tests);
+    socket.on('update', msg => {
+        app.fullTests = processTestsData(msg.tests, app.fullTests);
+    });
+    socket.on('finish', () => {
+        app.running = false;
     });
 
     function updateTestHash() {
diff --git a/test/runTest/client/index.html b/test/runTest/client/index.html
index e9797ec..a5b8994 100644
--- a/test/runTest/client/index.html
+++ b/test/runTest/client/index.html
@@ -32,15 +32,18 @@
                             <el-button title="Run Selected" 
@click="runSelectedTests" :loading="running" circle size="mini" type="primary" 
icon="el-icon-caret-right"></el-button>
                             <el-button v-if="running" title="Run Selected" 
@click="stopTests" circle size="mini" type="primary" 
icon="el-icon-close"></el-button>
                         </el-button-group>
+                        <el-button title="Refresh List" @click="refreshList" 
circle size="mini" type="primary" icon="el-icon-refresh"></el-button>
                     </div>
                 </div>
                 <ul class="test-list">
-                    <li v-for="test in tests"
+                    <li v-for="(test, index) in tests"
                         :title="test.name"
                         :class="{active: currentTest && currentTest.name === 
test.name}"
                         @click.self="goto(test.name)"
                     >
-                        <el-checkbox v-model="test.selected"></el-checkbox>
+                        <span @mouseup="handleSelect(index)" 
@mouseup.shift="handleShiftSelect(index)">
+                            <el-checkbox v-model="test.selected"></el-checkbox>
+                        </span>
                         <i class="el-icon-loading" v-if="test.status === 
'pending' && running"></i>
                         <el-progress
                             v-if="test.status === 'finished'"
diff --git a/test/runTest/serve.js b/test/runTest/serve.js
index 42f3ffa..1baade6 100644
--- a/test/runTest/serve.js
+++ b/test/runTest/serve.js
@@ -19,9 +19,6 @@ function serve() {
 
     const io = require('socket.io')(server);
     return {
-        broadcast(data) {
-            io.emit('broadcast', data);
-        },
         io
     }
 }


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to