cherry-pick(#30807): chore: do not close the reused context when video is on
This commit is contained in:
parent
3867d5581b
commit
5d2623030d
|
|
@ -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 const builtInReporters = ['list', 'line', 'dot', 'json', 'junit', 'null', 'github', 'html', 'blob', 'markdown'] as const;
|
||||||
export type BuiltInReporter = typeof builtInReporters[number];
|
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 {
|
function resolveScript(id: string | undefined, rootDir: string): string | undefined {
|
||||||
if (!id)
|
if (!id)
|
||||||
|
|
|
||||||
|
|
@ -356,8 +356,8 @@ const playwrightFixtures: Fixtures<TestFixtures, WorkerFixtures> = ({
|
||||||
_reuseContext: [async ({ video, _optionContextReuseMode }, use) => {
|
_reuseContext: [async ({ video, _optionContextReuseMode }, use) => {
|
||||||
let mode = _optionContextReuseMode;
|
let mode = _optionContextReuseMode;
|
||||||
if (process.env.PW_TEST_REUSE_CONTEXT)
|
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');
|
mode = 'when-possible';
|
||||||
const reuse = mode === 'force' || (mode === 'when-possible' && normalizeVideoMode(video) === 'off');
|
const reuse = mode === 'when-possible' && normalizeVideoMode(video) === 'off';
|
||||||
await use(reuse);
|
await use(reuse);
|
||||||
}, { scope: 'worker', _title: 'context' } as any],
|
}, { scope: 'worker', _title: 'context' } as any],
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -308,6 +308,7 @@ class TestServerDispatcher implements TestServerInterface {
|
||||||
reporter: params.reporters ? params.reporters.map(r => [r]) : undefined,
|
reporter: params.reporters ? params.reporters.map(r => [r]) : undefined,
|
||||||
use: {
|
use: {
|
||||||
trace: params.trace === 'on' ? { mode: 'on', sources: false, _live: true } : (params.trace === 'off' ? 'off' : undefined),
|
trace: params.trace === 'on' ? { mode: 'on', sources: false, _live: true } : (params.trace === 'off' ? 'off' : undefined),
|
||||||
|
video: 'off',
|
||||||
headless: params.headed ? false : undefined,
|
headless: params.headed ? false : undefined,
|
||||||
_optionContextReuseMode: params.reuseContext ? 'when-possible' : undefined,
|
_optionContextReuseMode: params.reuseContext ? 'when-possible' : undefined,
|
||||||
_optionConnectOptions: params.connectWsEndpoint ? { wsEndpoint: params.connectWsEndpoint } : undefined,
|
_optionConnectOptions: params.connectWsEndpoint ? { wsEndpoint: params.connectWsEndpoint } : undefined,
|
||||||
|
|
|
||||||
|
|
@ -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();
|
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) => {
|
test('should reuse context with trace if mode=when-possible', async ({ runInlineTest }, testInfo) => {
|
||||||
const result = await runInlineTest({
|
const result = await runInlineTest({
|
||||||
'playwright.config.ts': `
|
'playwright.config.ts': `
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue