Storycap Test Runner for Storybook Visual Testing
raw JSON →storycap-testrun is a utility designed to provide stable screenshot capture functionality specifically for Storybook components, integrated with `@storybook/test-runner`. While the root `storycap-testrun` package is currently at version 1.0.0, the primary development and new features are delivered through its scoped sub-packages: `@storycap-testrun/node` and `@storycap-testrun/browser`, which are actively maintained and are at version 2.1.0. This library enables visual regression testing by capturing screenshots of Storybook stories, leveraging Playwright for reliable browser automation. It differentiates itself by integrating directly into the `@storybook/test-runner` ecosystem, allowing developers to extend their existing Storybook testing setups with visual verification. Recent updates in the 2.x.x series of the scoped packages include per-story image configuration options and official support for Vitest-based browser testing. The release cadence for the scoped packages appears to be several minor/major updates per year, indicating active development.
Common errors
error ERR_OS_NOT_SUPPORTED: The current operating system is not supported. ↓
npx playwright install to download necessary browser binaries if they are missing or corrupted. error Error: Node.js v18.x is not supported. Please upgrade to Node.js v20.x or higher. ↓
nvm (Node Version Manager) or volta. error TypeError: (0 , storycap_testrun_1.preset) is not a function ↓
import preset from '@storycap-testrun/node/preset'; and ensure @storycap-testrun/node is installed and at version 2.0.0 or higher. Warnings
breaking The `storycap-testrun` package (version 1.0.0) dropped support for Node.js 18. The minimum required Node.js version is now 20. ↓
gotcha Starting from version 2.0.0, the core functionality and new features are primarily delivered through scoped packages: `@storycap-testrun/node` and `@storycap-testrun/browser`. The root `storycap-testrun` package at 1.0.0 may not include these newer features or configurations directly. ↓
gotcha Per-story image options (`fullPage`, `omitBackground`, `scale`) for screenshot capture were introduced in `@storycap-testrun/node` and `@storycap-testrun/browser` at version 2.1.0. These options are set via `parameters.screenshot` in your Storybook stories or `preview.js`. ↓
gotcha Support for `@storybook/addon-vitest` and a new Vitest plugin were added in `@storycap-testrun/browser` at version 2.0.0, accessible via the `/vitest-plugin` export. ↓
Install
npm install storycap-testrun yarn add storycap-testrun pnpm add storycap-testrun Imports
- preset wrong
import { preset } from 'storycap-testrun';correctimport preset from '@storycap-testrun/node/preset'; - VitestPlugin wrong
import { VitestPlugin } from 'storycap-testrun';correctimport { createVitestPlugin } from '@storycap-testrun/browser/vitest-plugin';
Quickstart
// .storybook/test-runner-jest.config.js (or similar Jest/Playwright configuration)
import { defineConfig } from 'jest-runner-storybook';
import preset from '@storycap-testrun/node/preset';
export default defineConfig({
...preset(),
// You can customize Playwright launch options here
// playwright: {
// launchOptions: {
// headless: true,
// },
// },
// Add any other custom Jest configuration
testTimeout: 30000,
});
// Example .storybook/preview.js for per-story options (requires @storycap-testrun/node@2.1.0+)
// import type { Preview } from '@storybook/react';
// const preview: Preview = {
// parameters: {
// screenshot: {
// fullPage: false,
// omitBackground: true,
// scale: 1,
// },
// },
// };
// export default preview;