@argos-ci/vitest

中文文档
0.9.0发布于 2026/10/21MITTypeScriptES Module构建来源已验证近 30 天下载 31.3万

Vitest SDK for visual testing with Argos.

原始使用文档
文档目录5 节
  1. Installation
  2. Usage
  3. Automatic naming
  4. Snapshots
  5. Links

Argos

The open source visual testing platform for teams and AI agents.

Official Argos Vitest integration

npm version npm dm npm dt

Capture Argos screenshots directly from your Vitest browser tests.

Visit the Vitest SDK documentation for guides, API and more.

Installation

Install the package:

npm install --save-dev @argos-ci/vitest

argosSnapshot runs in any Vitest test — browser or Node — and needs nothing else.

To capture screenshots with argosScreenshot, run your tests in Vitest browser mode with the Playwright provider and install the following peer dependencies:

npm install --save-dev vitest @vitest/browser @vitest/browser-playwright playwright

Usage

Register the plugin in your Vitest config:

// vitest.config.ts
import { defineConfig } from "vitest/config";
import { playwright } from "@vitest/browser-playwright";
import { argosVitestPlugin } from "@argos-ci/vitest/plugin";

export default defineConfig({
  plugins: [
    argosVitestPlugin({
      // Upload the screenshots to Argos at the end of the run.
      uploadToArgos: process.env.CI === "true",
    }),
  ],
  test: {
    browser: {
      enabled: true,
      headless: true,
      provider: playwright(),
      instances: [{ browser: "chromium" }],
    },
  },
});

Then take screenshots from your browser tests:

import { test } from "vitest";
import { render } from "vitest-browser-react";
import { argosScreenshot } from "@argos-ci/vitest";
import { Button } from "./Button";

test("Button", async () => {
  render(<Button>Click me</Button>);
  await argosScreenshot("button");
});

Automatic naming

The name is optional. When omitted, Argos derives one from the current test, mimicking Vitest snapshots. Several unnamed captures in the same test get an incrementing counter so they stay unique:

test("Button", async () => {
  render(<Button>Click me</Button>);
  await argosScreenshot(); // -> "src/Button.test.tsx > Button 1"
  await argosScreenshot(); // -> "src/Button.test.tsx > Button 2"
});

Unlike Vitest — which keeps a per-file .snap, so its keys only need to be unique within a file — Argos names are global across the build. The generated name therefore includes the test file path, so two tests with the same title in different files never collide.

Snapshots

argosSnapshot captures a snapshot of any value — not just a screenshot — and uploads it to Argos to diff across builds, mimicking Vitest snapshots. Unlike argosScreenshot, it does not need a browser and works in both browser and Node tests.

The value comes first; the name is optional. Omit it to auto-name the snapshot from the current test (like screenshots above), or pass options.name to set it explicitly:

import { test } from "vitest";
import { argosSnapshot } from "@argos-ci/vitest";

test("API response", async () => {
  const user = await fetchUser();
  // Objects are serialized with `@vitest/pretty-format`, strings are written
  // verbatim.
  await argosSnapshot(user); // -> "src/user.test.ts > API response 1"
  await argosSnapshot(user, { name: "user" }); // explicit name
});

Use the extension option to control how Argos renders and diffs the snapshot, and tag to attach tags:

await argosSnapshot(JSON.stringify(config, null, 2), {
  name: "config",
  extension: ".json",
  tag: "config",
});

Screenshots and snapshots are both written to the ./snapshots directory by default (configurable via the plugin root option) and uploaded by the reporter when uploadToArgos is enabled.

版本与发布记录

@argos-ci/vitest 共发布 22 个版本,首次发布于 2026/07/10;过去 12 个月发布了 22 个版本。最新版本附带 npm provenance 构建来源证明,可追溯到公开的 CI 构建记录。

版本发布日期距今
0.9.0latest2026/10/2117 天前
0.8.02026/10/041 个月前
0.7.12026/09/301 个月前
0.7.02026/09/131 个月前
0.6.12026/09/121 个月前
0.6.02026/09/052 个月前

其他发布通道:canary → 0.4.5-canary-20260811115807.6.sha-15ba429。

关于 @argos-ci/vitest 的常见问题

@argos-ci/vitest 是什么?

Vitest SDK for visual testing with Argos.

如何安装 @argos-ci/vitest?

在项目目录运行 npm install @argos-ci/vitest,或使用 pnpm add / yarn add / bun add。它还需要宿主项目提供 peer 依赖:vitest(>=4)、playwright(>=1)、@vitest/browser(>=4)、@vitest/browser-playwright(>=4)。npm 7 及以上与 pnpm 8 及以上默认会自动安装必需的 peer 依赖,Yarn 需要手动安装。

@argos-ci/vitest 支持 TypeScript 吗?

支持。包内自带 TypeScript 类型声明(package.json 声明了 types 入口),安装后即可获得类型提示,无需再安装 @types 包。

@argos-ci/vitest 支持 ESM 还是 CommonJS?

以 ES Module 形式发布,推荐使用 import 引入。在 CommonJS 项目中,Node.js 20.19+ / 22.12+ 可以直接 require() 不含顶层 await 的 ES Module,更早的版本需要改用动态 import()。

@argos-ci/vitest 需要什么版本的 Node.js?

package.json 的 engines 字段要求 Node.js >=22.0.0。版本不符时 npm 默认只给出警告,开启 engine-strict 后会拒绝安装。

@argos-ci/vitest 可以商用吗?

@argos-ci/vitest 使用 MIT 许可。宽松许可:允许商业使用、修改和再分发,通常只需在分发时保留原版权与许可声明。以上为概括,不构成法律意见,请以许可原文为准。

@argos-ci/vitest 的下载量有多少?

根据 npm 官方下载统计,@argos-ci/vitest 在 2026/10/07 – 2026/11/05 这 30 天内被下载 313,135 次,日均约 10,438 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@argos-ci/vitest 还在维护吗?

最新版本 0.9.0 发布于 2026/10/21(17 天前);至今共发布 22 个版本,其中过去 12 个月发布了 22 个;首次发布于 2026/07/10。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。