npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

storycap-run

v0.1.0

Published

CLI for capturing Storybook screenshots via storycap-testrun

Readme

storycap-run

CLI for capturing Storybook screenshots via storycap-testrun.

Runs vitest with @storybook/addon-vitest under the hood — no manual server or browser startup needed.

Why?

@storybook/addon-vitest runs stories as tests but doesn't capture screenshots. Existing options each have trade-offs:

  • Vitest toMatchScreenshot — assertion-based, requires adding code to each story manually
  • Chromatic — powerful visual regression service, but requires an external paid service
  • storycap (CLI) — captures screenshots from a running Storybook server URL, but requires a separate server process

storycap-run automatically captures screenshots for all stories with zero per-story setup. It reuses your existing @storybook/addon-vitest config — no separate Storybook server needed.

Prerequisites

Your project must have @storybook/addon-vitest configured in vitest.config.ts:

// vitest.config.ts
import { storybookTest } from '@storybook/addon-vitest/vitest-plugin';
import { defineConfig } from 'vitest/config';

export default defineConfig({
  plugins: [storybookTest()],
  test: {
    browser: {
      enabled: true,
      provider: 'playwright',
      name: 'chromium',
    },
  },
});

Install

pnpm add -D storycap-run

Peer dependencies:

  • vitest >= 3.0.0
  • @storybook/addon-vitest >= 8.0.0

Usage

# npm
npx storycap-run

# pnpm
pnpm dlx storycap-run

Filtering works the same as vitest: positional args for file path matching, -t for test name regex.

# Capture all stories
npx storycap-run

# Filter by file path (substring match, like vitest)
npx storycap-run Button

# Multiple file filters (space-separated, like vitest)
npx storycap-run Button Card

# Filter by test name regex (like vitest -t)
npx storycap-run -t "Primary|Secondary"

# Combine file filter and test name filter
npx storycap-run Button -t "Primary"

# Exclude files by glob pattern (like vitest --exclude)
npx storycap-run --exclude "**/*.integration.stories.*"

# List matched stories without capturing
npx storycap-run --dryRun

# Custom output directory
npx storycap-run --outDir ./screenshots

# Select a specific vitest project
npx storycap-run --project storybook

# Run with browser visible
npx storycap-run --headed

# Override viewport size (uses Storybook config by default)
npx storycap-run --viewport 1920x1080

# Show vitest's default reporter output
npx storycap-run --debug

Screenshots are saved to __screenshots__/ by default, organized by story file and story name (e.g. __screenshots__/Button.stories/Primary.png).

Tip: -t alone filters only by test name — all files are still transformed and loaded (same as vitest). For faster runs, combine with file filters: storycap-run Button -t "Primary"

Options

| Option | Alias | Description | Default | |--------|-------|-------------|---------| | [...filters] | | File path patterns (positional, space-separated) | all stories | | --testNamePattern | -t | Regex pattern to filter test names | | | --exclude <glob> | | Exclude files matching glob pattern (repeatable) | | | --outDir <dir> | -o | Output directory | __screenshots__ | | --viewport <WxH> | | Override viewport size (e.g. 1920x1080) | from Storybook | | --project <name> | | Vitest project name to run (e.g. storybook) | | | --dryRun | | List matched stories without capturing | false | | --headed | | Run browser in headed (visible) mode | false | | --debug | | Show vitest's default reporter output | false |

How it works

  1. Discovers your existing vitest config (with storybookTest() plugin)
  2. Creates a temporary wrapper config that injects @storycap-testrun/browser setup into browser-enabled projects
  3. Runs vitest in browser mode — stories render in a real browser
  4. Captures screenshots with CDP metrics stability checks and hash-based retake verification
  5. Saves screenshots to the output directory
  6. Cleans up all temporary files

Per-story configuration

Stories can configure screenshot behavior via Storybook parameters:

export const Primary: Story = {
  parameters: {
    screenshot: {
      skip: true,        // skip this story
      delay: 500,        // extra delay in ms
      mask: '.dynamic',  // mask elements with CSS selector
      remove: '.ads',    // remove elements before capture
    },
  },
};

License

MIT