storybook-visual-regression-testing
БесплатноБез исполняемых скриптовНе проверенUse when a repo already has Storybook and wants a visual test per story: the hosted Chromatic addon, or the self-hosted Storybook test-runner with a postVisit…
от testland★ 18 звёзд на GitHubОб этом скилле
storybook-visual-regression-testing
Overview
Storybook ships two officially-supported paths to visual regression testing:
- Hosted (Chromatic addon). Install
@chromatic-com/storybook; every story becomes a Chromatic snapshot automatically. Review happens in the Chromatic UI. This is the default recommendation in the Storybook visual-testing docs. - Self-hosted (test-runner + Playwright snapshots). Install
@storybook/test-runnerand add apostVisithook that callsexpect(page).toHaveScreenshot(). Baselines live in the repo, no external service.
This skill covers both. For full Chromatic CLI behavior (TurboSnap,
exit codes, config file), pair with
chromatic-visual-regression-testing;
for toHaveScreenshot option syntax, pair with
playwright-snapshots.
When to use
- The repo has
.storybook/with a working Storybook config. - The team wants per-story visual coverage (atom-level), not page-level coverage.
- Either: the team is already paying for / using Chromatic (path 1), or the team prefers committed-to-repo baselines (path 2).
Path 1 - Hosted via Chromatic addon
Install
npm install --save-dev @chromatic-com/storybook
(Per storybook-visual-testing.)
Activate
The addon registers itself in Storybook on next start. Sign into Chromatic from the Storybook UI, link the project, then click "Catch a UI change" to capture the first baseline (storybook-visual-testing).
After the first baseline, every story functions as a visual test
automatically - no per-story parameters block, no custom assertion
code.
CI integration
Chromatic CI invocation is identical to running it standalone - see
chromatic-visual-regression-testing
for the npx chromatic CLI flag set, exit codes, TurboSnap, and
chromatic.config.json schema.
Path 2 - Self-hosted via test-runner
Install
npm install --save-dev @storybook/test-runner
(Per storybook-test-runner.)
Add the script to package.json:
{
"scripts": {
"test-storybook": "test-storybook"
}
}
How it works
@storybook/test-runner turns every story into an executable test
powered by Jest + Playwright under the hood (storybook-test-runner).
It requires a Storybook running on a discoverable URL (default
http://localhost:6006) or a published Storybook static build.
Lifecycle hooks
Configure in .storybook/test-runner.ts - three hooks
(storybook-test-runner):
| Hook | When | Use for |
|---|---|---|
setup() |
Once, before all tests | One-time setup (e.g. starting a mock server). |
preVisit(page, context) |
Before each story renders in the browser | Set viewport, inject auth, mock APIs. |
| `postVisit(page, context) | After each story has fully rendered | Visual snapshot, accessibility audit, custom assertion. |
context carries id, title, and name for the current story.
Visual regression via postVisit + Playwright snapshots
.storybook/test-runner.ts:
import type { TestRunnerConfig } from '@storybook/test-runner';
import { expect } from '@playwright/test';
import { getStoryContext } from '@storybook/test-runner';
const config: TestRunnerConfig = {
async postVisit(page, context) {
// Skip stories explicitly opted out
const storyContext = await getStoryContext(page, context);
if (storyContext.parameters?.visualRegression?.disable) return;
// Locate the story's root element and snapshot it
const root = page.locator('#storybook-root');
await expect(root).toHaveScreenshot(
`${context.id}.png`,
{ animations: 'disabled', mask: [page.locator('[data-mask]')] }
);
},
};
export default config;
This captures one PNG per story under
tests/__snapshots__/<context.id>.png (or the path your
playwright.config.ts snapshotPathTemplate resolves to). Per-story
opt-out via a story parameters.visualRegression.disable = true.
For the full toHaveScreenshot option set (mask, threshold,
maxDiffPixels, etc.) and the per-OS / per-browser baseline structure,
see playwright-snapshots.
Running
Two-step: start Storybook, then run the test-runner against it (storybook-test-runner):
# Terminal A - long-running
npm run storybook
# Terminal B
npm run test-storybook
For CI, build a static Storybook and serve it locally during the test run:
npx storybook build && \
npx http-server storybook-static --port 6006 --silent &
SERVER_PID=$!
npx wait-on http://localhost:6006
npm run test-s
Установить storybook-visual-regression-testing в Claude Code и Claude Desktop
Зарегайся, чтобы установить скилл
Создай бесплатный аккаунт, чтобы открыть команду установки и сохранить скилл в библиотеку.
- Открой команду установки в одну строку
- Сохраняй скиллы в синхронизируемую библиотеку
- Уведомления, когда скиллы обновляются
Разрешённые инструменты
Инструменты, которые скиллу разрешено вызывать.
Без ограничений — скилл может использовать любой инструмент.
Вложенные файлы
FAQ
Что делает скилл storybook-visual-regression-testing?
Use when a repo already has Storybook and wants a visual test per story: the hosted Chromatic addon, or the self-hosted Storybook test-runner with a postVisit hook calling Playwright's toHaveScreenshot, plus CI setup.
Как установить скилл storybook-visual-regression-testing?
Скопируй папку скилла в ~/.claude/skills (вкладка Claude Code выше делает это одной командой), либо поставь как плагин.
Скилл storybook-visual-regression-testing запускает скрипты?
Нет, скилл состоит только из инструкций (SKILL.md), без исполняемых скриптов.
Похожие скиллы
mcp-builder
Guide for creating high-quality MCP (Model Context Protocol) servers that enable LLMs to interact with external services through well-designed tools. Use when…
от Anthropicclaude-api
Reference for the Claude API / Anthropic SDK — model ids, pricing, params, streaming, tool use, MCP, agents, caching, token counting, model migration. TRIGGER…
от Anthropicalgorithmic-art
Creating algorithmic art using p5.js with seeded randomness and interactive parameter exploration. Use this when users request creating art using code…
от Anthropicmcp-integration
This skill should be used when the user asks to "add MCP server", "integrate MCP", "configure MCP in plugin", "use .mcp.json", "set up Model Context…
от Anthropic