Skip to main content
Technology & EngineeringDesign Tool Services162 lines

Chromatic

Automate visual regression testing with Chromatic. Configure snapshot capture, UI review workflows, and TurboSnap to catch unintended visual changes in Storybook components before they reach production.

Quick Summary25 lines
You are an expert in Chromatic, the visual testing platform built by the Storybook team. You configure snapshot pipelines that catch pixel-level regressions, manage UI review workflows for design sign-off, and optimize build costs with TurboSnap and targeted story selection.

## Key Points

- **Running Chromatic without `fetch-depth: 0`** -- TurboSnap needs full git history to compute changed files; shallow clones disable it silently.
- **Setting `diffThreshold: 1` globally** -- effectively turns off visual testing; set thresholds per-story for known flaky elements only.
- **Snapshotting animated stories without `delay`** -- captures mid-animation frames causing false positives on every build.
- **Skipping UI Review and auto-accepting everything** -- defeats the purpose; reserve `--auto-accept-changes` for the main branch only.
- Maintaining a design system where visual consistency across dozens of components is critical.
- Running CI checks that block merges when unreviewed visual changes are detected.
- Coordinating designer approval of UI changes before deploy via the Chromatic review UI.
- Testing responsive layouts across multiple breakpoints without manual QA.
- Replacing flaky screenshot-based E2E tests with deterministic Storybook snapshots.

## Quick Example

```bash
npm install -D chromatic
```

```bash
npx chromatic --only-changed
```
skilldb get design-tool-services-skills/chromaticFull skill: 162 lines
Paste into your CLAUDE.md or agent config

Chromatic Visual Regression Testing

You are an expert in Chromatic, the visual testing platform built by the Storybook team. You configure snapshot pipelines that catch pixel-level regressions, manage UI review workflows for design sign-off, and optimize build costs with TurboSnap and targeted story selection.

Core Philosophy

Every Pixel Is a Contract

Visual tests complement unit and integration tests by asserting what the user actually sees. A component can pass all logic tests yet ship a broken layout. Chromatic captures baselines and diffs to enforce visual contracts.

Review, Don't Just Detect

Detection without a review workflow creates noise. Use Chromatic's UI Review to assign designers and engineers as reviewers so visual changes are explicitly approved or rejected, not silently merged.

Optimize Snapshots Ruthlessly

Each snapshot costs money and CI time. Use TurboSnap to skip unchanged stories, filter by component path, and avoid unnecessary viewport or theme permutations in non-critical stories.

Setup

npm install -D chromatic
// package.json
{
  "scripts": {
    "chromatic": "chromatic --project-token=$CHROMATIC_PROJECT_TOKEN"
  }
}
# .github/workflows/chromatic.yml
name: Chromatic
on: push
jobs:
  visual-test:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
        with:
          fetch-depth: 0 # Required for TurboSnap
      - uses: actions/setup-node@v4
        with: { node-version: 20 }
      - run: npm ci
      - uses: chromaui/action@latest
        with:
          projectToken: ${{ secrets.CHROMATIC_PROJECT_TOKEN }}
          onlyChanged: true # TurboSnap

Key Patterns

Do: Enable TurboSnap with onlyChanged

npx chromatic --only-changed

TurboSnap uses git history plus Webpack/Vite dependency graphs to snapshot only stories whose code or dependencies actually changed.

Not: Snapshot every story on every push

# Wastes budget -- unchanged stories produce identical baselines
npx chromatic

Do: Set per-story snapshot parameters

export const Hero: Story = {
  parameters: {
    chromatic: {
      viewports: [375, 1200],
      delay: 500, // wait for animation
      diffThreshold: 0.2, // allow minor anti-aliasing diffs
    },
  },
};

Common Patterns

Disable snapshots for interaction-only stories

export const ClickFlow: Story = {
  parameters: { chromatic: { disableSnapshot: true } },
  play: async ({ canvasElement }) => {
    // interaction-only test, no visual assertion needed
  },
};

Multi-viewport testing for responsive components

const meta: Meta<typeof NavBar> = {
  component: NavBar,
  parameters: {
    chromatic: { viewports: [320, 768, 1280] },
  },
};

Theme matrix via global decorators

// .storybook/preview.ts
import type { Preview } from "@storybook/react";

const preview: Preview = {
  globalTypes: {
    theme: {
      defaultValue: "light",
      toolbar: { items: ["light", "dark"], dynamicTitle: true },
    },
  },
  parameters: {
    chromatic: { modes: { light: { theme: "light" }, dark: { theme: "dark" } } },
  },
};
export default preview;

Ignore specific DOM regions

export const DynamicTimestamp: Story = {
  parameters: {
    chromatic: {
      // CSS selector for regions to ignore during diff
      ignoreSelectors: [".timestamp", "[data-chromatic-ignore]"],
    },
  },
};

CI gating with exit codes

# --exit-zero-on-changes: don't fail CI, just report
# --auto-accept-changes main: auto-accept on main branch
npx chromatic \
  --only-changed \
  --auto-accept-changes main \
  --exit-once-uploaded

Anti-Patterns

  • Running Chromatic without fetch-depth: 0 -- TurboSnap needs full git history to compute changed files; shallow clones disable it silently.
  • Setting diffThreshold: 1 globally -- effectively turns off visual testing; set thresholds per-story for known flaky elements only.
  • Snapshotting animated stories without delay -- captures mid-animation frames causing false positives on every build.
  • Skipping UI Review and auto-accepting everything -- defeats the purpose; reserve --auto-accept-changes for the main branch only.

When to Use

  • Maintaining a design system where visual consistency across dozens of components is critical.
  • Running CI checks that block merges when unreviewed visual changes are detected.
  • Coordinating designer approval of UI changes before deploy via the Chromatic review UI.
  • Testing responsive layouts across multiple breakpoints without manual QA.
  • Replacing flaky screenshot-based E2E tests with deterministic Storybook snapshots.

Install this skill directly: skilldb add design-tool-services-skills

Get CLI access →

Related Skills

Design Tokens

Manage cross-platform design tokens with Style Dictionary. Define token schemas, configure transforms and formats, and output CSS custom properties, Tailwind themes, iOS, and Android values from a single source of truth.

Design Tool Services201L

Figma API

Integrate with the Figma REST API and webhooks to read design files, extract components, manage variables, export images, and sync comments. Covers authentication, pagination, and real-time event handling for design-to-code workflows.

Design Tool Services166L

Iconify

Integrate icons at scale with the Iconify framework. Use framework-specific components for React and Vue, register custom icon sets, and leverage the Iconify API for on-demand SVG delivery without bundling thousands of icons.

Design Tool Services181L

Sharp

Process images at high performance with Sharp. Resize, crop, convert formats, extract metadata, and build streaming pipelines for thumbnails, responsive images, and batch transformations using libvips under the hood.

Design Tool Services177L

Storybook

Develop and test UI components in isolation with Storybook. Configure stories, addons, args, play functions, and visual testing to build a living component library with interactive documentation and automated interaction tests.

Design Tool Services164L

Tailwind Plugins

Build custom Tailwind CSS plugins that add utilities, components, and variants. Configure theme extensions, create design-system primitives, and author shareable plugins with proper type safety and documentation.

Design Tool Services196L