fix(tracing): make sure resetForReuse does not throw (#24415)

When trace chunk recording is in progress, calling `stop()` throws
`Error: Must stop trace file before stopping tracing`.
This commit is contained in:
Dmitry Gozman 2023-07-27 08:06:42 -07:00 committed by GitHub
parent 1b233a5ae2
commit 1754755684
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 17 additions and 0 deletions

View File

@ -113,6 +113,8 @@ export class Tracing extends SdkObject implements InstrumentationListener, Snaps
}
async resetForReuse() {
// Discard previous chunk if any and ignore any errors there.
await this.stopChunk({ mode: 'discard' }).catch(() => {});
await this.stop();
this._snapshotter?.resetForReuse();
}

View File

@ -234,3 +234,18 @@ test('should reset mouse position', async ({ reusedContext, browserName, platfor
await expect(page.locator('#one')).toHaveCSS('background-color', 'rgb(0, 0, 255)');
await expect(page.locator('#two')).toHaveCSS('background-color', 'rgb(0, 0, 255)');
});
test('should reset tracing', async ({ reusedContext }, testInfo) => {
let context = await reusedContext();
await context.tracing.start();
let page = await context.newPage();
await page.evaluate('1 + 1');
context = await reusedContext();
page = context.pages()[0];
await page.evaluate('2 + 2');
const error = await context.tracing.stopChunk({ path: testInfo.outputPath('trace.zip') }).catch(e => e);
expect(error.message).toContain('tracing.stopChunk: Must start tracing before stopping');
});