Skip to content

Repository files navigation

snapdiff

Zero-config CLI for visual regression testing. Powered by Playwright + pixelmatch.

npm versionnpm downloadsCIlicense


snapdiff is a visual regression testing CLI. Take a baseline screenshot before you change code, then compare after ? it tells you what changed and by how much, with an interactive HTML report.

Ideal for:

  • Checking for unintended layout changes after CSS/component edits
  • Automated visual diff on every PR
  • CI pipeline integration

snapdiff demo


Quick Start

# Initialize (interactive wizard, auto-captures first baseline)
npx snapdiff-cli init
# After code changes, compare against baseline
npx snapdiff-cli diff
# Check baseline status
npx snapdiff-cli status
# Accept changes as new baseline
npx snapdiff-cli approve <name>

Running init for the first time will:

  1. Create snapdiff.config.json
  2. Take the first baseline screenshot automatically
  3. Add .snapdiff/diffs/ and .snapdiff/reports/ to .gitignore

Features

FeatureDescription
Zero configsnapdiff init sets up everything ? config file, first capture, .gitignore
Pixel-level diffUses pixelmatch for accurate comparison
HTML reportSide-by-side view of baseline / current / diff, auto-generated
Parallel captureCaptures 3 pages concurrently
Mask regionsExclude dynamic areas (ads, animations) from comparison
CI readyBuilt-in GitHub Action, works with any CI pipeline
Multi-pageCapture and diff entire site configurations from a single config file
Auto-cleanupOld reports older than 7 days are removed automatically

Commands

init

Initialize a snapdiff project (interactive wizard, auto-captures first screenshot).

npx snapdiff-cli init # Interactive
npx snapdiff-cli init --yes # Non-interactive, use defaults
npx snapdiff-cli init --yes --ci # Non-interactive + generate CI config

init auto-detects whether stdin is a terminal. In CI environments (non-TTY), it switches to non-interactive mode automatically.

capture

Capture and save baseline screenshots.

# Capture all pages from the config file
npx snapdiff-cli capture
# Capture a single page
npx snapdiff-cli capture https://example.com --name my-page
# Wait for a CSS selector to appear before capturing
npx snapdiff-cli capture https://example.com --name home --selector "#app-root"# Custom viewport
npx snapdiff-cli capture https://example.com --name mobile -w 375 -h 812

Multi-page mode uses 3 concurrent workers automatically.

diff

Compare current pages against their baselines.

# Diff all pages from the config file
npx snapdiff-cli diff
# Diff a single page
npx snapdiff-cli diff https://example.com --name my-page
# Set a more permissive threshold (allow 0.5% diff)
npx snapdiff-cli diff -t 0.5

Generates an HTML report in .snapdiff/reports/ with baseline / current / diff side-by-side. Reports older than 7 days are auto-cleaned.

approve

Accept the current diff as the new baseline (overwrites old baseline).

npx snapdiff-cli approve my-page

status

Display all baseline entries in a table.

npx snapdiff-cli status

Config File

Create snapdiff.config.json in your project root:

{
"snaps": [
{
"name": "homepage",
"url": "https://example.com",
"viewport": { "width": 1440, "height": 900 },
"threshold": 0.1
},
{
"name": "pricing",
"url": "https://example.com/pricing",
"selector": "#app-root",
"viewport": { "width": 1440, "height": 900 },
"threshold": 0.1
}
]
}

Config Fields

FieldTypeRequiredDescription
namestringYesSnapshot name for identification
urlstringYesPage URL
selectorstringNoWait for CSS selector before capture
viewportobjectNoViewport size, default { width: 1440, height: 900 }
thresholdnumberNoDiff threshold percentage, default 0.1. Exceeds threshold = failure
fullPagebooleanNoCapture full scrollable page, default false
headlessbooleanNoHeadless browser mode, default true
maskRegionsarrayNoMask regions array [{ x, y, width, height }]. These areas are excluded from diff comparison

Directory Structure

project-root/
+-- snapdiff.config.json # Configuration file
+-- .gitignore # Automatically includes .snapdiff/*
+-- .snapdiff/
+-- baselines/ # Baseline images (tracked in git)
| +-- homepage.png
| +-- homepage.json # Metadata (URL, viewport, timestamp)
+-- diffs/ # Diff comparison images (gitignored)
| +-- homepage-1234567890-diff.png
+-- reports/ # HTML reports (gitignored)
| +-- report-1234567890.html
+-- tmp/ # Temp screenshots (gitignored)

Baseline images are tracked in git so that PR diffs show image changes directly. Diff images and reports are gitignored.


CI Integration

GitHub Actions

snapdiff ships with a built-in GitHub Action that supports both capture and diff modes.

# .github/workflows/snapdiff.ymlname: Visual Regression Teston: [pull_request]jobs:
snapdiff:
runs-on: ubuntu-lateststeps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4with:
node-version: 20
- run: npx snapdiff-cli diff

Generate this automatically with:

npx snapdiff-cli init --yes --ci

Other CI

snapdiff runs anywhere Node.js is available. Just install and run:

npx snapdiff-cli capture # In a pre-change step
npx snapdiff-cli diff # In a post-change step

Comparison

FeaturesnapdiffPercyChromaticBackstopJS
Local CLIFree, open-sourceLimited (cloud-dependent)Limited (cloud-dependent)Free
SaaS requirementNoneRequired (cloud rendering)Required (cloud rendering)None
PricingFree (open source MIT)Paid tiers after free quotaPaid tiers after free quotaFree
Self-hostedYesNo (cloud only)No (cloud only)Yes
HTML reportBuilt-in, localWeb dashboardWeb dashboardCustomizable
Parallel captureYes (3 workers)YesYesYes
Mask regionsYesYesYesLimited
CI integrationCLI + GitHub ActionGitHub Action + SDKGitHub AppCLI + Docker
Setup time~30 seconds~5 minutes + account~5 minutes + account~10 minutes
Full page captureYesYesYesYes

Tech Stack

ComponentPurpose
PlaywrightBrowser automation & screenshot engine
pixelmatchPixel-level image comparison
pngjsPNG image processing
commanderCLI framework

Development

git clone https://github.com/zixuan57/snapdiff.git
cd snapdiff
cd packages/cli
npm install
npm run build
node dist/index.js --help

Contributing

Bug reports, feature requests, and pull requests are welcome. See CONTRIBUTING.md.


License

MIT

About

No description or website provided.

Topics

Resources

Contributing

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages