From aa76cb561053966bde9ec0df54e018f4556bff1b Mon Sep 17 00:00:00 2001 From: Pavel Feldman Date: Mon, 13 Sep 2021 21:12:36 -0700 Subject: [PATCH] fix(tracing): fix tests via tracking context close state (#8906) --- tests/config/browserTest.ts | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/tests/config/browserTest.ts b/tests/config/browserTest.ts index 8e77b8d383..3ca7a4c82a 100644 --- a/tests/config/browserTest.ts +++ b/tests/config/browserTest.ts @@ -133,9 +133,11 @@ export const playwrightFixtures: Fixtures { - const contexts: BrowserContext[] = []; + const contexts = new Map(); await run(async options => { const context = await browser.newContext({ ...contextOptions, ...options }); + contexts.set(context, { closed: false }); + context.on('close', () => contexts.get(context).closed = true); if (trace) await context.tracing.start({ screenshots: true, snapshots: true }); (context as any)._csi = { @@ -146,12 +148,11 @@ export const playwrightFixtures: Fixtures newStep?.complete(error); }, }; - contexts.push(context); return context; }); - await Promise.all(contexts.map(async context => { + await Promise.all([...contexts.keys()].map(async context => { const videos = context.pages().map(p => p.video()).filter(Boolean); - if (!(context as any)._closed && trace) { + if (trace && !contexts.get(context)!.closed) { const tracePath = testInfo.outputPath('trace.zip'); await context.tracing.stop({ path: tracePath }); testInfo.attachments.push({ name: 'trace', path: tracePath, contentType: 'application/zip' });