For the complete documentation index, see llms.txt. This page is also available as Markdown.

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 example button-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.

Using Storybook? Follow the Storybook Quickstart instead — it builds on this same Vitest integration.

Prerequisites

Capturing screenshots additionally requires Vitest browser mode with the Playwright provider. Snapshots run in any Vitest test and need neither.

1

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:

2

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 test.browser block is only required for screenshots. If you only capture snapshots, you can omit it — the plugin still uploads your snapshots to Argos.

3

Capture screenshots and snapshots

Use the argosScreenshot helper to capture a screenshot in a browser test:

Unlike other Argos SDKs, argosScreenshot takes no page argument here — Vitest browser tests already run in the page context. The name is optional too: omit it and Argos derives one from the current 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:

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.

4

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.

Argos needs a baseline to compare against. Until a build runs on your default branch, pull request builds are marked as orphan. Merge this setup or run the workflow once on your default branch to establish the baseline.

Frequently asked questions

How do I update the baseline after an intended change?

You don't update any file. Review the build in Argos and approve the changes: an approved build is eligible as a baseline. Once you merge, the build on your default branch, which Argos approves automatically by default, becomes the baseline for the pull requests that follow. See Baseline build.

Why do screenshots differ between my machine and CI?

Fonts, text rendering, and browser versions depend on the operating system, so the same page renders slightly differently on macOS and on a Linux CI runner. The Argos plugin uploads to Argos only from CI (uploadToArgos: !!process.env.CI), so Argos only compares screenshots captured on CI, and the launchOptions flags make text render the same way on every machine. See Stabilize text rendering and Browser glitches.

Next steps


Last updated

Was this helpful?