Repository navigation
test: wait for stable page height before visual snapshots - #402
Conversation
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 <[email protected]>
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #402 +/- ##
=======================================
Coverage ? 47.75%
=======================================
Files ? 2
Lines ? 423
Branches ? 0
=======================================
Hits ? 202
Misses ? 221
Partials ? 0
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
There was a problem hiding this comment.
Pull request overview
This PR addresses flakiness in the Playwright-based visual regression suite by making waitForReady wait for post-MathJax layout stabilization before taking full-page screenshots, preventing intermittent height mismatches on math-heavy fixtures after the Playwright/Chromium bump.
Changes:
- Enhanced
waitForReadyto wait for web fonts to load and for document height to remain stable across consecutive polls before snapshotting. - Added a detailed changelog entry documenting the root cause (late reflow/font loading) and the updated stabilization strategy.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
tests/visual/theme.spec.ts |
Replaces a fixed post-typeset sleep with font readiness + stable-height polling to reduce screenshot dimension flakiness. |
CHANGELOG.md |
Documents the CI stabilization for flaky mobile-chrome visual tests on math-heavy pages. |
🎭 Visual Regression Test ResultsDetails
Skipped testsdesktop-chrome › theme.spec.ts › Visual Regression Tests › prob-matrix - full page screenshot |
…unction options - Update the waitForReady doc comment: pages without MathJax no longer return immediately; the font and height-stability waits apply to all pages. - Give the document.fonts.ready wait the same explicit 15s timeout as the other gates, via waitForFunction instead of evaluate. - Fix a latent bug the second comment surfaced: waitForFunction's second positional parameter is arg, not options, so the existing timeout (and the new polling interval) were never applied. Options now go in the third position on all three waits, making polling: 250 effective. Co-Authored-By: Claude Fable 5 <[email protected]>
Summary
Fixes the flaky
visualjob seen onmainafter #400 merged (failing run — passed on re-run with no code change).The flake
After the Playwright 1.57→1.60 (Chromium) bump,
mobile-chromefull-page screenshots of math-heavy fixtures (math,proofs,cross-references) intermittently rendered ~60px shorter than baseline (2888–2891px vs 2950px), with the height varying even between retries of the same run.toHaveScreenshotfails outright on any dimension mismatch before pixel tolerances apply, so themaxDiffPixelRatio: 0.05these pages already have never helped.Root cause: MathJax's
startup.promiseresolving doesn't mean layout is final — font loading and late reflow can still shift total page height. The fixedwaitForTimeout(500)was a race that Chromium's new timing made lossy.The fix
waitForReadynow, after the existing MathJax wait:document.fonts.ready, andThis targets the observed failure mode directly while keeping full-page coverage on all three affected pages (rather than the
fullPage: falseescape hatch, which sacrifices coverage). Baselines are intentionally not regenerated — the passing runs show 2950px is still the settled height; re-snapshotting mid-flake would just capture a coin flip.Verification
visualjob on this PR runs the full suite with the new wait.🤖 Generated with Claude Code