提交 525b1c84 编写于 作者: P pissang

test(visual): fix actions manager. fix some runtime issue

上级 05a0c7d1
......@@ -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);
}
......
......@@ -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;
}
......
......@@ -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();
}
......
......@@ -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,
......
......@@ -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
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册