test: unflake some timeout-dependent tests (#19139)

This commit is contained in:
Dmitry Gozman 2022-11-29 12:54:53 -08:00 committed by GitHub
parent 90e3194482
commit 23e02dd006
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 8 additions and 12 deletions

View file

@ -435,18 +435,14 @@ test('should respect expect.timeout', async ({ runInlineTest }) => {
test('timeout', async ({ page }) => {
await page.goto('data:text/html,<div>A</div>');
await Promise.all([
expect(page).toHaveURL('data:text/html,<div>B</div>'),
new Promise(f => setTimeout(f, 2000)).then(() => expect(true).toBe(false))
]);
const error = await expect(page).toHaveURL('data:text/html,<div>B</div>').catch(e => e);
expect(error.message).toContain('expect.toHaveURL with timeout 1000ms');
expect(error.message).toContain('data:text/html,<div>');
});
`,
}, { workers: 1 });
const output = stripAnsi(result.output);
expect(output).toContain('expect(received).toHaveURL(expected)');
expect(output).toContain('expect.toHaveURL with timeout 1000ms');
expect(result.failed).toBe(1);
expect(result.exitCode).toBe(1);
expect(result.exitCode).toBe(0);
expect(result.passed).toBe(1);
});
test('should log scale the time', async ({ runInlineTest }) => {

View file

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