You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@echarts.apache.org by sh...@apache.org on 2021/04/30 13:50:16 UTC

[echarts] branch enhance-visual-regression-test updated: test(visual): add report generate

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

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


The following commit(s) were added to refs/heads/enhance-visual-regression-test by this push:
     new 6ba9361  test(visual): add report generate
6ba9361 is described below

commit 6ba93610247df3adb6334e26f42e5ba5f88f6ace
Author: pissang <bm...@gmail.com>
AuthorDate: Fri Apr 30 21:49:05 2021 +0800

    test(visual): add report generate
---
 test/runTest/client/client.js | 33 ++++++++++++++++++++++------
 test/runTest/genReport.js     | 50 ++++++++++++++++---------------------------
 test/runTest/server.js        | 14 +++++++++++-
 test/runTest/store.js         | 12 +++++++----
 4 files changed, 66 insertions(+), 43 deletions(-)

diff --git a/test/runTest/client/client.js b/test/runTest/client/client.js
index 99d2f99..274fb4c 100644
--- a/test/runTest/client/client.js
+++ b/test/runTest/client/client.js
@@ -354,9 +354,12 @@ const app = new Vue({
             this.runConfig.isExpectedNightly = runResult.expectedVersion.includes('-dev.');
             this.runConfig.isActualNightly = runResult.actualVersion.includes('-dev.');
             this.runConfig.renderer = runResult.renderer;
+
+            this.showRunsDialog = false;
         },
-        genTestsRunReport(runResult) {
 
+        genTestsRunReport(runResult) {
+            socket.emit('genTestsRunReport', runResult);
         },
 
         delTestsRun(runResult) {
@@ -455,8 +458,12 @@ socket.on('abort', res => {
 socket.on('getAllTestsRuns_return', res => {
     app.testsRuns = res.runs;
 });
+socket.on('genTestsRunReport_return', res => {
+    window.open(res.reportUrl, '_blank');
+});
 
-function updateUrl(notRefresh) {
+let isFallbacking = false;
+function updateUrl(notRefresh, fallbackParams) {
     const searchUrl = assembleParams({
         test: app.currentTestName,
         runConfig: JSON.stringify(app.runConfig)
@@ -473,7 +480,10 @@ function updateUrl(notRefresh) {
                 center: true
             }).then(value => {
                 window.location.search = '?' + searchUrl;
-            }).catch(() => {});
+            }).catch(() => {
+                isFallbacking = true;
+                Object.assign(app.runConfig, fallbackParams);
+            });
         }
         else {
             window.location.search = '?' + searchUrl;
@@ -482,6 +492,17 @@ function updateUrl(notRefresh) {
 }
 
 // Only update url when version is changed.
-app.$watch('runConfig.actualVersion', () => updateUrl());
-app.$watch('runConfig.expectedVersion', () => updateUrl());
-app.$watch('runConfig.renderer', () => updateUrl());
\ No newline at end of file
+app.$watch(() => {
+    return {
+        actualVersion: app.runConfig.actualVersion,
+        expectedVersion: app.runConfig.expectedVersion,
+        renderer: app.runConfig.renderer
+    };
+}, (newVal, oldVal) => {
+    if (!isFallbacking) {
+        updateUrl(false, oldVal)
+    }
+    isFallbacking = false;
+});
+// app.$watch('runConfig.expectedVersion', () => updateUrl());
+// app.$watch('runConfig.renderer', () => updateUrl());
\ No newline at end of file
diff --git a/test/runTest/genReport.js b/test/runTest/genReport.js
index ab41f25..7c356d0 100644
--- a/test/runTest/genReport.js
+++ b/test/runTest/genReport.js
@@ -21,17 +21,10 @@
 const fs = require('fs');
 const path = require('path');
 const util = require('util');
-
-// const jimp = require('jimp');
-const marked = require('marked');
-
-const tests = JSON.parse(fs.readFileSync(
-    path.join(__dirname, 'tmp/__cache__.json'), 'utf-8'
-));
+const { RESULT_FILE_NAME } = require('./store');
 
 const readFileAsync = util.promisify(fs.readFile);
 
-
 function resolveImagePath(imageUrl) {
     if (!imageUrl) {
         return '';
@@ -108,10 +101,15 @@ async function genDetail(test) {
     };
 }
 
-async function run() {
+module.exports = async function(testDir) {
     let sections = [];
 
     let failedTest = 0;
+
+    const tests = JSON.parse(fs.readFileSync(
+        path.join(testDir, RESULT_FILE_NAME), 'utf-8'
+    ));
+
     for (let test of tests) {
         let detail = await genDetail(test);
 
@@ -119,20 +117,12 @@ async function run() {
             failedTest++;
             let title = `${failedTest}. ${test.name} (Failed ${detail.failed} / ${detail.total})`;
             console.log(title);
-    //         let sectionText = `
-    // ## ${title}
-
-    // <details>
-    //   <summary>Click to expand!</summary>
-    // ${detail.content}
-    // </details>
-    //         `;
 
             let sectionText = `
 <div style="margin-top: 100px;height: 20px;border-top: 1px solid #aaa"></div>
 <a id="${test.name}"></a>
 
-## ${title}
+<h2>${title}</h2>
 
 ${detail.content}
     `;
@@ -145,22 +135,18 @@ ${detail.content}
         }
     }
 
-    let mdText = '# Visual Regression Test Report\n\n';
-    mdText += `
+    let htmlText = '<h1> Visual Regression Test Report</h1>\n';
+    htmlText += `
 <p>Total: ${tests.length}</p>
 <p>Failed: ${failedTest}</p>
-
 `;
-    mdText += sections.map(section => {
-        return `+ [${section.title}](#${section.id}) `;
-    }).join('\n');
-    mdText += sections.map(section => section.content).join('\n\n');
-
-    fs.writeFileSync(__dirname + '/tmp-report.md', mdText, 'utf-8');
-
-    marked(mdText, { smartLists: true }, (err, res) => {
-        fs.writeFileSync(__dirname + '/tmp-report.html', res, 'utf-8');
-    });
+    htmlText += '<ul>\n' + sections.map(section => {
+        return `<li><a href="${section.id}">${section.title}</a></li>`;
+    }).join('\n') + '</ul>';
+    htmlText += sections.map(section => section.content).join('\n\n');
+
+    const file = path.join(testDir, 'report.html');
+    fs.writeFileSync(file, htmlText, 'utf-8');
+    return file;
 }
 
-run();
diff --git a/test/runTest/server.js b/test/runTest/server.js
index a73afd3..332f949 100644
--- a/test/runTest/server.js
+++ b/test/runTest/server.js
@@ -33,12 +33,14 @@ const {
     getResultBaseDir,
     getRunHash,
     getAllTestsRuns,
-    delTestsRun
+    delTestsRun,
+    RESULTS_ROOT_DIR
 } = require('./store');
 const {prepareEChartsLib, getActionsFullPath} = require('./util');
 const fse = require('fs-extra');
 const fs = require('fs');
 const open = require('open');
+const genReport = require('./genReport');
 
 function serve() {
     const server = http.createServer((request, response) => {
@@ -256,6 +258,16 @@ async function start() {
             });
         });
 
+        socket.on('genTestsRunReport', async (params) => {
+            const absPath = await genReport(
+                path.join(RESULTS_ROOT_DIR, getRunHash(params))
+            );
+            const relativeUrl = path.join('../', path.relative(__dirname, absPath));
+            socket.emit('genTestsRunReport_return', {
+                reportUrl: relativeUrl
+            });
+        });
+
         socket.on('delTestsRun', async (params) => {
             delTestsRun(params.id);
             console.log('Deleted', params.id);
diff --git a/test/runTest/store.js b/test/runTest/store.js
index 20bfc73..2d11dd2 100644
--- a/test/runTest/store.js
+++ b/test/runTest/store.js
@@ -23,7 +23,6 @@ const fs = require('fs');
 const globby = require('globby');
 const {testNameFromFile} = require('./util');
 const {blacklist, SVGBlacklist} = require('./blacklist');
-const { promisify } = require('util');
 
 let _tests = [];
 let _testsMap = {};
@@ -32,6 +31,9 @@ let _runHash = '';
 const RESULT_FILE_NAME = '__result__.json';
 const RESULTS_ROOT_DIR = path.join(__dirname, 'tmp', 'result');
 
+module.exports.RESULT_FILE_NAME = RESULT_FILE_NAME;
+module.exports.RESULTS_ROOT_DIR = RESULTS_ROOT_DIR;
+
 const TEST_HASH_SPLITTER = '__';
 
 function convertBytes(bytes) {
@@ -104,10 +106,12 @@ function getResultBaseDir() {
 module.exports.getResultBaseDir = getResultBaseDir;
 module.exports.getRunHash = getRunHash;
 
-function getCacheFilePath() {
+function getResultFilePath() {
     return path.join(getResultBaseDir(), RESULT_FILE_NAME);
 }
 
+module.exports.getResultFilePath = getResultFilePath;
+
 module.exports.getTestsList = function () {
     return _tests;
 };
@@ -128,7 +132,7 @@ module.exports.updateTestsList = async function (
     fse.ensureDirSync(getResultBaseDir());
 
     try {
-        let cachedStr = fs.readFileSync(getCacheFilePath(), 'utf-8');
+        let cachedStr = fs.readFileSync(getResultFilePath(), 'utf-8');
         const tests = JSON.parse(cachedStr);
         tests.forEach(test => {
             // In somehow tests are stopped and leave the status pending.
@@ -184,7 +188,7 @@ module.exports.updateTestsList = async function (
 };
 
 module.exports.saveTestsList = function () {
-    fse.outputFileSync(getCacheFilePath(), JSON.stringify(_tests, null, 2), 'utf-8');
+    fse.outputFileSync(getResultFilePath(), JSON.stringify(_tests, null, 2), 'utf-8');
 };
 
 module.exports.mergeTestsResults = function (testsResults) {

---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@echarts.apache.org
For additional commands, e-mail: commits-help@echarts.apache.org