mirror of
https://github.com/microsoft/playwright.git
synced 2024-12-14 05:37:20 +03:00
chore: fix context reuse disposal (#20876)
Fixes: https://github.com/microsoft/playwright/issues/20409
This commit is contained in:
parent
42c606e181
commit
798696a18a
@ -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);
|
||||
|
@ -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);
|
||||
});
|
||||
|
Loading…
Reference in New Issue
Block a user