test: unflake 'should not include trace resources from the previous chunks' test

This commit is contained in:
Max Schmitt 2024-04-09 21:54:35 +02:00
parent 86cc252da2
commit 6e245ed33e
3 changed files with 15 additions and 8 deletions

View file

@ -432,6 +432,7 @@ export class BrowserContext extends ChannelOwner<channels.BrowserContextChannel>
this._browser._contexts.delete(this);
this._browserType?._contexts?.delete(this);
this._disposeHarRouters();
this.tracing._resetStackCounterIfNeeded();
this.emit(Events.BrowserContext.Close, this);
}

View file

@ -76,10 +76,7 @@ export class Tracing extends ChannelOwner<channels.TracingChannel> implements ap
}
private async _doStopChunk(filePath: string | undefined) {
if (this._isTracing) {
this._isTracing = false;
this._connection.setIsTracing(false);
}
this._resetStackCounterIfNeeded();
if (!filePath) {
// Not interested in artifacts.
@ -113,4 +110,11 @@ export class Tracing extends ChannelOwner<channels.TracingChannel> implements ap
await this._connection.localUtils()._channel.zip({ zipFile: filePath, entries: [], mode: 'append', stacksId: this._stacksId, includeSources: this._includeSources });
}
_resetStackCounterIfNeeded() {
if (this._isTracing) {
this._isTracing = false;
this._connection.setIsTracing(false);
}
}
}

View file

@ -17,17 +17,19 @@
import { browserTest, expect } from '../config/browserTest';
import type { BrowserContext, BrowserContextOptions } from '@playwright/test';
const test = browserTest.extend<{ reusedContext: (options?: BrowserContextOptions) => Promise<BrowserContext> }>({
reusedContext: async ({ browserType, browser }, use) => {
const test = browserTest.extend<{}, { reusedContext: (options?: BrowserContextOptions) => Promise<BrowserContext> }>({
reusedContext: [async ({ browserType, browser }, use) => {
let context;
await use(async (options: BrowserContextOptions = {}) => {
const defaultContextOptions = (browserType as any)._defaultContextOptions;
const context = await (browser as any)._newContextForReuse({
context = await (browser as any)._newContextForReuse({
...defaultContextOptions,
...options,
});
return context;
});
},
await context.close();
}, { scope: 'worker' }],
});
test('should re-add binding after reset', async ({ reusedContext }) => {