VARIANCE AUTHORITY
BrowseStorybook

Your test suite

Storybook

Here is what Variance Authority does for your Storybook: it records which lines of your code the preview ran to show each story, and variance run shows each story as a test. One addon and one collector option write the record. Then CI shows only the stories your change reached, you can read what one story ran, and visual review runs on your machine and in CI with no hosted service. Stories that run under @storybook/addon-vitest are Vitest tests, and the Vitest page covers them.

Try it

npm install --save-dev @variance-authority/storybook-collector @variance-authority/cli
npx playwright install chromium
// .storybook/main.js: add one entry to addons
addons: ['@variance-authority/storybook-collector'],
// variance/storybook.mjs
import { storybookCollector } from '@variance-authority/storybook-collector';

export default storybookCollector({ source: { dirs: ['src'] }, tests: true });

Name that module and the built index in variance.config.json, with "subjects": { "kind": "storybook", "index": "storybook-static/index.json", "collector": "variance/storybook.mjs" } beside the keys write the run config lists. Build the preview that records, run once, change a source file, and run again:

npx storybook build --test -o storybook-static
variance run --config variance.config.json
variance run --config variance.config.json --since origin/main
[not observed] story:checkout--summary
not affected by the diff against origin/main: none of its 4 components touched

Probes go in only under --test or a dev server, so the Storybook you publish stays as it is.

What you get

Leave out the stories a change did not reach

--since leaves out each story whose approved image records no changed component and whose recorded lines include none you changed. A preview built before the edit is read against your checkout, and a file changed since the build counts as not instrumented, so every story that ran it is observed. Running less of the suite says how the two records join.

Place shards by recorded time

variance run --config variance.config.json --shard 2/3 places each story file on one job by the time its stories took on the mainline's last run, and a last job merges the reports. Split stories and routes the same way prints the workflow.

Read one story's test story

VARIANCE_AUTHORITY_STORY=1 variance run --config variance.config.json --subjects "story:cart--empty"
variance story --file src/cart.stories.tsx --name "Cart/Empty"

It lists the calls of your code the preview made to show that story, in order, with the branch each one took. Test stories shows how to read one and compare two.

Ask which stories cover a line

Every recorded run also writes one row per story per region, so variance covering --file src/cart.tsx --line 40 names the stories that ran line 40. Covering lists every way to ask.

Visual review

Every variance run paints each story, compares it with its approved image, and reports a changed region with the component that drew it and its file:line. Storybook keeps mounting, decorators and play functions. Compare Storybook stories against approved screenshots sets it up, and works without the recording too.

Not yet

  • Recording from a build without --test or a dev server: the Storybook you publish gets no probes.
  • Recording inside @storybook/addon-vitest: that run is a Vitest run, and the Vitest seam records it where you configured one.
  • Skipping cases does not apply: a story is already the case.

Go further