test(clock): fix clock mode bots (#31472)

This commit is contained in:
Pavel Feldman 2024-06-28 11:46:28 -07:00 committed by GitHub
parent 93d147cf28
commit f46ae15500
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 14 additions and 11 deletions

View File

@ -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;
}

View File

@ -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;
});

View File

@ -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);
});

View File

@ -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 }} };