From 5112abc1d2e951d777696c5505c194798789f530 Mon Sep 17 00:00:00 2001 From: Pavel Feldman Date: Thu, 9 Feb 2023 08:49:51 -0800 Subject: [PATCH] chore: fix a racy time-based test (#20783) --- packages/playwright-test/src/index.ts | 4 ++-- tests/playwright-test/timeout.spec.ts | 7 ++++--- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/packages/playwright-test/src/index.ts b/packages/playwright-test/src/index.ts index 5685cd0272..89f37ef5b6 100644 --- a/packages/playwright-test/src/index.ts +++ b/packages/playwright-test/src/index.ts @@ -517,10 +517,10 @@ const playwrightFixtures: Fixtures = ({ _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) { diff --git a/tests/playwright-test/timeout.spec.ts b/tests/playwright-test/timeout.spec.ts index 52760f593a..2d913c5138 100644 --- a/tests/playwright-test/timeout.spec.ts +++ b/tests/playwright-test/timeout.spec.ts @@ -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 }) => {