fix(reuse): serial mode with tracing should not throw (#21726)
Regressed in #19733. Fixes #21113.
This commit is contained in:
parent
a68201b491
commit
7879cf30f0
|
|
@ -239,7 +239,7 @@ const playwrightFixtures: Fixtures<TestFixtures, WorkerFixtures> = ({
|
||||||
|
|
||||||
_snapshotSuffix: [process.platform, { scope: 'worker' }],
|
_snapshotSuffix: [process.platform, { scope: 'worker' }],
|
||||||
|
|
||||||
_setupContextOptionsAndArtifacts: [async ({ playwright, _snapshotSuffix, _combinedContextOptions, _reuseContext, _artifactsDir, trace, screenshot, actionTimeout, navigationTimeout, testIdAttribute }, use, testInfo) => {
|
_setupContextOptionsAndArtifacts: [async ({ playwright, _snapshotSuffix, _combinedContextOptions, _artifactsDir, trace, screenshot, actionTimeout, navigationTimeout, testIdAttribute }, use, testInfo) => {
|
||||||
if (testIdAttribute)
|
if (testIdAttribute)
|
||||||
playwrightLibrary.selectors.setTestIdAttribute(testIdAttribute);
|
playwrightLibrary.selectors.setTestIdAttribute(testIdAttribute);
|
||||||
testInfo.snapshotSuffix = _snapshotSuffix;
|
testInfo.snapshotSuffix = _snapshotSuffix;
|
||||||
|
|
@ -376,11 +376,15 @@ const playwrightFixtures: Fixtures<TestFixtures, WorkerFixtures> = ({
|
||||||
(browserType as any)._onDidCreateContext = onDidCreateBrowserContext;
|
(browserType as any)._onDidCreateContext = onDidCreateBrowserContext;
|
||||||
(browserType as any)._onWillCloseContext = onWillCloseContext;
|
(browserType as any)._onWillCloseContext = onWillCloseContext;
|
||||||
(browserType as any)._defaultContextOptions = _combinedContextOptions;
|
(browserType as any)._defaultContextOptions = _combinedContextOptions;
|
||||||
|
const promises: Promise<void>[] = [];
|
||||||
const existingContexts = Array.from((browserType as any)._contexts) as BrowserContext[];
|
const existingContexts = Array.from((browserType as any)._contexts) as BrowserContext[];
|
||||||
if (_reuseContext)
|
for (const context of existingContexts) {
|
||||||
existingContexts.forEach(c => reusedContexts.add(c));
|
if ((context as any)[kIsReusedContext])
|
||||||
else
|
reusedContexts.add(context);
|
||||||
await Promise.all(existingContexts.map(onDidCreateBrowserContext));
|
else
|
||||||
|
promises.push(onDidCreateBrowserContext(context));
|
||||||
|
}
|
||||||
|
await Promise.all(promises);
|
||||||
}
|
}
|
||||||
{
|
{
|
||||||
(playwright.request as any)._onDidCreateContext = onDidCreateRequestContext;
|
(playwright.request as any)._onDidCreateContext = onDidCreateRequestContext;
|
||||||
|
|
@ -540,6 +544,7 @@ const playwrightFixtures: Fixtures<TestFixtures, WorkerFixtures> = ({
|
||||||
|
|
||||||
const defaultContextOptions = (playwright.chromium as any)._defaultContextOptions as BrowserContextOptions;
|
const defaultContextOptions = (playwright.chromium as any)._defaultContextOptions as BrowserContextOptions;
|
||||||
const context = await (browser as any)._newContextForReuse(defaultContextOptions);
|
const context = await (browser as any)._newContextForReuse(defaultContextOptions);
|
||||||
|
(context as any)[kIsReusedContext] = true;
|
||||||
await use(context);
|
await use(context);
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|
@ -631,6 +636,7 @@ function normalizeScreenshotMode(screenshot: PlaywrightWorkerOptions['screenshot
|
||||||
}
|
}
|
||||||
|
|
||||||
const kTracingStarted = Symbol('kTracingStarted');
|
const kTracingStarted = Symbol('kTracingStarted');
|
||||||
|
const kIsReusedContext = Symbol('kReusedContext');
|
||||||
|
|
||||||
function connectOptionsFromEnv() {
|
function connectOptionsFromEnv() {
|
||||||
const wsEndpoint = process.env.PW_TEST_CONNECT_WS_ENDPOINT;
|
const wsEndpoint = process.env.PW_TEST_CONNECT_WS_ENDPOINT;
|
||||||
|
|
|
||||||
|
|
@ -516,3 +516,38 @@ test('should not delete others contexts', async ({ runInlineTest }) => {
|
||||||
expect(result.exitCode).toBe(0);
|
expect(result.exitCode).toBe(0);
|
||||||
expect(result.passed).toBe(1);
|
expect(result.passed).toBe(1);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test('should survive serial mode with tracing and reuse', async ({ runInlineTest }, testInfo) => {
|
||||||
|
const result = await runInlineTest({
|
||||||
|
'playwright.config.ts': `
|
||||||
|
import { defineConfig } from '@playwright/test';
|
||||||
|
export default defineConfig({ use: { trace: 'on' } });
|
||||||
|
`,
|
||||||
|
'reuse.spec.ts': `
|
||||||
|
import { test, expect } from '@playwright/test';
|
||||||
|
let page;
|
||||||
|
|
||||||
|
test.describe.configure({ mode: 'serial' });
|
||||||
|
|
||||||
|
test.beforeAll(async ({ browser }) => {
|
||||||
|
page = await browser.newPage();
|
||||||
|
});
|
||||||
|
|
||||||
|
test('one', async ({}) => {
|
||||||
|
await page.setContent('<button>Click</button>');
|
||||||
|
await page.click('button');
|
||||||
|
});
|
||||||
|
|
||||||
|
test('two', async ({}) => {
|
||||||
|
await page.setContent('<input>');
|
||||||
|
await page.fill('input', 'value');
|
||||||
|
});
|
||||||
|
`,
|
||||||
|
}, { 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', 'trace.zip'))).toBe(true);
|
||||||
|
expect(fs.existsSync(testInfo.outputPath('test-results', 'reuse-two', 'trace.zip'))).toBe(true);
|
||||||
|
});
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue