Migrating to Vitest addon from test-runner
The test-runner is incompatible with Storybook 11. Follow this guide to replace it with the Vitest addon.
The test-runner was created back in 2021 to enable users to run stories as tests. It is a solution that uses Jest as a runner and Playwright as a browser environment. Over the years, Storybook has evolved and introduced many testing-related concepts, including a Vitest-based testing solution, a spiritual successor to the test-runner. Alongside it, we released a testing widget, allowing users to run tests directly from Storybook's UI and get reports such as a11y and coverage.
You do not have to change how you write your stories between the test-runner and the Vitest addon.
This guide explains how to migrate an existing project using @storybook/test-runner to the @storybook/addon-vitest.
Why migrate?
Migrating to the Vitest addon replaces the previous Jest-based test-runner with a modern, browser-friendly testing stack. It's designed to run stories as tests directly in Storybook's UI while also integrating with Vitest's CLI and IDE integrations — reducing setup complexity and bringing built-in support for accessibility and coverage. The main benefits are summarized below.
- Vitest is used as a runner instead of Jest, offering faster test execution and better integration with modern JavaScript tooling.
- Stories seamlessly integrate as tests in your Vitest setup, significantly simplifying your component test configuration.
- There is no need to build and run Storybook to run tests, which makes the setup faster and more portable.
- Tests are still tested in a Playwright environment, but in Vitest's Browser mode.
- Accessibility testing comes out of the box and integrates with the Storybook testing widget and Accessibility addon panel.
- Code coverage is enabled via Vitest's built-in coverage support. You no longer need instrumentation from the
@storybook/addon-coveragepackage, which can make your stories render faster.
Comparison to the Vitest addon
The test-runner required a running Storybook instance to test your stories, because it visited each one, executed the play function, and listened for results.
The Vitest addon uses a Vitest plugin to transform your stories into tests using Vite and portable stories, so it does not need a running Storybook to test them.
Because of this reliance on Vite, the Vitest addon only works with Storybook frameworks that use Vite, whereas the test-runner could be used with any Storybook framework.
| Feature | test-runner | Vitest addon |
|---|---|---|
| Test types | ||
| - Interaction tests | ✅ | ✅ |
| - Accessibility tests | ✅ | ✅ |
| - Visual tests | ❌ | ✅ |
| - Snapshot tests | ✅ | ❌ |
| Testing contexts | ||
| - Storybook UI | ❌ | ✅ |
| - Editor extensions | ❌ | ✅ |
| - CLI | ✅ | ✅ |
| - In CI | ✅ | ✅ |
| Tests run via | Jest | Vitest |
| Works with all Storybook frameworks | ✅ | ❌ (requires Vite) |
| Runs tests in a real browser environment | ✅ | ✅ |
| Calculates code coverage | ✅ (with addon-coverage) | ✅ |
| Requires a running or published Storybook | ✅ | ❌ |
| Extensible to other addons | ❌ | ✅ |
The test-runner was only a CLI tool. It did not have a UI for running tests, nor did it have an editor extension. The Vitest addon provides a UI in Storybook for running tests, and it enables you to run and debug tests using Vitest IDE integrations.
Additionally, the test-runner ran your stories as orchestrated tests in Jest, and that orchestration came with some complexity. The Vitest addon transforms your stories into real tests and then runs them using Vitest, which is simpler and more configurable.
Finally, because of the simpler architecture and the use of Vitest, the Vitest addon is faster than the test-runner for most projects.
Is my project eligible to upgrade?
The Vitest addon is supported and recommended for React, Preact, Vue, Svelte, Web Components, and Angular projects that use the Vite builder, including the Next.js framework with Vite and the Angular framework with Vite.
If you are using the Webpack builder, migrate to Vite first.
Migration steps
Below you will find the essential steps to migrate from the test-runner to the Vitest addon. Additionally, you can use the following commit as a reference for an example project being migrated.
1. Remove test-runner dependencies
Remove the following dependencies:
@storybook/test-runnerdependency@storybook/addon-coveragedependency (if present)
2. Remove test-runner related files
Remove the following files:
test-runner-jest.config.jsfile (if present).storybook/test-runner.tsfile (if present)- If you had configured accessibility testing, this is now done out of the box with the Vitest addon.
- If you had configured image snapshot testing, check this FAQ.
- If you had configuration for custom, advanced use cases such as using the
preparehook, please reach out on Discord or open a discussion on GitHub so we can assist you with the migration.
3. Set up @storybook/addon-vitest
-
Run this command, which will set up all the necessary code for you.
npx storybook add @storybook/addon-vitest -
Update the
package.jsonscript for Storybook tests, replacing the test-runner binary and using Vitest instead:package.json { "scripts": { - "test-storybook": "test-storybook" + "test-storybook": "vitest --project=storybook" } }
4. Update your CI to run Vitest instead of the test-runner
If you're using the Storybook test-runner in CI, replace its build/serve/wait flow with a single Vitest command. For example, in GitHub Actions:
name: 'Storybook Tests'
on: push
jobs:
test:
timeout-minutes: 60
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version-file: '.nvmrc'
- name: Install dependencies
run: npm ci
- name: Install Playwright
run: npx playwright install --with-deps
- - name: Build Storybook
- run: npm run build-storybook --quiet
- - name: Serve Storybook and run tests
- 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 --coverage"
+ - name: Run storybook tests
+ run: |
+ npm run test-storybookIf you want to generate coverage reports in CI, use the --coverage flag with the test script: npm run test-storybook -- --coverage.
For other CI providers and for more detailed configuration info, check the testing in CI guide.
FAQ
What if I am using Storybook with Webpack or RsPack?
The Vitest addon relies on Vite to transform and run your stories as tests. Which means it only works with Storybook frameworks that use Vite.
The test-runner is incompatible with Storybook 11, so if your Storybook project uses a non-Vite builder like Webpack or Rspack, switch to a Vite-based framework before migrating:
- If you are using Next.js, migrate to the
@storybook/nextjs-viteframework. - If you are using Angular, migrate to the
@storybook/angular-viteframework. - If you are using React with Webpack, migrate to the
@storybook/react-viteframework. - For other frameworks, follow the steps to migrate from Webpack to Vite.
If you cannot switch to Vite, keep using Storybook 10.x, or follow the test-runner migration notes to set up Playwright to run your stories as tests.
What if I am using Jest for my unit tests?
You can keep using Jest for your unit tests. The Vitest addon only runs your stories as tests, so it works alongside an existing Jest setup.
What if I am doing image snapshot testing?
There are solutions for image snapshot testing that integrate with the Storybook testing widget:
- On the cloud with the Visual tests addon
- Locally with
storybook-addon-vis
