Skip to content

feat: per-platform baselines via {platform}, {os} and {browser} path tokens - #422

Open
FRSgit wants to merge 4 commits into
feat/manifestfrom
feat/platform-token
Open

FRSgit wants to merge 4 commits into
feat/manifestfrom
feat/platform-token

Conversation

@FRSgit

@FRSgit FRSgit commented Sep 22, 2026 •

Copy link
Copy Markdown
Member

This is the path-token half of the #212 story (the first half is the deterministic rendering preset in #421). Cross-OS rendering drift can't be fixed inside the browser, so imagesPath gets tokens that let you keep one set of baselines per OS and browser instead of having macOS and Linux fight over the same files.

What changed:

  • imagesPath understands three new tokens: {os} (Cypress.platform, so linux / darwin / win32), {browser} (the browser that rendered the screenshot, Cypress.browser.name today) and {platform}, which is just {os}-{browser}. Unlike {spec_path}, they can also be part of a segment, so shots-{platform} works. Custom browser names get sanitised so they're always valid directory names.
  • They're opt-in. The default imagesPath stays {spec_path}/__image_snapshots__, so nothing changes for existing users and this isn't a breaking change any more. An earlier version of this PR switched the default to {spec_path}/__image_snapshots__/{platform}; I backed that out because the plan in RENDERER-DESIGN.md is a renderer that produces the pixels in a pinned Docker image no matter where Cypress runs, which makes local-vs-CI drift disappear by construction. A per-platform default would only have made that migration harder (everybody moving their baselines twice). {platform} stays useful later for keeping several rendered browsers apart.
  • New README section "Per-platform baselines": how to opt in (expose/env/config), a .gitignore recipe for committing only the CI platform, the cleanup caveat, and a short note on where this is heading. The FAQ about browser names in filenames now just points at {browser} instead of the Commands.overwrite hack.
  • The resolver takes the token values as an argument (pathVariables) rather than reading Cypress.* itself, so the renderer can later hand it its own browser name without touching the path code.

One thing worth knowing: pluginVisualRegressionCleanupUnusedImages doesn't know about platforms. It globs the whole project, so a local macOS run with cleanup on would delete the committed Linux baselines as "unused". I documented that cleanup should only run on the platform whose baselines you commit (CI). Making the sweep platform-aware is a good follow-up but I didn't want to grow this PR.

The manifest records the same os / browser values per entry, plus a renderer block (that landed in #414, which is why this PR is based on feat/manifest; it'll retarget to feat/major-5 once that merges). matchAgainstPath is intentionally not expanded, it's an explicit file path.

Tests cover whole-segment and embedded tokens, {spec_path} staying whole-segment only, absolute unix/windows paths, sanitisation, and that another platform's screenshot doesn't count as "used" for cleanup. I didn't run the headed example on this Mac; the default path is only exercised in commands.ts, which the e2e job covers.

Refs: #212

🤖 Generated with Claude Code

… tokens

`imagesPath` gains three tokens: `{os}` (Cypress.platform), `{browser}`
(Cypress.browser.name) and `{platform}` = `{os}-{browser}`. Unlike
`{spec_path}` they can sit anywhere inside a segment; values are sanitised
so custom browser names stay valid directory names.

BREAKING CHANGE: the default `imagesPath` is now
`{spec_path}/__image_snapshots__/{platform}`, so every OS/browser
combination keeps its own baselines and local runs stop fighting with CI
images. MIGRATION.md shows how to keep the 4.x layout
(`pluginVisualRegressionImagesPath={spec_path}/__image_snapshots__`) or
move existing baselines. The example baselines move into
`linux-electron/`, which is what the CI job produces.

Refs: #212

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
FRSgit and others added 3 commits September 23, 2026 14:23
# Conflicts:
#	packages/cypress-plugin-visual-regression-diff/MIGRATION.md
The default imagesPath stays {spec_path}/__image_snapshots__, as planned in
RENDERER-DESIGN.md: once pixels come from a pinned renderer the local vs CI
drift disappears by construction, so a per-platform default would only make
that migration harder. The tokens stay available for people who want to
split baselines by OS and browser today. {browser} is documented as the
browser that rendered the screenshot, which is Cypress's browser for native
screenshots and will be the renderer's browser later. The example baselines
move back to their flat folder and the MIGRATION entry goes away since
nothing breaks any more.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
@FRSgit FRSgit changed the title feat!: per-platform baselines via {platform}, {os} and {browser} path tokens feat: per-platform baselines via {platform}, {os} and {browser} path tokens Sep 23, 2026
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.

1 participant