Vitest browser mode visual testing quickstart
Set up visual testing in your Vitest browser tests with the Argos Vitest SDK.
To add visual testing to Vitest, install @argos-ci/vitest, add argosVitestPlugin() to your Vitest config, call argosScreenshot() in a browser mode test, and run npx vitest run in CI with the ARGOS_TOKEN environment variable set. Argos compares every screenshot with a baseline build picked from your Git history and reports the changes as a check on your pull request.
The Argos Vitest SDK captures two kinds of files:
Screenshots of your rendered components, captured from Vitest browser tests.
Snapshots of any value — objects, JSON, HTML, and more — captured from browser or plain Node tests. No browser required.
What Argos adds over toMatchScreenshot()
Vitest's built-in toMatchScreenshot() already compares screenshots in browser mode. Argos keeps your Vitest tests and changes what happens around them:
No reference images in your repository.
toMatchScreenshot()stores references in__screenshots__folders that you commit, named per browser and platform (for examplebutton-chromium-darwin.png), so references captured on macOS are not used on Linux CI. Argos picks the baseline from your Git history.Review on the pull request. A
toMatchScreenshot()mismatch fails the test until you re-run with--update. Argos turns visual changes into a pull request check that your team approves or rejects.Diff more than pixels.
argosSnapshot()compares any value — API responses, generated HTML, Markdown — from browser or Node tests.
Already using toMatchScreenshot()? Follow Migrate from Vitest toMatchScreenshot to Argos.
Prerequisites
Node.js 22 or later
Vitest set up in your project
Capturing screenshots additionally requires Vitest browser mode with the Playwright provider. Snapshots run in any Vitest test and need neither.
Install
Install the Argos Vitest SDK:
To capture screenshots, also install the Vitest browser mode peer dependencies, plus vitest-browser-react to render the React component in the example below (skip this if you only need snapshots). On Vue or Svelte, install vitest-browser-vue or vitest-browser-svelte instead:
Add the Argos plugin to your Vitest config
The Argos plugin registers the argosScreenshot browser command and, when uploadToArgos is enabled, uploads the captured screenshots to Argos at the end of the run:
The launchOptions above disable subpixel text and font hinting, so glyphs render identically on your machine and on CI. This single change prevents one of the most common causes of flaky screenshots — learn why in Stabilize text rendering.
Capture screenshots and snapshots
Use the argosScreenshot helper to capture a screenshot in a browser test:
Use argosSnapshot to capture a snapshot of any value — it works in browser and Node tests, no browser required. The value comes first and the name is optional (omit it to auto-name from the current test, or pass options.name). Strings are written verbatim; any other value is serialized automatically:
argosSnapshot lets you visually diff anything, not just UI — API responses, generated HTML, config files, Markdown, and more. Pass the extension option (e.g. .json, .html, .yml) to control how Argos renders and diffs it. See the SDK reference for details.
Both are written to the ./snapshots directory by default. Add ./snapshots to your .gitignore file to avoid committing them.
Tip: Check out our guides to capture multiple viewports or add ARIA snapshots.
Set up CI
Run your Vitest tests in CI with ARGOS_TOKEN set. The Argos plugin uploads screenshots automatically when uploadToArgos is enabled:
ARGOS_TOKEN is the project token from Settings → General → Token. On GitHub Actions, you can also use OIDC or tokenless authentication to avoid managing a secret. On other CI providers, pass the token with the ARGOS_TOKEN environment variable or the plugin's token option. For GitLab CI, CircleCI, Buildkite, and other providers, see Run Argos in CI.
You're all set
Push your changes and open a pull request — the Argos check appears on it once the build is uploaded. Review the visual changes, approve or reject them, and merge with confidence.
Frequently asked questions
Next steps
Stabilize screenshots – Prevent flaky diffs before they reach your pull requests
Vitest SDK reference – All options, including
argosSnapshotVitest browser mode documentation – Vitest's own browser testing guide
Vitest visual testing – A guide to browser mode screenshots, on the Argos blog
Need help? Join our Discord, open an issue on GitHub, or send us an email.
Last updated
Was this helpful?