Skip to content

test: wait for stable page height before visual snapshots - #402

Merged
mmcky merged 2 commits into
mainfrom
fix/visual-height-flake
Jun 10, 2026
Merged

mmcky merged 2 commits into
mainfrom
fix/visual-height-flake

Conversation

@mmcky

@mmcky mmcky commented Jun 10, 2026

Copy link
Copy Markdown
Contributor

Summary

Fixes the flaky visual job seen on main after #400 merged (failing run — passed on re-run with no code change).

The flake

After the Playwright 1.57→1.60 (Chromium) bump, mobile-chrome full-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. toHaveScreenshot fails outright on any dimension mismatch before pixel tolerances apply, so the maxDiffPixelRatio: 0.05 these pages already have never helped.

Root cause: MathJax's startup.promise resolving doesn't mean layout is final — font loading and late reflow can still shift total page height. The fixed waitForTimeout(500) was a race that Chromium's new timing made lossy.

The fix

waitForReady now, after the existing MathJax wait:

  1. awaits document.fonts.ready, and
  2. polls every 250ms until the document height is unchanged for three consecutive polls (750ms stable), with the same 15s timeout as the MathJax wait.

This targets the observed failure mode directly while keeping full-page coverage on all three affected pages (rather than the fullPage: false escape 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

  • visual job on this PR runs the full suite with the new wait.
  • I'll re-run the job a second time before merge for extra confidence, since a single green run can't distinguish "fixed" from "lucky".

🤖 Generated with Claude Code

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]>
Copilot AI review requested due to automatic review settings June 10, 2026 00:23
@github-actions

github-actions Bot commented Jun 10, 2026 •

Copy link
Copy Markdown
Contributor

@github-actions
github-actions Bot temporarily deployed to pull request June 10, 2026 00:24 Inactive
@codecov

codecov Bot commented Jun 10, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
⚠️ Please upload report for BASE (main@0258896). Learn more about missing BASE report.

Additional details and impacted files
@@           Coverage Diff           @@
##             main     #402   +/-   ##
=======================================
  Coverage        ?   47.75%           
=======================================
  Files           ?        2           
  Lines           ?      423           
  Branches        ?        0           
=======================================
  Hits            ?      202           
  Misses          ?      221           
  Partials        ?        0           
Flag Coverage Δ
pytests 47.75% <ø> (?)

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 waitForReady to 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.

Comment thread tests/visual/theme.spec.ts Resolved
Comment thread tests/visual/theme.spec.ts Resolved
@github-actions

github-actions Bot commented Jun 10, 2026 •

Copy link
Copy Markdown
Contributor

🎭 Visual Regression Test Results

passed  103 passed
skipped  3 skipped

Details

stats  106 tests across 1 suite
duration  3 minutes, 60 seconds
commit  ff234df

Skipped tests

desktop-chrome › theme.spec.ts › Visual Regression Tests › prob-matrix - full page screenshot
mobile-chrome › theme.spec.ts › Visual Regression Tests › prob-matrix - full page screenshot
mobile-chrome › theme.spec.ts › Theme Features › f-string interpolation styling

@github-actions
github-actions Bot temporarily deployed to pull request June 10, 2026 00:29 Inactive
…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]>
@github-actions
github-actions Bot temporarily deployed to pull request June 10, 2026 00:41 Inactive
@mmcky
mmcky merged commit cc05b04 into main Jun 10, 2026
11 checks passed
@mmcky
mmcky deleted the fix/visual-height-flake branch June 10, 2026 01:29

This branch was previously deployed

1 inactive deployment
pull request — ff234dfc Deployed Jun 10, 2026 by github-actions[bot]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants