chore: fix a racy time-based test (#20783)

This commit is contained in:
Pavel Feldman 2023-02-09 08:49:51 -08:00 committed by GitHub
parent 190c121e66
commit 5112abc1d2
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 6 additions and 5 deletions

View file

@ -517,10 +517,10 @@ const playwrightFixtures: Fixtures<TestFixtures, WorkerFixtures> = ({
_contextReuseMode: process.env.PW_TEST_REUSE_CONTEXT === 'when-possible' ? 'when-possible' : (process.env.PW_TEST_REUSE_CONTEXT ? 'force' : 'none'),
_reuseContext: async ({ video, _contextReuseMode }, use, testInfo) => {
_reuseContext: [async ({ video, _contextReuseMode }, use, testInfo) => {
const reuse = _contextReuseMode === 'force' || (_contextReuseMode === 'when-possible' && !shouldCaptureVideo(normalizeVideoMode(video), testInfo));
await use(reuse);
},
}, { scope: 'test', _title: 'context' } as any],
context: async ({ playwright, browser, _reuseContext, _contextFactory }, use, testInfo) => {
if (!_reuseContext) {

View file

@ -75,16 +75,16 @@ test('should respect test.setTimeout outside of the test', async ({ runInlineTes
test.setTimeout(1000);
test('fails', async ({}) => {
await new Promise(f => setTimeout(f, 1000));
await new Promise(f => setTimeout(f, 1100));
});
test('passes', async ({}) => {
await new Promise(f => setTimeout(f, 100));
});
test.describe('suite', () => {
test.setTimeout(50);
test.setTimeout(500);
test('fails', async ({}) => {
await new Promise(f => setTimeout(f, 100));
await new Promise(f => setTimeout(f, 600));
});
test('passes', async ({}) => {
});
@ -95,6 +95,7 @@ test('should respect test.setTimeout outside of the test', async ({ runInlineTes
expect(result.failed).toBe(2);
expect(result.passed).toBe(2);
expect(result.output).toContain('Test timeout of 1000ms exceeded.');
expect(result.output).toContain('Test timeout of 500ms exceeded.');
});
test('should timeout when calling test.setTimeout too late', async ({ runInlineTest }) => {