vitest-image-snapshot has 7,766 recorded weekly downloads on npm, a decrease of 59.9% over the past 30 days, ranking #1368 of 3,247 tracked listings.
About vitest-image-snapshot
Image Snapshot Testing
Visual regression testing for images. Compare rendered outputs against reference images to catch visual bugs.
- Native vitest integratio
- Accepts
ImageDataor PNG buffers - test WebGPU, Canvas, or any image processing - Aggregated HTML diff report for visual failures
Setup
1. Install
pnpm install --save-dev vitest-image-snapshot
2. Import in your test file
import { imageMatcher } from "vitest-image-snapshot";
imageMatcher(); // Call once at the top level
3. (Optional) Configure HTML diff report
Configure the reporter in vitest.config.ts:
import { defineConfig } from 'vitest/config'
import { fileURLToPath } from 'node:url'
import { dirname, join } from 'node:path'
const __dirname = dirname(fileURLToPath(import.meta.url))
export default defineConfig({
test: {
include: ['src/test/**/*.test.ts'],
reporters: [
'default',
['vitest-image-snapshot/reporter', {
reportPath: join(__dirname, '__image_diff_report__'), // Absolute path recommended for monorepos
autoOpen: 'failures', // Auto-open report in browser on failures (or 'always' to always open or 'never')
}]
],
},
})
Default behavior (no configuration):
- Report location:
{vitest.config.root}/__image_diff_report__/index.html - Auto-open:
failures(can override withIMAGE_DIFF_AUTO_OPEN=alwaysorIMAGE_DIFF_AUTO_OPEN=neverenv var)
Configuration options:
reportPath: Absolute or relative toconfig.root(default:'__image_diff_report__')autoOpen: Auto-open report in browser on failures, always or never (default: 'failures' or 'never' on CI)port: Port for html report server (default: 4343)
Basic Usage
Accepts standard browser ImageData or Buffer (pre-encoded PNGs):
// With ImageData (from canvas, shader tests, etc.)
await expect(imageData).toMatchImage("snapshot-name");
// With Buffer (pre-encoded PNG)
await expect(pngBuffer).toMatchImage("snapshot-name");
// Auto-generated name from test name (single snapshot per test only)
await expect(imageData).toMatchImage();
Options
await expect(imageData).toMatchImage({
name: "edge-detection",
threshold: 0.2, // Allow more color variation
});
See Match Options for all available configuration options.
Updating Snapshots
When you intentionally change shader behavior:
# Update all snapshots
pnpm vitest -- -u
# Update specific test file
pnpm vitest ImageSnapshot.test.ts -- -u
Diff Report
If you added ImageSnapshotReporter to vitest.config.ts, failed tests generate a self-contained HTML report with:
- Expected vs Actual side-by-side
- Diff visualization (mismatched pixels highlighted)
- Mismatch statistics
- All images copied to report directory (portable and shareable)
Default location: {vitest.config.root}/__image_diff_report__/index.html
Monorepo behavior: In workspace mode (running tests from workspace root), each package's report goes to its own directory when using absolute paths in config.
Auto-open on failure:
IMAGE_DIFF_AUTO_OPEN=failures pnpm vitest
# Always auto-open
IMAGE_DIFF_AUTO_OPEN=always pnpm vitest
Or enable via inline reporter config:
reporters: [
'default',
['vitest-image-snapshot/reporter', { autoOpen: 'failures' /* or 'always' or 'never' */ }]
]
IMAGE_DIFF_AUTO_OPEN will override reporter config if both are set.
CI
When a CI environment is detected then IMAGE_DIFF_AUTO_OPEN and config options are ignored and autoOpen is set to "never".
The report is still generated and can be saved as an artifact for review or published to a static hosting service if you prefer.
Directory Structure
package-root/
├── src/test/
│ ├── ImageSnapshot.test.ts
│ ├── __image_snapshots__/ # Reference images (commit to git)
│ │ └── snapshot-name.png
│ ├── __image_actual__/ # Current test outputs (gitignore, always saved)
│ │ └── snapshot-name.png
│ └── __image_diffs__/ # Diff visualizations (gitignore, only on failure)
│ └── snapshot-name.png
└── __image_diff_report__/ # HTML report (gitignore, self-contained)
├── index.html
└── src/test/ # Copied images preserving directory structure
├── __image_snapshots__/
├── __image_actual__/
└── __image_diffs__/
Notes:
__image_actual__/saves on every run (pass or fail) for manual inspection- Report copies all images to
__image_diff_report__/preserving directory structure - Report is self-contained and portable (can be zipped, shared, or committed)
API Reference
toMatchImage()
Vitest matcher for comparing images against reference snapshots.
await expect(imageData).toMatchImage(nameOrOptions?)
Parameters:
imageData: ImageData | Buffer- Image to comparenameOrOptions?: string | MatchImageOptions- Snapshot name or options
Match Options:
interface MatchImageOptions {
name?: string; // Snapshot name (default: auto-generated from test name)
threshold?: number; // Color difference threshold 0-1 (default: 0.1)
allowedPixelRatio?: number; // Max ratio of pixels allowed to differ 0-1 (default: 0)
allowedPixels?: number; // Max absolute pixels allowed to differ (default: 0)
includeAA?: boolean; // Disable AA detection if true (default: false)
}
How Comparison Works
Image comparison uses pixelmatch, which converts RGB to YIQ color space for perceptually-weighted comparison. YIQ separates luminance (Y) from chrominance (I, Q), making the comparison more aligned with human perception than raw RGB byte comparison.
The threshold option (0-1) controls sensitivity to color differences in YIQ space.…
Description from the npm listing.
- image
- snapshot
- testing
- visual-regression
- vitest
- vitest-plugin
README badge
Show your rank in a README or on your website. The badge updates automatically.
Charts
Images: 30d · 1y · all time · 1600×900 dark
Adoption over time
7/30/90-day growth
Ranking history
Listing placement
Listing placement
Filled points are observed values; hollow points come from Internet Archive snapshots of the listing page. Dashed segments span periods with no observations — values between points are not interpolated.
Each band is one page of 20. Weekly downloads on a linear scale. Placement is projected from weekly downloads, so it can differ from the marketplace's own sort order. Hover a dot to see the listing.
Recent observations
Full history (592)Similar npm Testing plugins
All 20 vitest-image-snapshot alternativesData source
Weekly downloads (trailing 7 complete days) come from the official npm downloads API. Downloads include CI and mirrors and are not equivalent to installs or users. npm publishes no ratings.
Listing: https://www.npmjs.com/package/vitest-image-snapshot. First seen Oct 16, 2026; last successful collection Dec 6, 2026. See the methodology.