docs/writing-tests/integrations/vitest-addon/migration-guide.mdx
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.
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.
@storybook/addon-coverage package, which can make your stories render faster.For more, please refer to the comparison table in the Vitest addon guide.
The Vitest addon is supported and recommended for React, Preact, Vue, Svelte, and Web Components projects, which use the Vite builder (or the Next.js framework with Vite).
If you are using a different renderer (such as Angular) or the Webpack builder, you should continue to use the test runner to test your stories.
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.
Remove the following dependencies:
@storybook/test-runner dependency@storybook/addon-coverage dependency (if present)Remove the following files:
test-runner-jest.config.js file (if present).storybook/test-runner.ts file (if present)
prepare hook, please reach out on Discord or open a discussion on GitHub so we can assist you with the migration.@storybook/addon-vitestRun this command, which will set up all the necessary code for you.
<CodeSnippets path="addon-test-install.md" />Update the package.json script for Storybook tests, replacing the test-runner binary and using Vitest instead:
{
"scripts": {
- "test-storybook": "test-storybook"
+ "test-storybook": "vitest --project=storybook"
}
}
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-storybook
If 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.
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.
If your Storybook project uses a non-Vite builder like Webpack or RsPack, you will need to keep using the @storybook/test-runner for your component testing.
Most Webpack-based Storybook projects which do not have complex configurations can migrate to Vite relatively easily. If you are using Next.js, you can use the @storybook/nextjs-vite framework to use Vite with Storybook.
You can still migrate to use Vitest, but if you believe you won't benefit from it, you can keep using the @storybook/test-runner.
There are solutions for image snapshot testing that integrate with the Storybook testing widget:
storybook-addon-vis