test: unflake a few tests (#15959)

This commit is contained in:
Dmitry Gozman 2022-07-27 11:27:53 -07:00 committed by GitHub
parent f663e5d6cc
commit a94fe361a2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 19 additions and 32 deletions

View File

@ -140,12 +140,18 @@ it('watchPosition should be notified', async ({ server, contextFactory }) => {
console.log(`lat=${coords.latitude} lng=${coords.longitude}`);
}, err => {});
});
await context.setGeolocation({ latitude: 0, longitude: 10 });
await page.waitForEvent('console', message => message.text().includes('lat=0 lng=10'));
await context.setGeolocation({ latitude: 20, longitude: 30 });
await page.waitForEvent('console', message => message.text().includes('lat=20 lng=30'));
await context.setGeolocation({ latitude: 40, longitude: 50 });
await page.waitForEvent('console', message => message.text().includes('lat=40 lng=50'));
await Promise.all([
page.waitForEvent('console', message => message.text().includes('lat=0 lng=10')),
context.setGeolocation({ latitude: 0, longitude: 10 }),
]);
await Promise.all([
page.waitForEvent('console', message => message.text().includes('lat=20 lng=30')),
context.setGeolocation({ latitude: 20, longitude: 30 }),
]);
await Promise.all([
page.waitForEvent('console', message => message.text().includes('lat=40 lng=50')),
context.setGeolocation({ latitude: 40, longitude: 50 }),
]);
const allMessages = messages.join('|');
expect(allMessages).toContain('lat=0 lng=10');

View File

@ -55,18 +55,6 @@ test.beforeAll(async function recordTrace({ browser, browserName, browserType, s
}
await doClick();
// Make sure resources arrive in a predictable order.
const htmlDone = page.waitForEvent('requestfinished', request => request.url().includes('frame.html'));
const styleDone = page.waitForEvent('requestfinished', request => request.url().includes('style.css'));
await page.route(server.PREFIX + '/frames/style.css', async route => {
await htmlDone;
await route.continue();
});
await page.route(server.PREFIX + '/frames/script.js', async route => {
await styleDone;
await route.continue();
});
await Promise.all([
page.waitForNavigation(),
page.waitForTimeout(200).then(() => page.goto(server.PREFIX + '/frames/frame.html'))
@ -99,14 +87,9 @@ test('should open simple trace viewer', async ({ showTraceViewer }) => {
/page.evaluate/,
/page.evaluate/,
/page.click"Click"/,
/page.waitForEvent/,
/page.waitForEvent/,
/page.route/,
/page.waitForNavigation/,
/page.waitForTimeout/,
/page.gotohttp:\/\/localhost:\d+\/frames\/frame.html/,
/route.continue/,
/route.continue/,
/page.setViewportSize/,
]);
});
@ -200,11 +183,9 @@ test('should have network requests', async ({ showTraceViewer }) => {
const traceViewer = await showTraceViewer([traceFile]);
await traceViewer.selectAction('http://localhost');
await traceViewer.showNetworkTab();
await expect(traceViewer.networkRequests).toHaveText([
'200GETframe.htmltext/html',
'200GETstyle.csstext/css',
'200GETscript.jsapplication/javascript',
]);
await expect(traceViewer.networkRequests).toContainText(['200GETframe.htmltext/html']);
await expect(traceViewer.networkRequests).toContainText(['200GETstyle.csstext/css']);
await expect(traceViewer.networkRequests).toContainText(['200GETscript.jsapplication/javascript']);
});
test('should show snapshot URL', async ({ page, runAndTrace, server }) => {

View File

@ -719,10 +719,10 @@ test('test.setTimeout should work separately in beforeAll', async ({ runInlineTe
});
test('passed', async () => {
console.log('\\n%%test');
await new Promise(f => setTimeout(f, 800));
await new Promise(f => setTimeout(f, 500));
});
`,
}, { timeout: '1000' });
}, { timeout: 2000 });
expect(result.exitCode).toBe(0);
expect(result.passed).toBe(1);
expect(result.output.split('\n').filter(line => line.startsWith('%%'))).toEqual([

View File

@ -145,7 +145,7 @@ test('should not override use:browserName without projects', async ({ runInlineT
`,
'a.test.ts': `
const { test } = pwt;
test('pass', async ({ page, browserName }) => {
test('pass', async ({ browserName }) => {
console.log('\\n%%browser=' + browserName);
});
`,
@ -165,7 +165,7 @@ test('should override use:browserName with --browser', async ({ runInlineTest })
`,
'a.test.ts': `
const { test } = pwt;
test('pass', async ({ page, browserName }) => {
test('pass', async ({ browserName }) => {
console.log('\\n%%browser=' + browserName);
});
`,