Skip to content

Commit 860604e

Browse files
mmckyclaude
andcommitted
test: wait for stable page height before visual snapshots
After the Playwright 1.57 -> 1.60 (Chromium) bump in #400, math-heavy fixture pages on mobile-chrome intermittently settled ~60px shorter than their baselines (2888-2891px vs 2950px, varying between retries of the same run). toHaveScreenshot fails on any full-page dimension mismatch before pixel tolerances apply, so these flaked regardless of the maxDiffPixelRatio already granted to math pages. waitForReady now waits for document.fonts.ready and then polls until the document height is unchanged for three consecutive 250ms polls, replacing the fixed 500ms sleep after MathJax typesetting. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
1 parent 0258896 commit 860604e

2 files changed

Lines changed: 29 additions & 1 deletion

File tree

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
88
## [Unreleased]
99

1010
### CI
11+
- **Stabilized flaky mobile-chrome visual tests on math-heavy pages** — after the Playwright 1.57→1.60 (Chromium) bump in #400, `math`/`proofs`/`cross-references` full-page screenshots intermittently rendered ~60px shorter than baseline, failing Playwright's dimension check before pixel tolerances apply. `waitForReady` now waits for `document.fonts.ready` and polls until the document height holds steady for 750ms, instead of a fixed 500ms sleep after MathJax typesetting.
1112
- **Cleared open Dependabot security alerts via `npm audit fix`**`webpack-dev-server` 5.2.2→5.2.4 (GHSA-79cf-xcqc-c78w), `shell-quote` 1.8.1→1.8.4 (GHSA-w7jw-789q-3m8p, critical), `qs` 6.14.2→6.15.2 (GHSA-q8mj-m7cp-5q26), `ws` 8.18.0→8.21.0 (GHSA-58qx-3vcg-4xpx). All transitive dev/build-time only; built theme assets unchanged. The remaining `uuid` alert (GHSA-w5hq-g745-h8pq) was dismissed as not exploitable — `sockjs` only calls `uuid.v4()`, the advisory affects `v3`/`v5`/`v6` with a caller-provided `buf`.
1213
- **Dependabot now watches npm** — added an `npm` ecosystem entry to `dependabot.yml` (monthly, grouped into a single PR) alongside the existing `github-actions` config.
1314

tests/visual/theme.spec.ts

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,14 @@ import { test, expect, Page } from "@playwright/test";
1414

1515
// Wait for the page to fully settle, including MathJax typesetting when the
1616
// page contains math. Pages without MathJax resolve immediately.
17+
//
18+
// After MathJax's startup promise resolves, font loading and late reflow
19+
// can still shift the total page height for a short window. Full-page
20+
// screenshots fail outright on any dimension mismatch (before pixel
21+
// tolerances apply), so a fixed post-typeset delay isn't enough: math-heavy
22+
// pages were observed settling ~60px apart between runs on mobile-chrome.
23+
// Instead of sleeping, wait for web fonts and then require the document
24+
// height to hold steady across consecutive polls.
1725
async function waitForReady(page: Page) {
1826
await page.waitForLoadState("networkidle");
1927
await page.waitForFunction(
@@ -24,7 +32,26 @@ async function waitForReady(page: Page) {
2432
},
2533
{ timeout: 15000 }
2634
);
27-
await page.waitForTimeout(500);
35+
await page.evaluate(() => document.fonts.ready.then(() => true));
36+
// Stable means three consecutive 250ms polls (750ms) without the
37+
// document height changing.
38+
await page.waitForFunction(
39+
() => {
40+
const w = window as any;
41+
const height = Math.max(
42+
document.body.scrollHeight,
43+
document.documentElement.scrollHeight
44+
);
45+
if (w.__qeLastHeight === height) {
46+
w.__qeStablePolls = (w.__qeStablePolls ?? 0) + 1;
47+
} else {
48+
w.__qeLastHeight = height;
49+
w.__qeStablePolls = 0;
50+
}
51+
return w.__qeStablePolls >= 3;
52+
},
53+
{ timeout: 15000, polling: 250 }
54+
);
2855
}
2956

3057
// hasMath: true loosens the snapshot tolerance for that page. MathJax font

0 commit comments

Comments
 (0)