Skip to content

Addon-Vitest: Add channel API to programmatically trigger test runs - #33206

Merged
JReinhold merged 29 commits into
nextfrom
jeppe/addon-vitest-trigger-api
Feb 19, 2026
Merged

Addon-Vitest: Add channel API to programmatically trigger test runs#33206
JReinhold merged 29 commits into
nextfrom
jeppe/addon-vitest-trigger-api

Conversation

@JReinhold

@JReinhold JReinhold commented Nov 27, 2025

Copy link
Copy Markdown
Contributor

Works on storybookjs/mcp#138

Companion PR: storybookjs/mcp#131

What I did

Added a new programmatic trigger to addon-vitest, which allows external actors (like addon-mcp) to trigger a test run and get results back via events on the channel.

To support this, I had to make additional modifications:

  1. Add the channel to the options, so that any preset property (like experimental_devServer) automatically has access to the channel and can do stuff with it.
  2. Replaced the flow for how addon-vitest gets the index on the server.

Previously, it would fetch the index.json when necessary; however, it wouldn't know which origin/url to fetch from. To know that, the manager would send the origin to the server (indexUrl) on startup, because the client does know where to fetch the index from. If this sounds bad, it's because it was, but it was a good compromise at the time.

But not anymore, because now you can trigger tests without even opening the manager UI once, which would leave indexUrl undefined, and crash the test run. So now it does the more clear thing, which is possible as of recently, but wasn't before. Now addon-vitest gets the index directly from StoryIndexGenerator on the server, and subscribes to changes to the index, so that when tests are triggered, the index is already available and up-to-date.

Checklist for Contributors

Testing

The changes in this PR are covered in the following automated tests:

  • stories
  • unit tests
  • integration tests
  • end-to-end tests

Manual testing

  1. Have a react-vite Storybook with addon-mcp installed from Add testing toolset mcp#131
  2. Start the dev server and configure the MCP server for your agent
  3. Prompt your agent with "Run tests for the Button component stories using the Storybook MCP testing tool. Use the run-story-tests tool and report which stories passed or failed."
  4. See that it runs tests and reports results back. See that in the Storybook UI, you can see the statuses too in the sidebar/testing widget, because they are all connected.

Documentation

  • Add or update documentation reflecting your changes
  • If you are deprecating/removing a feature, make sure to update
    MIGRATION.MD

Checklist for Maintainers

  • When this PR is ready for testing, make sure to add ci:normal, ci:merged or ci:daily GH label to it to run a specific set of sandboxes. The particular set of sandboxes can be found in code/lib/cli-storybook/src/sandbox-templates.ts

  • Make sure this PR contains one of the labels below:

    Available labels
    • bug: Internal changes that fixes incorrect behavior.
    • maintenance: User-facing maintenance tasks.
    • dependencies: Upgrading (sometimes downgrading) dependencies.
    • build: Internal-facing build tooling & test updates. Will not show up in release changelog.
    • cleanup: Minor cleanup style change. Will not show up in release changelog.
    • documentation: Documentation only changes. Will not show up in release changelog.
    • feature request: Introducing a new feature.
    • BREAKING CHANGE: Changes that break compatibility in some way with current major version.
    • other: Changes that don't fit in the above categories.

🦋 Canary release

This pull request has been released as version 0.0.0-pr-33206-sha-06900f2a. Try it out in a new sandbox by running npx storybook@0.0.0-pr-33206-sha-06900f2a sandbox or in an existing project with npx storybook@0.0.0-pr-33206-sha-06900f2a upgrade.

More information
Published version 0.0.0-pr-33206-sha-06900f2a
Triggered by @JReinhold
Repository storybookjs/storybook
Branch jeppe/addon-vitest-trigger-api
Commit 06900f2a
Datetime Fri Feb 6 12:53:21 UTC 2026 (1770382401)
Workflow run 21751255283

To request a new release of this pull request, mention the @storybookjs/core team.

core team members can create a new canary release here or locally with gh workflow run --repo storybookjs/storybook publish.yml --field pr=33206

Summary by CodeRabbit

  • New Features

    • Programmatic Vitest test-run API with trigger/response flow, optional config override, and new run/result types
    • A11y addon exposes an opt-in preset and a runtime flag; per-run a11y statuses and reports are surfaced
    • In-memory story index for faster lookup and focused-run filtering
  • Refactor

    • Standardized accessibility type names
    • Streamlined channel plumbing across server, build, and presets
  • Tests

    • New tests for selective/focused test triggering and result handling

@nx-cloud

nx-cloud Bot commented Nov 27, 2025

Copy link
Copy Markdown

View your CI Pipeline Execution ↗ for commit a3aad16

Command Status Duration Result
nx run-many -t compile,check,knip,test,pretty-d... ❌ Failed 1m 6s View ↗

☁️ Nx Cloud last updated this comment at 2026-02-19 19:14:14 UTC

@storybook-bot

Copy link
Copy Markdown
Contributor

Failed to publish canary version of this pull request, triggered by @JReinhold. See the failed workflow run at: https://github.com/storybookjs/storybook/actions/runs/19732250010

@storybook-bot

Copy link
Copy Markdown
Contributor

Failed to publish canary version of this pull request, triggered by @JReinhold. See the failed workflow run at: https://github.com/storybookjs/storybook/actions/runs/21150762531

@storybook-bot

Copy link
Copy Markdown
Contributor

Failed to publish canary version of this pull request, triggered by @JReinhold. See the failed workflow run at: https://github.com/storybookjs/storybook/actions/runs/21150973271

@storybook-bot

Copy link
Copy Markdown
Contributor

Failed to publish canary version of this pull request, triggered by @JReinhold. See the failed workflow run at: https://github.com/storybookjs/storybook/actions/runs/21151373423

@JReinhold JReinhold changed the title WIP: Addon-Vitest: Add test trigger API, take screenshots WIP: Addon-Vitest: Add channel API to programmatically trigger test runs Jan 20, 2026
Comment thread code/addons/vitest/src/types.ts
@JReinhold JReinhold changed the title WIP: Addon-Vitest: Add channel API to programmatically trigger test runs Addon-Vitest: Add channel API to programmatically trigger test runs Feb 17, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

addon: a11y addon: vitest ci:normal Run our default set of CI jobs (choose this for most PRs). feature request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants