vitest-visual-diff weekly downloads statistics
By acoyfellow · npm · Testing
Compare two live elements through structure, computed style, pixels, and accessibility in Vitest Browser Mode.
vitest-visual-diff has 4 recorded weekly downloads on npm, unchanged over the past 30 days, ranking #3241 of 3,247 tracked listings.
About vitest-visual-diff
vitest-visual-diff
A Vitest matcher for Browser Mode that answers one question: are these two elements, rendered live in a real browser, actually the same?
import { expect, test } from 'vitest';
import { page } from 'vitest/browser';
import 'vitest-visual-diff';
test('the new checkbox renders the same as the old one', async () => {
await expect(page.getByTestId('checkbox-new')).toMatchVisualDiff(
page.getByTestId('checkbox-old'),
);
});
If the answer is no, the failure tells you why — a missing element, a wrong color, a shifted pixel, or a broken screen-reader state — instead of just "these don't match."
Tutorial: your first comparison
This walks through comparing two elements in a real test, from an empty project to a passing (and then a deliberately failing) assertion.
1. Install it.
bun add -d github:acoyfellow/vitest-visual-diff vitest @vitest/browser @vitest/browser-playwright playwright
bunx playwright install chromium
2. Point Vitest at a real browser. Create vitest.config.ts:
import { defineConfig } from 'vitest/config';
import { playwright } from '@vitest/browser-playwright';
export default defineConfig({
test: {
setupFiles: ['vitest-visual-diff'],
browser: {
enabled: true,
provider: playwright(),
instances: [{ browser: 'chromium' }],
},
},
});
setupFiles: ['vitest-visual-diff'] registers toMatchVisualDiff on expect once,
for every test file.
3. Write a test that mounts two elements and compares them.
// checkbox.test.ts
import { test, expect } from 'vitest';
import { page } from 'vitest/browser';
test('two identically-styled checkboxes match', async () => {
const checkbox = (testId: string) => `
<button data-testid="${testId}" role="checkbox" aria-checked="true"
style="width:20px; height:20px; background:#2563eb; border-radius:4px;">
<svg width="12" height="12"><path d="M2 6l3 3 5-7" stroke="white" stroke-width="2" fill="none"/></svg>
</button>`;
document.body.innerHTML = `
<div style="position:fixed; top:0; left:0;">${checkbox('checkbox-old')}</div>
<div style="position:fixed; top:100px; left:0;">${checkbox('checkbox-new')}</div>
`;
const oldCheckbox = page.getByTestId('checkbox-old');
const newCheckbox = page.getByTestId('checkbox-new');
await expect(newCheckbox).toMatchVisualDiff(oldCheckbox);
});
Run it: bun run test. It passes — same markup, same styles, same pixels.
4. Break something on purpose and watch the failure explain itself.
Remove the new checkbox's <svg> checkmark before the assertion (a real
regression class: "the checkbox looks right until you check it, and then
nothing appears"):
newCheckbox.element().querySelector('svg')?.remove();
Run it again. It fails, and the message says exactly what's wrong:
expected candidate to match visual-diff baseline (A=FAIL B=pass C=pass)
structure: missing overall — {"svg":1,"path":1}
That's the shape of the whole library: every failure names the tier that caught it and the concrete thing that differed.
Why
position:fixedon the two containers? Two elements sitting next to each other in normal page flow can round their own box height by a fraction of a pixel differently across browser engines (confirmed on Firefox specifically — see Why two fixed-positioned containers). Giving each container its own fixed position removes that coupling. If you're comparing two elements that are already isolated in their own containers (an iframe, a separate test render), you don't need this.
How-to guides
Compare two elements that don't have a stored baseline file
Use toMatchVisualDiff directly with two live elements — no reference image
to commit, no --update workflow. This is the case for A/B component
variants, a migration's before/after, or a design-reference iframe next to
the real render.
await expect(candidate).toMatchVisualDiff(reference);
Skip the pixel check
Pass { pixels: false } when one side is a bare DOM Element (no
screenshot capability) or when you only care about structure and style:
await expect(candidateElement).toMatchVisualDiff(referenceElement, { pixels: false });
pixels defaults to true automatically when both sides are Locators
(screenshot-capable) and false when either side is a plain Element.
Catch an accessibility-only regression
Pass a11y: true to add two checks: Tier S compares accessible names,
descriptions, and state; Tier R compares relationships such as label[for],
aria-labelledby, and aria-describedby. This catches a checkbox whose
aria-checked silently flipped and a label that no longer points to its
control:
await expect(candidate).toMatchVisualDiff(reference, { a11y: true });
Tune the style comparison tolerance
await expect(candidate).toMatchVisualDiff(reference, {
style: { tol: 1.5 }, // px tolerance for numeric style values
});
Tune the pixel-diff threshold
await expect(candidate).toMatchVisualDiff(reference, {
pixelOpts: { threshold: 0.2, flagPct: 2.0 },
});
Run against a different browser engine
Nothing in vitest-visual-diff is Chromium-specific. Add more instances to
vitest.config.ts:
browser: {
enabled: true,
provider: playwright(),
instances: [
{ browser: 'chromium' },
{ browser: 'firefox' },
{ browser: 'webkit' },
],
}
Run against a different Vitest Browser Mode provider entirely
vitest-visual-diff never imports a provider package — it only uses the
Locator/Element and .screenshot() surface Vitest itself hands the test.
Swap @vitest/browser-playwright for @vitest/browser-webdriverio and
nothing in src/ needs to change:…
Description from the npm listing.
- vitest
- vitest-plugin
- visual-regression
- visual-diff
- browser-mode
- custom-matcher
- pixelmatch
- accessibility
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 (170)Similar npm Testing plugins
All 20 vitest-visual-diff 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-visual-diff. First seen Oct 16, 2026; last successful collection Dec 6, 2026. See the methodology.