Catch unexpected visual changes & UI bugs in your stories
npx @tessl/cli install tessl/npm-chromatic-com--storybook@4.1.0The @chromatic-com/storybook addon provides comprehensive visual testing capabilities that integrate with Chromatic to catch unexpected visual changes and UI bugs in your Storybook stories. It enables automated visual regression testing directly from the Storybook interface, with support for multiple viewports, themes, and browsers.
npx storybook add @chromatic-com/storybookFor Storybook preset configuration:
// .storybook/main.ts
export default {
addons: ['@chromatic-com/storybook'],
};Package exports (from package.json):
{
"exports": {
".": "./dist/index.js", // Main entry (empty export)
"./manager": "./dist/manager.js", // Manager UI bundle
"./preset": "./dist/preset.js", // Server preset configuration
"./package.json": "./package.json"
}
}The addon provides zero-config visual testing through Storybook's interface:
// Stories automatically get visual testing capability
export default {
title: 'Button',
component: Button,
parameters: {
chromatic: {
// Optional: Configure visual test behavior
modes: {
light: { theme: 'light' },
dark: { theme: 'dark' },
},
},
},
};
export const Primary = {
args: {
primary: true,
label: 'Button',
},
};The addon is built around several key components:
Core Storybook addon functionality including preset configuration and UI panel registration. This handles the automatic setup and integration with Storybook's architecture.
// Preset configuration (automatic via package.json exports)
interface PresetConfig {
managerEntries: () => string[];
experimental_serverChannel: (channel: any) => void;
staticDirs: () => string[];
env: () => Record<string, string>;
}Visual test build execution, monitoring, and status tracking. Provides real-time progress updates and comprehensive build state management.
/**
* Execute a Chromatic visual test build
* @param localBuildProgress - Build progress state object
* @param options - Build configuration options
* @returns Promise that resolves when build completes
*/
function runChromaticBuild(
localBuildProgress: LocalBuildProgress,
options: Record<string, any>
): Promise<void>;
/**
* Stop a currently running Chromatic build
*/
function stopChromaticBuild(): void;
interface LocalBuildProgress {
buildId: string;
branch: string;
progress: number;
currentStep: KnownStep;
changeCount: number;
errorCount: number;
stepProgress: StepProgressPayload[];
}
type KnownStep = 'initialize' | 'build' | 'upload' | 'verify' | 'snapshot';Environment configuration, package identifiers, and channel event constants used throughout the addon.
// Environment URLs
declare const CHROMATIC_BASE_URL: string;
declare const CHROMATIC_API_URL: string;
declare const CHROMATIC_INDEX_URL: string;
// Package identifiers
declare const PACKAGE_NAME: '@chromatic-com/storybook';
declare const ADDON_ID: 'chromaui/addon-visual-tests';
declare const PANEL_ID: string;
declare const PARAM_KEY: 'chromatic';
// Channel events
declare const START_BUILD: string;
declare const STOP_BUILD: string;
declare const LOCAL_BUILD_PROGRESS: string;
declare const CONFIG_INFO: string;
declare const GIT_INFO: string;Predefined visual testing configurations for different themes, viewports, and layout options.
interface VisualTestMode {
name: string;
viewport?: { width: number; height: number };
theme?: string;
[key: string]: any;
}
// Predefined mode collections
declare const baseModes: VisualTestMode[];
declare const panelModes: VisualTestMode[];interface AnnouncedBuild {
id: string;
status: 'ANNOUNCED';
branch: string;
commit: string;
}
interface StartedBuild extends AnnouncedBuild {
status: 'STARTED';
startedAt: string;
}
interface CompletedBuild extends StartedBuild {
status: 'PASSED' | 'FAILED' | 'CANCELLED';
completedAt: string;
changeCount: number;
errorCount: number;
}
type SelectedBuildWithTests = StartedBuild | CompletedBuild;interface ConfigurationUpdate {
[key: string]: any;
}
interface ConfigInfoPayload {
configuration: Record<string, any>;
problems: string[];
suggestions: string[];
}
interface ProjectInfoPayload {
projectId: string;
projectToken: string;
projectName: string;
}
interface GitInfoPayload {
branch: string;
commit: string;
uncommittedHash?: string;
parentCommits: string[];
}interface StepProgressPayload {
step: KnownStep;
progress: number;
estimatedDuration: number;
startedAt?: string;
completedAt?: string;
}
type UpdateStatusFunction = (progress: LocalBuildProgress) => void;