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

Storybook Test Runner visual testing quickstart

Set up visual testing in Storybook with Test Runner and the Argos CLI.

To add visual testing with Storybook Test Runner, install @argos-ci/storybook and @argos-ci/cli, call argosScreenshot(page, context) in the postVisit hook of .storybook/test-runner.ts, run test-storybook against your built Storybook, and upload the screenshots with npm exec -- argos upload ./screenshots in CI with the ARGOS_TOKEN environment variable set.

What Argos adds

  • A screenshot of every story. The postVisit hook captures each story after Test Runner has rendered it and run its play function.

  • Baselines from your Git history. Argos picks the baseline build automatically, so there are no images to commit.

  • Review on the pull request. Visual changes become a pull request check that your team approves or rejects.

If you use the Storybook Vitest addon (Storybook 9 or later), follow the Storybook quickstart instead.

If you use a legacy version of Storybook (<v8), follow the legacy Storybook Quickstart.

Prerequisites

1

Install

Install the Argos CLI, the Argos Storybook SDK, and Storybook Test Runner:

npm i --save-dev @argos-ci/cli @argos-ci/storybook @storybook/test-runner
yarn add --dev @argos-ci/cli @argos-ci/storybook @storybook/test-runner
pnpm add --save-dev @argos-ci/cli @argos-ci/storybook @storybook/test-runner
bun add --dev @argos-ci/cli @argos-ci/storybook @storybook/test-runner
2

Add a test script

Add the following script to your package.json:

package.json
{
  "scripts": {
    "test-storybook": "NODE_NO_WARNINGS=1 NODE_OPTIONS=--experimental-vm-modules test-storybook"
  }
}

NODE_OPTIONS=--experimental-vm-modules is required because Storybook Test Runner uses Jest, which needs this flag to run modern packages like the Argos Storybook SDK.

3

Capture screenshots

Add a .storybook/test-runner.ts file to your project. The postVisit hook captures a screenshot of every story:

.storybook/test-runner.ts
import type { TestRunnerConfig } from "@storybook/test-runner";
import { argosScreenshot } from "@argos-ci/storybook/test-runner";

const config: TestRunnerConfig = {
  async postVisit(page, context) {
    await argosScreenshot(page, context);
  },
};

export default config;

Screenshots are written to the ./screenshots directory. Add ./screenshots to your .gitignore file to avoid committing them.

4

Set up CI

Add a workflow that builds your Storybook, runs the tests, and uploads the screenshots to Argos. If you use another CI provider, adapt the steps with Run Argos in CI:

.github/workflows/argos.yml
name: Argos

on:
  pull_request:
  push:
    branches:
      - main

jobs:
  argos:
    runs-on: ubuntu-latest
    timeout-minutes: 30
    steps:
      - uses: actions/checkout@v6
      - uses: actions/setup-node@v6
        with:
          node-version: 22

      - name: Install dependencies
        run: npm ci

      - name: Build Storybook
        run: npm run build-storybook

      - name: Install Playwright dependencies
        run: npx playwright install --with-deps chromium

      - name: Run Storybook tests and capture screenshots
        run: |
          npx concurrently -k -s first -n "SB,TEST" -c "magenta,blue" \
            "npx http-server ./storybook-static --port 6006 --silent" \
            "npx wait-on tcp:127.0.0.1:6006 && npm run test-storybook"

      - name: Upload screenshots to Argos
        run: npm exec -- argos upload ./screenshots
        env:
          ARGOS_TOKEN: ${{ secrets.ARGOS_TOKEN }}

ARGOS_TOKEN is the project token from Settings → Authentication → Project token. On GitHub Actions, you can also use OIDC or tokenless authentication to avoid managing a secret.

To learn how to run tests on a deployed Storybook, refer to the Storybook Test Runner documentation.

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 workflow above uploads screenshots only from CI, so Argos only compares screenshots captured on CI. Keep your CI on the same image and browser version from one run to the next. See Browser glitches and Stabilize screenshots.

Next steps


Last updated

Was this helpful?