Prompt
How do I integrate visual regression tests into pull requests?
Latest observation
Oct 27, 2026
OpenAI APIWeb search: off
A good way to integrate visual regression tests into pull requests is to make them part of your CI pipeline and gate merges on their results.
Typical setup
1) Pick a visual regression tool
Common options:
- Percy
- Chromatic (great for Storybook)
- Applitools
- Cypress + screenshot diffing
- Playwright or Puppeteer with image comparison
2) Capture baseline screenshots
- Run your app or component stories in a stable environment.
- Generate reference screenshots for key pages/components/states.
- Store baselines in the visual testing service or in git if using an in-house setup.
3) Run tests on every PR
In your CI workflow:
- Build the app
- Start the preview/storybook/server
- Run the visual test suite
- Upload screenshots to the visual testing service
- Compare PR screenshots against the baseline
4) Post results back to the PR
Your tool or CI should comment on the PR with:
- Changed screenshots
- Diffs highlighting pixel changes
- Links to approve or reject updates
5) Make it a merge check
Require the visual regression job to pass before merging:
- If diffs are unexpected, block the merge
- If changes are intentional, approve/update baselines from the PR UI
Recommended PR workflow
- Developer opens PR
- CI runs unit/integration tests + visual tests
- Visual tool compares screenshots
- PR gets a report:
- No changes → pass
- Expected changes → approve baseline update
- Unexpected changes → fail
- Merge only after approval
Best practices
- Test stable states only: avoid animations, timers, random data, and live APIs.
- Use consistent environment: same browser, viewport, fonts, locale, and theme.
- Control nondeterminism:
- mock dates/timestamps
- freeze animations
- stub network calls
- Limit coverage to high-value UI:
- critical pages
- reusable components
- important breakpoints/themes
- Review diffs carefully:
- whitespace/layout shifts
- color/token changes
- accidental regressions
Example CI flow
If using GitHub Actions with Playwright:
name: Visual Tests
on: [pull_request]
jobs:
visual:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: 20
- run: npm ci
- run: npm run build
- run: npm run start &
- run: npx wait-on http://localhost:3000
- run: npx playwright test --update-snapshots=false
For a hosted service like Percy/Chromatic, you’d add their CLI and token, and the service handles diff review in the PR.
If you want the simplest path
- React + Storybook → use Chromatic
- General web app → use Playwright or Cypress with Percy
- Enterprise/advanced workflows → use Applitools
If you tell me your stack (React/Vue/Angular, Storybook or not, CI provider), I can suggest a concrete PR setup and sample config.