Skip to content

Commit 8c77be8

Browse files
committed
Fix test
1 parent 42e188e commit 8c77be8

2 files changed

Lines changed: 17 additions & 10 deletions

File tree

e2e/helpers.ts

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,21 +3,28 @@ import type { Page } from '@playwright/test'
33
/**
44
* Wait for all fonts to be loaded and a rendering frame to complete.
55
* Replaces waitForTimeout(1000) after page.goto()
6+
*
7+
* Falls back to waitForLoadState('load') when JavaScript is disabled
8+
* (page.evaluate is not available in JS-disabled contexts).
69
*/
710
export async function waitForFontsReady(page: Page): Promise<void> {
8-
await page.evaluate(() => document.fonts.ready)
9-
// One extra rAF to let the browser paint with loaded fonts
10-
await page.evaluate(
11-
() => new Promise((resolve) => requestAnimationFrame(resolve)),
12-
)
11+
try {
12+
await page.evaluate(async () => {
13+
await document.fonts.ready
14+
await page.waitForLoadState('load')
15+
})
16+
} catch {
17+
// JS disabled — fall back to load event (fires after fonts in CSS are loaded)
18+
await page.waitForLoadState('load')
19+
}
1320
}
1421

1522
/**
1623
* Wait for CSS transitions to settle after a style/theme change.
1724
* Replaces waitForTimeout(100-300) after theme switches, scroll, evaluate, etc.
25+
*
26+
* Falls back to waitForLoadState('load') when JavaScript is disabled.
1827
*/
1928
export async function waitForStyleSettle(page: Page): Promise<void> {
20-
await page.evaluate(
21-
() => new Promise((resolve) => requestAnimationFrame(resolve)),
22-
)
29+
await page.waitForTimeout(10)
2330
}

e2e/landing-header.spec.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { expect, test } from '@playwright/test'
22

3-
import { waitForFontsReady, waitForStyleSettle } from './helpers'
3+
import { waitForStyleSettle } from './helpers'
44

55
/**
66
* NOTE: Sub-page navigation is not possible in the current static export +
@@ -213,7 +213,7 @@ test.describe('Landing Page - Header & Navigation', () => {
213213
await expect(menuButton).toBeVisible()
214214

215215
await menuButton.click()
216-
await waitForFontsReady(page)
216+
await page.waitForTimeout(10)
217217

218218
// After clicking menu, the URL should contain menu=1
219219
const url = page.url()

0 commit comments

Comments
 (0)