Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 15 additions & 19 deletions tests/library/page-clock.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});
});

Expand Down
Loading