Skip to content

Playwright is a framework for Web Testing and Automation. It allows testing Chromium, Firefox and WebKit with a single API.

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

Pavel Feldman5112abc1d2e9
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<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) {
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 }) => {