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/05/08 02:50:00 UTC
[echarts] branch enhance-visual-regression-test updated:
test(visual): fix actions manager. fix some runtime issue
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 525b1c8 test(visual): fix actions manager. fix some runtime issue
525b1c8 is described below
commit 525b1c840d26ec1ea07f912427b522a1f85b075b
Author: pissang <bm...@gmail.com>
AuthorDate: Fri May 7 21:02:14 2021 +0800
test(visual): fix actions manager. fix some runtime issue
---
test/runTest/cli.js | 20 +++++++++----------
test/runTest/runtime/ActionPlayback.js | 35 +++++++++++++++++-----------------
test/runTest/runtime/main.js | 2 +-
test/runTest/server.js | 2 +-
test/runTest/store.js | 14 ++++----------
5 files changed, 33 insertions(+), 40 deletions(-)
diff --git a/test/runTest/cli.js b/test/runTest/cli.js
index 9614815..e1c7f97 100644
--- a/test/runTest/cli.js
+++ b/test/runTest/cli.js
@@ -122,7 +122,7 @@ async function takeScreenshot(page, fullPage, fileUrl, desc, isExpected, minor)
};
}
-async function runActions(page, testOpt, isExpected, screenshots) {
+async function runActions(page, testOpt) {
let actions;
try {
let actContent = fs.readFileSync(path.join(__dirname, 'actions', testOpt.name + '.json'));
@@ -132,10 +132,11 @@ async function runActions(page, testOpt, isExpected, screenshots) {
// Can't find actions
return;
}
-
- await page.evaluate(async (actions) => {
- await __VST_RUN_ACTIONS__(actions);
- }, actions);
+ if (actions.length > 0) {
+ await page.evaluate(async (actions) => {
+ await __VST_RUN_ACTIONS__(actions);
+ }, actions);
+ }
}
async function runTestPage(browser, testOpt, version, runtimeCode, isExpected) {
@@ -148,7 +149,6 @@ async function runTestPage(browser, testOpt, version, runtimeCode, isExpected) {
page.setRequestInterception(true);
page.on('request', request => replaceEChartsVersion(request, version));
-
async function pageScreenshot() {
if (!program.save) {
return;
@@ -226,18 +226,18 @@ async function runTestPage(browser, testOpt, version, runtimeCode, isExpected) {
timeout: 10000
});
- let autoscreenshotTimeout;
-
+ let autoScreenshotTimeout;
+ // TODO Use waitForFunction?
await Promise.race([
waitClientScreenshot,
new Promise(resolve => {
- autoscreenshotTimeout = setTimeout(() => {
+ autoScreenshotTimeout = setTimeout(() => {
console.log(`Automatically screenshot in ${testNameFromFile(fileUrl)}`);
pageScreenshot().then(resolve)
}, 1000)
})
]);
- clearTimeout(autoscreenshotTimeout);
+ clearTimeout(autoScreenshotTimeout);
await runActions(page, testOpt, isExpected, screenshots);
}
diff --git a/test/runTest/runtime/ActionPlayback.js b/test/runTest/runtime/ActionPlayback.js
index 5732a93..690c184 100644
--- a/test/runTest/runtime/ActionPlayback.js
+++ b/test/runTest/runtime/ActionPlayback.js
@@ -68,22 +68,22 @@ export class ActionPlayback {
let self = this;
+ async function takeScreenshot() {
+ // Pause timeline when doing screenshot to avoid screenshot needs taking a while.
+ timeline.pause();
+ await __VST_ACTION_SCREENSHOT__(action);
+ timeline.resume();
+ }
+
return new Promise(resolve => {
async function tick() {
+ // Date has multiplied playbackSpeed
let current = Date.now();
let dTime = current - self._current;
- self._elapsedTime += dTime * playbackSpeed;
+ self._elapsedTime += dTime;
self._current = current;
- await self._update(
- async () => {
- // Pause timeline when doing screenshot to avoid screenshot needs taking a while.
- timeline.pause();
- await __VST_ACTION_SCREENSHOT__(action);
- timeline.resume();
- },
- playbackSpeed
- );
+ await self._update(takeScreenshot, playbackSpeed);
if (self._currentOpIndex >= self._ops.length) {
// Finished
resolve();
@@ -104,7 +104,7 @@ export class ActionPlayback {
}
}
- async _update(playbackSpeed) {
+ async _update(takeScreenshot, playbackSpeed) {
let op = this._ops[this._currentOpIndex];
if (op.time > this._elapsedTime) {
@@ -112,8 +112,7 @@ export class ActionPlayback {
return;
}
- let page = this._page;
- let takenScreenshot = false;
+ let screenshotTaken = false;
switch (op.type) {
case 'mousedown':
await __VST_MOUSE_MOVE__(op.x, op.y);
@@ -121,7 +120,7 @@ export class ActionPlayback {
break;
case 'mouseup':
await __VST_MOUSE_MOVE__(op.x, op.y);
- await page.mouse.up();
+ await __VST_MOUSE_UP__();
break;
case 'mousemove':
await __VST_MOUSE_MOVE__(op.x, op.y);
@@ -143,7 +142,7 @@ export class ActionPlayback {
break;
case 'screenshot':
await takeScreenshot();
- takenScreenshot = true;
+ screenshotTaken = true;
break;
case 'valuechange':
document.querySelector(op.selector).value = op.value;
@@ -159,14 +158,14 @@ export class ActionPlayback {
// TODO Configuration time
await waitTime(delay / playbackSpeed);
await takeScreenshot();
- takenScreenshot = true;
+ screenshotTaken = true;
this._currentOpIndex++;
}
if (this._isLastOpMousewheel && op.type !== 'mousewheel') {
// Only take screenshot after mousewheel finished
- if (!takenScreenshot) {
- takeScreenshot();
+ if (!screenshotTaken) {
+ await takeScreenshot();
}
this._isLastOpMousewheel = false;
}
diff --git a/test/runTest/runtime/main.js b/test/runTest/runtime/main.js
index 5dc592b..9d1233d 100644
--- a/test/runTest/runtime/main.js
+++ b/test/runTest/runtime/main.js
@@ -57,7 +57,7 @@ window.__VST_RUN_ACTIONS__ = async function (actions) {
timeline.resume();
const actionPlayback = new ActionPlayback();
for (let action of actions) {
- await actionPlayback.runAction(action);
+ await actionPlayback.runAction(action, __VST_PLAYBACK_SPEED__);
}
actionPlayback.stop();
}
diff --git a/test/runTest/server.js b/test/runTest/server.js
index dd42188..0f7711e 100644
--- a/test/runTest/server.js
+++ b/test/runTest/server.js
@@ -361,7 +361,6 @@ async function start() {
});
io.of('/recorder').on('connect', async socket => {
- await updateTestsList();
socket.on('saveActions', data => {
if (data.testName) {
fse.outputFile(
@@ -403,6 +402,7 @@ async function start() {
});
socket.emit('getTests', {
+ // TODO updateTestsList.
tests: getTestsList().map(test => {
return {
name: test.name,
diff --git a/test/runTest/store.js b/test/runTest/store.js
index 460457a..cc056fc 100644
--- a/test/runTest/store.js
+++ b/test/runTest/store.js
@@ -181,12 +181,14 @@ module.exports.updateTestsList = async function (
_tests.push(_testsMap[key]);
});
- const actionsMetaData = {};
+ let actionsMetaData = {};
const metaPath = path.join(__dirname, 'actions/__meta__.json');
try {
actionsMetaData = JSON.parse(fs.readFileSync(metaPath, 'utf-8'));
}
- catch(e) {}
+ catch(e) {
+ console.log(e);
+ }
_tests.forEach(testOpt => {
testOpt.actions = actionsMetaData[testOpt.name] || 0;
@@ -233,14 +235,6 @@ async function getFolderSize(dir) {
size += fs.statSync(file).size;
}
return size;
- // const statAsync = promisify(fs.stat);
- // return Promise.all(
- // files.map(file => statAsync(file))
- // ).then(sizes => {
- // return sizes.reduce((total, current) => {
- // return total + current.size;
- // }, 0)
- // });
}
/**
* Get results of all runs
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@echarts.apache.org
For additional commands, e-mail: commits-help@echarts.apache.org