Vitest Quickstart
Set up visual testing in your Vitest browser tests with the Argos Vitest SDK.
Prerequisites
1
Install
npm i --save-dev @argos-ci/vitestyarn add --dev @argos-ci/vitestpnpm add --save-dev @argos-ci/vitestbun add --dev @argos-ci/vitestnpm i --save-dev vitest @vitest/browser @vitest/browser-playwright playwrightyarn add --dev vitest @vitest/browser @vitest/browser-playwright playwrightpnpm add --save-dev vitest @vitest/browser @vitest/browser-playwright playwrightbun add --dev vitest @vitest/browser @vitest/browser-playwright playwright2
Add the Argos plugin to your Vitest config
import { defineConfig } from "vitest/config";
import { playwright } from "@vitest/browser-playwright";
import { argosVitestPlugin } from "@argos-ci/vitest/plugin";
export default defineConfig({
plugins: [
argosVitestPlugin({
// Upload to Argos on CI only.
uploadToArgos: !!process.env.CI,
}),
],
test: {
browser: {
enabled: true,
headless: true,
provider: playwright({
// Stabilize text rendering so screenshots match across macOS and CI.
launchOptions: {
args: ["--disable-lcd-text", "--font-render-hinting=none"],
},
}),
instances: [{ browser: "chromium" }],
},
},
});3
Capture screenshots and snapshots
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");
});import { test } from "vitest";
import { argosSnapshot } from "@argos-ci/vitest";
import { fetchUser } from "./api";
test("API response", async () => {
const user = await fetchUser();
await argosSnapshot(user); // -> "src/user.test.ts > API response 1"
});You're all set
Next steps
Last updated
Was this helpful?