Skip to content

Commit

Permalink
test: unflake 'should not include trace resources from the previous c…
Browse files Browse the repository at this point in the history
…hunks' test
  • Loading branch information
mxschmitt committed Apr 9, 2024
1 parent 86cc252 commit 71fafb9
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 8 deletions.
1 change: 1 addition & 0 deletions packages/playwright-core/src/client/browserContext.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down
12 changes: 8 additions & 4 deletions packages/playwright-core/src/client/tracing.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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);
}
}
}
10 changes: 6 additions & 4 deletions tests/library/browsercontext-reuse.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 }) => {
Expand Down

0 comments on commit 71fafb9

Please sign in to comment.