Skip to content

Commit

Permalink
test(clock): fix clock mode bots (#31472)
Browse files Browse the repository at this point in the history
  • Loading branch information
pavelfeldman committed Jun 28, 2024
1 parent 93d147c commit f46ae15
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 11 deletions.
10 changes: 0 additions & 10 deletions packages/playwright-core/src/client/browser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -85,16 +85,6 @@ export class Browser extends ChannelOwner<channels.BrowserChannel> implements ap
const response = forReuse ? await this._channel.newContextForReuse(contextOptions) : await this._channel.newContext(contextOptions);
const context = BrowserContext.from(response.context);
await this._browserType._didCreateContext(context, contextOptions, this._options, options.logger || this._logger);
if (!forReuse && process.env.PW_CLOCK === 'frozen') {
await this._wrapApiCall(async () => {
await context.clock.install({ time: 0 });
await context.clock.pauseAt(1000);
}, true);
} else if (!forReuse && process.env.PW_CLOCK === 'realtime') {
await this._wrapApiCall(async () => {
await context.clock.install({ time: 0 });
}, true);
}
return context;
}

Expand Down
12 changes: 12 additions & 0 deletions packages/playwright/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -274,6 +274,18 @@ const playwrightFixtures: Fixtures<TestFixtures, WorkerFixtures> = ({
contexts.set(context, contextData);
if (captureVideo)
context.on('page', page => contextData.pagesWithVideo.push(page));

if (process.env.PW_CLOCK === 'frozen') {
await (context as any)._wrapApiCall(async () => {
await context.clock.install({ time: 0 });
await context.clock.pauseAt(1000);
}, true);
} else if (process.env.PW_CLOCK === 'realtime') {
await (context as any)._wrapApiCall(async () => {
await context.clock.install({ time: 0 });
}, true);
}

return context;
});

Expand Down
2 changes: 1 addition & 1 deletion tests/page/page-clock.frozen.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,5 +23,5 @@ it('clock should be frozen', async ({ page }) => {

it('clock should be realtime', async ({ page }) => {
it.skip(process.env.PW_CLOCK !== 'realtime');
expect(await page.evaluate('Date.now()')).toBeLessThan(1000);
expect(await page.evaluate('Date.now()')).toBeLessThan(10000);
});
1 change: 1 addition & 0 deletions tests/playwright-test/reporter-html.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -294,6 +294,7 @@ for (const useIntermediateMergeReport of [false] as const) {
});

test('should include image diff when screenshot failed to generate due to animation', async ({ runInlineTest, page, showReport }) => {
test.skip(process.env.PW_CLOCK === 'frozen', 'Assumes Date.now() changes');
const result = await runInlineTest({
'playwright.config.ts': `
module.exports = { use: { viewport: { width: 200, height: 200 }} };
Expand Down

0 comments on commit f46ae15

Please sign in to comment.