Skip to content

Commit

Permalink
chore: do not close the reused context when video is on (#30807)
Browse files Browse the repository at this point in the history
Fixes #30779
  • Loading branch information
pavelfeldman committed May 15, 2024
1 parent fda9051 commit 7a588e6
Show file tree
Hide file tree
Showing 4 changed files with 4 additions and 32 deletions.
2 changes: 1 addition & 1 deletion packages/playwright/src/common/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
4 changes: 2 additions & 2 deletions packages/playwright/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -356,8 +356,8 @@ const playwrightFixtures: Fixtures<TestFixtures, WorkerFixtures> = ({
_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],

Expand Down
1 change: 1 addition & 0 deletions packages/playwright/src/runner/testServer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
29 changes: 0 additions & 29 deletions tests/playwright-test/playwright.reuse.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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': `
Expand Down

0 comments on commit 7a588e6

Please sign in to comment.