Visual regression testing — screenshot tests of components and pages against approved baselines, choosing what to snapshot (catalogue states, key screens, themes, viewports), deterministic rendering (fonts, animations, time, data, network), a pinned rendering environment, diff thresholds and masking, baseline review and updates in PRs, triage of real changes vs flakiness. Use to catch unintended UI changes in CI (visual regression, screenshot testing, snapshot, baseline, pixel diff, visual te...
Installs into .claude/skills of the current project.
Sponsors
SSkills DirectorySkills Directory
Know which skills are safe — weekly.
SSkills DirectorySkills Directory
Is that skill safe to install?
Are you the author of Visual Regression Testing?
Add the live security badge to your README. It updates with every re-scan.
[](https://www.skillsdirectory.com/skills/vectora-os-visual-regression-testing)
---
name: visual-regression-testing
description: Visual regression testing — screenshot tests of components and pages against approved baselines, choosing what to snapshot (catalogue states, key screens, themes, viewports), deterministic rendering (fonts, animations, time, data, network), a pinned rendering environment, diff thresholds and masking, baseline review and updates in PRs, triage of real changes vs flakiness. Use to catch unintended UI changes in CI (visual regression, screenshot testing, snapshot, baseline, pixel diff, visual testing).
metadata:
category: quality
---
# Visual regression testing
## Purpose
Catch unintended changes in how the UI looks — the defects unit, E2E and accessibility checks pass straight through: a shifted layout, a lost state style, a broken theme.
**Use when:** setting up or maintaining screenshot tests, reviewing visual diffs in a PR, investigating flaky snapshots.
**Not for:** behaviour of user journeys (`e2e-testing`), WCAG checks (`accessibility`), deciding whether a design is good (`ui-design`).
## Inputs
- Component catalogue or fixtures, key screens, target themes and viewports.
- The test runner and rendering environment the project already uses; a new tool or service is an ADR.
## Outputs
- Screenshot tests and committed or stored baselines.
- A CI job that fails on unapproved diffs and publishes the diff images.
- Triage notes for each diff: intended change, regression or flakiness.
## Read first
- [Project Brain](../../../project-brain/README.md) — `npm run brain -- query "visual regression"` for prior decisions, patterns and anti-patterns.
- [Testing standard](../../../standards/testing.md)
- [Design system](../design-system/SKILL.md) — the catalogue whose states are the first snapshot targets.
- [UI design](../ui-design/SKILL.md) — the state contract the snapshots cover.
## Steps
1. **Select.** Snapshot components in isolation first: each variant and state from the catalogue, in each theme. Add full pages only for key screens and layouts, at the smallest and largest target viewport. Skip what is covered better elsewhere (text content, behaviour).
Done when each snapshot maps to a component state or a key screen, and the count is justified.
2. **Make rendering deterministic.** Bundle and preload fonts; disable animations, transitions and caret blink; freeze time and random values; use fixed synthetic data; stub network calls and remote images; wait for fonts and layout to settle, not for a fixed delay.
Done when the same commit produces identical screenshots, or differences within the documented per-snapshot threshold, in several consecutive runs.
3. **Pin the environment.** Render in one fixed environment (a container image or a pinned browser version, fixed device scale factor and locale), the same locally and in CI. Baselines from a different environment are invalid. Changing the environment (new image, browser version or fonts) regenerates all baselines in a dedicated PR with no UI or code changes: first render the old commit in the new environment, compare it with the old baselines and explain every difference, then commit the regenerated baselines for human approval.
Done when local and CI runs of the same commit match within the documented thresholds, and baselines regenerated for a new environment are in their own PR, separate from the harness and code changes that led to it.
4. **Compare.** Compare per snapshot with the smallest threshold that removes anti-aliasing noise; mask only regions that are dynamic by nature (for example a live chart), never to hide a failure. Report diffs as images: baseline, actual, highlighted difference.
Done when the thresholds and masks are written down with a reason for each.
5. **Review baselines.** A baseline changes only in the PR that intends the visual change, and a human approves the diff images; mass-updating baselines to make CI green is forbidden; the only bulk update is the environment change from step 3. Unreviewed diffs block the merge like any failing check.
Done when every baseline change in the PR is linked to an intended change and approved.
6. **Triage.** For each failing snapshot: intended (update baseline in this PR), regression (fix code, add a note to the task), or flaky (find the source of non-determinism from step 2 and fix it; quarantine follows the [testing standard](../../../standards/testing.md): temporary, with a ticket and an owner).
Done when every failure has a category and, for flaky ones, a cause and an owner.
## Best practices
- Component snapshots are cheap and stable; page snapshots are expensive and brittle — keep the ratio high.
- Name snapshots by component, variant, state, theme and viewport so a diff explains itself.
- Run visual tests on every PR that touches UI or tokens; token changes are reviewed by their visual diff.
- Pair with `accessibility` checks on the same fixtures.
## Common mistakes
- Generating baselines on a developer machine and comparing in CI.
- Raising the threshold or masking regions until the test passes.
- Updating all baselines in one commit without looking at them, or mixing an environment change with UI changes in one PR.
- Fixed sleeps instead of waiting for fonts and network to settle.
- Snapshotting only the default state, so hover, focus and error regress unnoticed.
## Example
A spacing token change: CI fails on 14 snapshots → diff images show buttons and inputs grew by 4 px, intended; one card in dark theme lost its border, regression → fixed; one chart snapshot differs on every run, flaky → animation was not disabled, fixed; baselines for the 14 intended diffs updated in the same PR and approved by the reviewer.
## Reusable prompt
```text
Apply the Visual regression testing skill (.agents/skills/visual-regression-testing/SKILL.md).
Context: {{catalogue or fixtures; key screens; themes and viewports; existing test tooling}}
Constraints: {{allowed files; approved ADRs; CI limits}}
Set up or review screenshot tests: selection, deterministic rendering, pinned environment, thresholds and masks, baseline review and triage.
Return: tests and baselines, CI job, thresholds with reasons, triage notes for each diff.
Cite evidence (file:line, command output, source) for every claim; list open questions separately.
```
## Checks
- [ ] Same commit matches within documented thresholds locally and in CI over several runs.
- [ ] Every threshold and mask has a written reason.
- [ ] Baseline changes appear only with intended visual changes and are approved.
- [ ] Flaky snapshots have a cause, a ticket and an owner.
- [ ] Any new tool or service has an ADR.
## Out of scope
- Choosing a screenshot service or tool — `architecture-decisions`.
- Functional assertions in browser flows — `e2e-testing`.