Visual Regression Testing#
Playwright-based tests capture screenshots of pages from the
quantecon-book-theme-fixtures
site and compare them against baseline snapshots to detect unintended
styling changes. The fixtures repo is a curated, stable rendering target:
the landing page, 12 synthetic pages (one per theme surface), and
real-world lecture captures that previously exposed theme bugs.
The fixtures repo is pinned to a specific commit in the theme’s CI
workflows (FIXTURES_SHA in .github/workflows/ci.yml and
.github/workflows/update-snapshots.yml), so the test input doesn’t move
between theme PRs.
Running Visual Tests#
Locally#
$ tox -e visual
This will:
Clone
quantecon-book-theme-fixtures(if not present)Check out the requested ref — defaults to
main, overridable via theFIXTURES_REFenv var (accepts SHA, branch, or tag)Build the fixtures site with
jb build .Install Playwright and Chromium
Run visual regression tests against the build
To pin to the same fixtures commit as CI for local testing:
$ FIXTURES_REF=<sha-from-ci.yml> tox -e visual
Updating Local Baselines#
$ tox -e visual-update
Local baselines are stored in tests/visual/macos/ (gitignored) and are
separate from CI baselines in tests/visual/__snapshots__/, since
screenshot rendering differs between macOS and Linux.
CI Integration#
Visual tests run as part of the ci.yml workflow on every push and PR:
Checks out the fixtures repo at
FIXTURES_SHAInstalls build deps via
pip install -r fixtures/requirements.txtInstalls the PR’s theme via
pip install .Builds the fixtures site with
jb build . --warningiserrorRuns Playwright against the build
Deploys the fixtures site to Netlify as a PR preview (reviewers can click through every fixture page with this PR’s theme applied)
Updating CI Baselines via PR Comments#
Two commands are available as PR comments:
Command |
Behavior |
|---|---|
|
Regenerates all baselines — use for styling changes |
|
Adds only missing baselines — use for new tests |
Both commands:
Check out the fixtures repo at
FIXTURES_SHABuild the fixtures site with the PR’s theme applied
Run Playwright on Ubuntu for platform-consistent snapshots
Commit updated snapshots to the PR branch
Post a summary comment on the PR
The /update-snapshots command also uploads a snapshot-update-diff artifact
with before/after images for review.
Note
issue_comment workflows always load the workflow file from the default
branch, not from the PR branch. If a PR changes update-snapshots.yml
itself, the new workflow takes effect only after that change has been
merged to main.
Bumping the fixtures pin#
To consume new fixtures (e.g. after a real-world capture is added to the fixtures repo):
Open a PR on
quantecon-book-theme-fixturesadding the page. See itsreal-world/README.mdfor capture conventions.Once merged, open a follow-up PR on this repo that bumps
FIXTURES_SHAin both workflow files and (if needed) adds a corresponding test entry intheme.spec.ts.Comment
/update-new-snapshotson that PR to seed baselines for any newly tested pages.
Test Structure#
tests/visual/
├── README.md
├── theme.spec.ts # Playwright test specifications
├── __snapshots__/ # CI baseline images (Ubuntu)
└── macos/ # Local baseline images (gitignored)
Configuration#
Visual test configuration is in playwright.config.ts at the project root.
The tox.ini [testenv:visual] and [testenv:visual-update] sections
contain the full environment setup including the fixtures-repo clone +
checkout dance and dependencies like jupyter-book, sphinx-exercise,
etc.