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

Migrate from Vitest toMatchScreenshot to Argos

Move from Vitest's built-in toMatchScreenshot() to Argos. Stop committing __screenshots__ reference images and review visual changes on the pull request.

To migrate from Vitest's built-in toMatchScreenshot() to Argos, install @argos-ci/vitest, add argosVitestPlugin() to your Vitest config, replace each toMatchScreenshot() assertion with await argosScreenshot("name"), and delete the committed __screenshots__ folders. Your browser mode tests stay the same; Argos picks baselines from your Git history and reports visual changes as a check on your pull request.

Why teams move off toMatchScreenshot()

toMatchScreenshot() works, but it puts three problems on your team:

  • References are committed images. Vitest stores reference screenshots in __screenshots__ folders next to your tests, and you commit them. Screenshots of deleted or renamed tests aren't removed automatically.

  • References are platform-specific. File names include the browser and the platform, for example button-chromium-darwin.png, so references captured on macOS are not used on Linux CI. Vitest recommends a controlled environment, such as Docker or CI-only runs, to keep them consistent.

  • There is no review step. A mismatch fails the test. To accept an intended change, you re-run with --update and commit the new images, and the diff image is written to .vitest/attachments/ on the machine that ran the test.

Argos keeps your Vitest tests but removes all three: baselines are selected from your Git history, screenshots are captured on CI, and changes are reviewed and approved on the pull request.

What changes semantically

With toMatchScreenshot(), a visual difference fails the test. With Argos, argosScreenshot saves the screenshot and the comparison runs in Argos once the files are uploaded: the visual result becomes a commit status that you review and approve, independent of whether the test passed.

Concept mapping

Vitest toMatchScreenshot()

Argos

await expect(page.getByRole("button")).toMatchScreenshot("button")

await argosScreenshot("button")

A screenshot of one element

await argosScreenshot("button", { element: "button" }) (a CSS selector)

__screenshots__/ folders committed to Git

Baselines from Git history

vitest --update

Approve in the Argos review UI

comparatorOptions (threshold, allowedMismatchedPixelRatio, …)

The threshold option of argosScreenshot, and the diff algorithm

screenshotOptions.mask

The argosCSS option, for example visibility: hidden on dynamic elements

timeout (retries until the screenshot is stable)

Argos stabilization: waits for fonts, images, and aria-busy elements

Diff images in .vitest/attachments/

The build page and the pull request comment

A mismatch fails the test

A pull request check to review and approve

Migrate the project

1

Install the Argos Vitest SDK

You keep vitest, @vitest/browser, @vitest/browser-playwright, and playwright: the SDK requires Vitest 4 or later and captures screenshots with the Playwright provider. If your browser mode uses another provider, switch to @vitest/browser-playwright.

2

Add the Argos plugin

Add argosVitestPlugin() to your Vitest config, next to your existing browser mode settings:

You can remove the browser.expect.toMatchScreenshot settings once every assertion is migrated.

3

Replace toMatchScreenshot() with argosScreenshot()

Before (Vitest)

After (Argos)

By default, argosScreenshot captures the rendered output of the test. To capture a single element, pass a CSS selector: await argosScreenshot("button", { element: "button" }). Per-call options must be serializable, so pass a selector string, not a locator. The name is optional: omit it and Argos derives one from the current test.

4

Delete the committed references

Remove the reference folders and stop tracking them:

If you set a custom screenshotDirectory or resolveScreenshotPath, remove it too. You no longer commit reference images: Argos stores the baselines.

5

Seed the baseline and wire up CI

Run your tests in CI with ARGOS_TOKEN set. Run on your default branch first so Argos has a baseline; until then, pull request builds are marked as orphan.

ARGOS_TOKEN comes from Settings → Authentication → Project token. On GitHub Actions you can use OIDC or tokenless authentication instead of a secret.

Frequently asked questions

Can I keep some toMatchScreenshot() assertions?

Yes. argosScreenshot is a separate command and doesn't change toMatchScreenshot(), so both can run in the same suite while you migrate. Once every assertion is converted, delete the __screenshots__ folders.

Do I still need Docker to keep screenshots consistent?

No. Argos compares each screenshot with a baseline captured on CI, so you don't need to render locally in the same environment as CI to match committed images. Keep the text-rendering launchOptions above: they make glyphs render the same way on every machine. See Stabilize text rendering.

How do I accept an intended visual change now?

Open the build in Argos and approve it in the review UI. There is no --update run and no image to commit.

What about threshold and allowedMismatchedPixelRatio?

Argos applies its own diff algorithm, so you rarely need per-assertion tuning. If a screenshot needs a different sensitivity, pass the threshold option to argosScreenshot: a value between 0 and 1, where higher is less sensitive. It defaults to 0.5 and doesn't use the same scale as the pixelmatch threshold.

Can I diff things that aren't screenshots?

Yes. argosSnapshot() captures any value — an API response, generated HTML, Markdown — in browser or Node tests, and Argos diffs it as text. See the Vitest SDK reference.

Next steps

Last updated

Was this helpful?