提交 7bebc787 编写于 作者: P pissang

test(visual): optimize test cases

上级 8bcf63cf
......@@ -566,12 +566,12 @@ under the License.
type: 'gauge',
anchor: {
show: true,
icon: "image://https://www.apache.org/img/support-apache.jpg",
icon: "image://asset/echarts-logo.png",
size: 50,
showAbove: true
},
pointer: {
icon: "image://https://www.apache.org/img/support-apache.jpg",
icon: "image://asset/echarts-logo.png",
length: "70%"
},
detail: {formatter: '{value}%'},
......
......@@ -17,6 +17,8 @@
* under the License.
*/
// TODO: Cases that needs lots of network loading still may fail. Like bmap-xxx
const puppeteer = require('puppeteer');
const slugify = require('slugify');
const fse = require('fs-extra');
......@@ -44,13 +46,15 @@ program.parse(process.argv);
program.speed = +program.speed || 1;
program.actual = program.actual || 'local';
program.expected = program.expected || '4.2.1';
program.renderer = (program.renderer || 'canvas').toLowerCase();
program.dir = program.dir || (__dirname + '/tmp');
if (!program.tests) {
throw new Error('Tests are required');
}
if (!program.expected) {
throw new Error('Expected version is required');
}
function getScreenshotDir() {
return `${program.dir}/__screenshot__`;
......@@ -125,6 +129,26 @@ async function takeScreenshot(page, fullPage, fileUrl, desc, isExpected, minor)
};
}
async function waitForNetworkIdle(page) {
let count = 0;
const started = () => (count = count + 1);
const ended = () => (count = count - 1);
page.on('request', started);
page.on('requestfailed', ended);
page.on('requestfinished', ended);
return async (timeout = 5000) => {
while (count > 0) {
await waitTime(100);
if ((timeout = timeout - 100) < 0) {
console.error('Timeout');
}
}
page.off('request', started);
page.off('requestfailed', ended);
page.off('requestfinished', ended);
};
}
async function runTestPage(browser, testOpt, version, runtimeCode, isExpected) {
const fileUrl = testOpt.fileUrl;
......@@ -170,6 +194,9 @@ async function runTestPage(browser, testOpt, version, runtimeCode, isExpected) {
await page.exposeFunction('__VRT_MOUSE_UP__', async () => {
await page.mouse.up();
});
// await page.exposeFunction('__VRT_WAIT_FOR_NETWORK_IDLE__', async () => {
// await waitForNetworkIdle();
// });
// TODO should await exposeFunction here
const waitForScreenshot = new Promise((resolve) => {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册