How to Use the BackstopJS Reference, Test, and Approve Flow in CI
BackstopJS separates baseline creation (reference) from comparison (test) and acceptance (approve), so CI runs test while reference and approve happen deliberately.
Create baselines with backstop reference, compare with backstop test in CI, and promote intended changes with backstop approve when you review a diff.
Steps
- Define scenarios and viewports in
backstop.json. - Run
backstop referenceto capture baselines and commit them. - Run
backstop testin CI to compare. - Run
backstop approvelocally to accept intended changes.
Commands
Terminal
npx backstop reference # create baselines
npx backstop test # compare (used in CI)
npx backstop approve # promote diffs to baselinesWorkflow
.github/workflows/ci.yml
jobs:
backstop:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- run: npm ci
- run: npx backstop test
- uses: actions/upload-artifact@v4
if: failure()
with:
name: backstop-report
path: backstop_data/html_report/Gotchas
- Never run
backstop approveinside CI; it would rubber-stamp every diff. - Commit
bitmaps_reference/so the runner has baselines to compare against.
Related guides
How to Use jest-image-snapshot in CIAdd pixel diffing to Jest tests with jest-image-snapshot and toMatchImageSnapshot, tuning failureThreshold so…
How to Upload Snapshot Artifacts on Visual Test Failure in CISave the expected, actual, and diff images on a failing visual run by uploading the Playwright report as an a…