From 7a588e6c720a3f419d3f4f5113acec810643fdbf Mon Sep 17 00:00:00 2001 From: Pavel Feldman Date: Wed, 15 May 2024 09:05:06 -0700 Subject: [PATCH] chore: do not close the reused context when video is on (#30807) Fixes https://github.com/microsoft/playwright/issues/30779 --- packages/playwright/src/common/config.ts | 2 +- packages/playwright/src/index.ts | 4 +-- packages/playwright/src/runner/testServer.ts | 1 + .../playwright-test/playwright.reuse.spec.ts | 29 ------------------- 4 files changed, 4 insertions(+), 32 deletions(-) diff --git a/packages/playwright/src/common/config.ts b/packages/playwright/src/common/config.ts index 7bc56cf4f6dba..d54c739726582 100644 --- a/packages/playwright/src/common/config.ts +++ b/packages/playwright/src/common/config.ts @@ -265,7 +265,7 @@ export function toReporters(reporters: BuiltInReporter | ReporterDescription[] | export const builtInReporters = ['list', 'line', 'dot', 'json', 'junit', 'null', 'github', 'html', 'blob', 'markdown'] as const; export type BuiltInReporter = typeof builtInReporters[number]; -export type ContextReuseMode = 'none' | 'force' | 'when-possible'; +export type ContextReuseMode = 'none' | 'when-possible'; function resolveScript(id: string | undefined, rootDir: string): string | undefined { if (!id) diff --git a/packages/playwright/src/index.ts b/packages/playwright/src/index.ts index 9b8b4bc55be22..0a6651f3626a5 100644 --- a/packages/playwright/src/index.ts +++ b/packages/playwright/src/index.ts @@ -356,8 +356,8 @@ const playwrightFixtures: Fixtures = ({ _reuseContext: [async ({ video, _optionContextReuseMode }, use) => { let mode = _optionContextReuseMode; if (process.env.PW_TEST_REUSE_CONTEXT) - mode = process.env.PW_TEST_REUSE_CONTEXT === 'when-possible' ? 'when-possible' : (process.env.PW_TEST_REUSE_CONTEXT ? 'force' : 'none'); - const reuse = mode === 'force' || (mode === 'when-possible' && normalizeVideoMode(video) === 'off'); + mode = 'when-possible'; + const reuse = mode === 'when-possible' && normalizeVideoMode(video) === 'off'; await use(reuse); }, { scope: 'worker', _title: 'context' } as any], diff --git a/packages/playwright/src/runner/testServer.ts b/packages/playwright/src/runner/testServer.ts index 0809bd43d7ca5..e7670c3548abc 100644 --- a/packages/playwright/src/runner/testServer.ts +++ b/packages/playwright/src/runner/testServer.ts @@ -308,6 +308,7 @@ class TestServerDispatcher implements TestServerInterface { reporter: params.reporters ? params.reporters.map(r => [r]) : undefined, use: { trace: params.trace === 'on' ? { mode: 'on', sources: false, _live: true } : (params.trace === 'off' ? 'off' : undefined), + video: 'off', headless: params.headed ? false : undefined, _optionContextReuseMode: params.reuseContext ? 'when-possible' : undefined, _optionConnectOptions: params.connectWsEndpoint ? { wsEndpoint: params.connectWsEndpoint } : undefined, diff --git a/tests/playwright-test/playwright.reuse.spec.ts b/tests/playwright-test/playwright.reuse.spec.ts index 799b6fa3d7280..0620195f65c7f 100644 --- a/tests/playwright-test/playwright.reuse.spec.ts +++ b/tests/playwright-test/playwright.reuse.spec.ts @@ -85,35 +85,6 @@ test('should not reuse context with video if mode=when-possible', async ({ runIn expect(fs.existsSync(testInfo.outputPath('test-results', 'reuse-two', 'video.webm'))).toBeFalsy(); }); -test('should reuse context and disable video if mode=force', async ({ runInlineTest }, testInfo) => { - const result = await runInlineTest({ - 'playwright.config.ts': ` - export default { - use: { video: 'on' }, - }; - `, - 'reuse.test.ts': ` - import { test, expect } from '@playwright/test'; - let lastContextGuid; - - test('one', async ({ context, page }) => { - lastContextGuid = context._guid; - await page.waitForTimeout(2000); - }); - - test('two', async ({ context, page }) => { - expect(context._guid).toBe(lastContextGuid); - await page.waitForTimeout(2000); - }); - `, - }, { workers: 1 }, { PW_TEST_REUSE_CONTEXT: '1' }); - - expect(result.exitCode).toBe(0); - expect(result.passed).toBe(2); - expect(fs.existsSync(testInfo.outputPath('test-results', 'reuse-one', 'video.webm'))).toBeFalsy(); - expect(fs.existsSync(testInfo.outputPath('test-results', 'reuse-two', 'video.webm'))).toBeFalsy(); -}); - test('should reuse context with trace if mode=when-possible', async ({ runInlineTest }, testInfo) => { const result = await runInlineTest({ 'playwright.config.ts': `