From 5fbd10348a23948237956250be8d90e5a2e21e11 Mon Sep 17 00:00:00 2001 From: Isaiah Odhner Date: Mon, 1 Jul 2024 01:08:48 -0400 Subject: [PATCH] Fix flaky test of screensaver animation --- tests/screensavers.spec.ts | 22 +++++++++++++++------- 1 file changed, 15 insertions(+), 7 deletions(-) diff --git a/tests/screensavers.spec.ts b/tests/screensavers.spec.ts index bc8aa24a..5394530a 100644 --- a/tests/screensavers.spec.ts +++ b/tests/screensavers.spec.ts @@ -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); });