Visual testing for Storybook test runner.

View on GithubNew to Storybook?Get started

Snapvisor Storybook integration

npm version npm dm npm dt

Capture and review visual changes of your Storybook stories with Snapvisor. It runs your stories in a real browser and uploads a screenshot of each one to Snapvisor in your CI.

Visit the Storybook SDK documentation for guides, the API reference, and more.

Installation

npm install --save-dev @snapvisor/storybook

Usage

The recommended way to run visual tests is with the Storybook Vitest addon. Register the Snapvisor plugin in your Vitest config:

// vitest.config.ts
import { defineConfig } from "vitest/config";
import { snapvisorVitestPlugin } from "@snapvisor/storybook/vitest-plugin";

export default defineConfig({
  plugins: [
    snapvisorVitestPlugin({
      // Upload the screenshots to Snapvisor only on CI.
      uploadToSnapvisor: process.env.CI === "true",
    }),
  ],
});

A screenshot is captured for every story automatically. To capture additional screenshots (for example, at different steps of an interaction), call snapvisorScreenshot inside a story's play function:

// Button.stories.tsx
import { snapvisorScreenshot } from "@snapvisor/storybook/vitest";

export const Example: Story = {
  play: async (ctx) => {
    await snapvisorScreenshot(ctx, "example");
  },
};

Using the Storybook Test Runner instead? Import snapvisorScreenshot from @snapvisor/storybook/test-runner and call it from the postVisit hook. See the SDKs documentation.

The Argos-named exports from earlier versions (argosVitestPlugin, uploadToArgos, argosScreenshot) still work.

Compatibility

@snapvisor/storybook supports Storybook 8 through 11, including the 11 pre-releases. Screenshots can be taken with the Vitest addon (Storybook 9 or later, Vitest 4 or 5) or with the Storybook Test Runner (Storybook 8 or later).

Links

Attribution

Based on Argos (MIT, Copyright 2022 Smooth Code). Snapvisor modifications are copyright Devino Solutions Inc. See the LICENSE.