Skip to content

Commit 5d26230

Browse files
committed
cherry-pick(#30807): chore: do not close the reused context when video is on
1 parent 3867d55 commit 5d26230

File tree

4 files changed

+4
-32
lines changed

4 files changed

+4
-32
lines changed

packages/playwright/src/common/config.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -265,7 +265,7 @@ export function toReporters(reporters: BuiltInReporter | ReporterDescription[] |
265265
export const builtInReporters = ['list', 'line', 'dot', 'json', 'junit', 'null', 'github', 'html', 'blob', 'markdown'] as const;
266266
export type BuiltInReporter = typeof builtInReporters[number];
267267

268-
export type ContextReuseMode = 'none' | 'force' | 'when-possible';
268+
export type ContextReuseMode = 'none' | 'when-possible';
269269

270270
function resolveScript(id: string | undefined, rootDir: string): string | undefined {
271271
if (!id)

packages/playwright/src/index.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -356,8 +356,8 @@ const playwrightFixtures: Fixtures<TestFixtures, WorkerFixtures> = ({
356356
_reuseContext: [async ({ video, _optionContextReuseMode }, use) => {
357357
let mode = _optionContextReuseMode;
358358
if (process.env.PW_TEST_REUSE_CONTEXT)
359-
mode = process.env.PW_TEST_REUSE_CONTEXT === 'when-possible' ? 'when-possible' : (process.env.PW_TEST_REUSE_CONTEXT ? 'force' : 'none');
360-
const reuse = mode === 'force' || (mode === 'when-possible' && normalizeVideoMode(video) === 'off');
359+
mode = 'when-possible';
360+
const reuse = mode === 'when-possible' && normalizeVideoMode(video) === 'off';
361361
await use(reuse);
362362
}, { scope: 'worker', _title: 'context' } as any],
363363

packages/playwright/src/runner/testServer.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -308,6 +308,7 @@ class TestServerDispatcher implements TestServerInterface {
308308
reporter: params.reporters ? params.reporters.map(r => [r]) : undefined,
309309
use: {
310310
trace: params.trace === 'on' ? { mode: 'on', sources: false, _live: true } : (params.trace === 'off' ? 'off' : undefined),
311+
video: 'off',
311312
headless: params.headed ? false : undefined,
312313
_optionContextReuseMode: params.reuseContext ? 'when-possible' : undefined,
313314
_optionConnectOptions: params.connectWsEndpoint ? { wsEndpoint: params.connectWsEndpoint } : undefined,

tests/playwright-test/playwright.reuse.spec.ts

Lines changed: 0 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -85,35 +85,6 @@ test('should not reuse context with video if mode=when-possible', async ({ runIn
8585
expect(fs.existsSync(testInfo.outputPath('test-results', 'reuse-two', 'video.webm'))).toBeFalsy();
8686
});
8787

88-
test('should reuse context and disable video if mode=force', async ({ runInlineTest }, testInfo) => {
89-
const result = await runInlineTest({
90-
'playwright.config.ts': `
91-
export default {
92-
use: { video: 'on' },
93-
};
94-
`,
95-
'reuse.test.ts': `
96-
import { test, expect } from '@playwright/test';
97-
let lastContextGuid;
98-
99-
test('one', async ({ context, page }) => {
100-
lastContextGuid = context._guid;
101-
await page.waitForTimeout(2000);
102-
});
103-
104-
test('two', async ({ context, page }) => {
105-
expect(context._guid).toBe(lastContextGuid);
106-
await page.waitForTimeout(2000);
107-
});
108-
`,
109-
}, { workers: 1 }, { PW_TEST_REUSE_CONTEXT: '1' });
110-
111-
expect(result.exitCode).toBe(0);
112-
expect(result.passed).toBe(2);
113-
expect(fs.existsSync(testInfo.outputPath('test-results', 'reuse-one', 'video.webm'))).toBeFalsy();
114-
expect(fs.existsSync(testInfo.outputPath('test-results', 'reuse-two', 'video.webm'))).toBeFalsy();
115-
});
116-
11788
test('should reuse context with trace if mode=when-possible', async ({ runInlineTest }, testInfo) => {
11889
const result = await runInlineTest({
11990
'playwright.config.ts': `

0 commit comments

Comments
 (0)