chore: fix context reuse disposal (#20876)

Fixes: https://github.com/microsoft/playwright/issues/20409
This commit is contained in:
Pavel Feldman 2023-02-14 12:56:47 -08:00 committed by GitHub
parent 42c606e181
commit 798696a18a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 20 additions and 4 deletions

View File

@ -97,10 +97,6 @@ export abstract class Browser extends SdkObject {
async newContextForReuse(params: channels.BrowserNewContextForReuseParams, metadata: CallMetadata): Promise<{ context: BrowserContext, needsReset: boolean }> {
const hash = BrowserContext.reusableContextHash(params);
for (const context of this.contexts()) {
if (context !== this._contextForReuse?.context)
await context.close(metadata);
}
if (!this._contextForReuse || hash !== this._contextForReuse.hash || !this._contextForReuse.context.canResetForReuse()) {
if (this._contextForReuse)
await this._contextForReuse.context.close(metadata);

View File

@ -495,3 +495,23 @@ test('should reset tracing', async ({ runInlineTest }, testInfo) => {
]);
expect(trace2.events.some(e => e.type === 'frame-snapshot')).toBe(true);
});
test('should not delete others contexts', async ({ runInlineTest }) => {
const result = await runInlineTest({
'src/reuse.test.ts': `
const test = pwt.test.extend<{ loggedInPage: Page }>({
loggedInPage: async ({ browser }, use) => {
const page = await browser.newPage();
await use(page);
await page.close();
},
});
test("passes", async ({ loggedInPage, page }) => {
await loggedInPage.goto('data:text/plain,Hello world');
});
`,
}, { workers: 1 }, { PW_TEST_REUSE_CONTEXT: '1' });
expect(result.exitCode).toBe(0);
expect(result.passed).toBe(1);
});