Skip to content

Commit

Permalink
Fix flaky test of screensaver animation
Browse files Browse the repository at this point in the history
  • Loading branch information
1j01 committed Jul 1, 2024
1 parent 4d21cae commit 5fbd103
Showing 1 changed file with 15 additions and 7 deletions.
22 changes: 15 additions & 7 deletions tests/screensavers.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,19 @@ test('closes when pressing a key', async ({ page }) => {
test('has an animated canvas', async ({ page }) => {
const canvas = page.frameLocator('iframe').locator('#canvas-webgl');
await expect(canvas).toBeVisible();
const firstFrame = await canvas.screenshot();
await page.waitForTimeout(200);
const secondFrame = await canvas.screenshot();
await page.waitForTimeout(200);
const thirdFrame = await canvas.screenshot();
expect(secondFrame).not.toEqual(firstFrame);
expect(thirdFrame).not.toEqual(secondFrame);
expect(await canvas.evaluate((canvas: HTMLCanvasElement) => {
const frames = new Set();
return new Promise((resolve) => {
function animate() {
frames.add(canvas.toDataURL());
const uniqueFrames = frames.size;
if (uniqueFrames > 10) {
resolve(uniqueFrames);
} else {
requestAnimationFrame(animate);
}
}
animate();
});
})).toBeGreaterThan(10);
});

0 comments on commit 5fbd103

Please sign in to comment.