Playwright is a framework for Web Testing and Automation. It allows testing Chromium, Firefox and WebKit with a single API.
TypeScript automationchromechromiume2e-testingelectronend-to-end-testingfirefoxjavascriptplaywrighttesttest-automationtestingtesting-toolswebwebkit
test(clock): unflake "while running" page-clock tests (#41689)
Simon Knott317210d54e18
diff --git a/tests/library/page-clock.spec.ts b/tests/library/page-clock.spec.tsindex 8d653da944..c31693f381 100644--- a/tests/library/page-clock.spec.ts+++ b/tests/library/page-clock.spec.ts@@ -399,66 +399,62 @@ it.describe('setFixedTime', () => {it.describe('while running', () => {it('should progress time', async ({ page }) => {await page.clock.install({ time: 0 });+ const startRealTime = Date.now();await page.goto('data:text/html,');await page.waitForTimeout(1000);const now = await page.evaluate(() => Date.now());+ const realElapsed = Date.now() - startRealTime;expect(now).toBeGreaterThanOrEqual(1000);- expect(now).toBeLessThanOrEqual(2000);+ expect(now).toBeLessThanOrEqual(realElapsed + 1000);});it('should runFor', async ({ page }) => {await page.clock.install({ time: 0 });+ const startRealTime = Date.now();await page.goto('data:text/html,');await page.clock.runFor(10000);const now = await page.evaluate(() => Date.now());+ const realElapsed = Date.now() - startRealTime;expect(now).toBeGreaterThanOrEqual(10000);- expect(now).toBeLessThanOrEqual(11000);+ expect(now).toBeLessThanOrEqual(10000 + realElapsed + 1000);});it('should fastForward', async ({ page }) => {await page.clock.install({ time: 0 });+ const startRealTime = Date.now();await page.goto('data:text/html,');await page.clock.fastForward(10000);const now = await page.evaluate(() => Date.now());+ const realElapsed = Date.now() - startRealTime;expect(now).toBeGreaterThanOrEqual(10000);- expect(now).toBeLessThanOrEqual(11000);- });-- it('should fastForwardTo', async ({ page }) => {- await page.clock.install({ time: 0 });- await page.goto('data:text/html,');- await page.clock.fastForward(10000);- const now = await page.evaluate(() => Date.now());- expect(now).toBeGreaterThanOrEqual(10000);- expect(now).toBeLessThanOrEqual(11000);+ expect(now).toBeLessThanOrEqual(10000 + realElapsed + 1000);});it('should pause', async ({ page }) => {await page.clock.install({ time: 0 });await page.goto('data:text/html,');- await page.clock.pauseAt(1000);+ await page.clock.pauseAt(60000);// Internally wait to make sure the clock is paused and not running.await page.waitForTimeout(1111);const now = await page.evaluate(() => Date.now());- expect(now).toBeGreaterThanOrEqual(0);- expect(now).toBeLessThanOrEqual(1000);+ expect(now).toBe(60000);});it('should pause and fastForward', async ({ page }) => {await page.clock.install({ time: 0 });await page.goto('data:text/html,');- await page.clock.pauseAt(1000);+ await page.clock.pauseAt(60000);await page.clock.fastForward(1000);const now = await page.evaluate(() => Date.now());- expect(now).toBe(2000);+ expect(now).toBe(61000);});it('should set system time on pause', async ({ page }) => {await page.clock.install({ time: 0 });await page.goto('data:text/html,');- await page.clock.pauseAt(1000);+ await page.clock.pauseAt(60000);const now = await page.evaluate(() => Date.now());- expect(now).toBe(1000);+ expect(now).toBe(60000);});});