Skip to content

Conversation

@yannbf
Copy link
Member

@yannbf yannbf commented Sep 15, 2025

Closes #32244

What I did

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

Follow the documentation here:
https://chromatic-ui.notion.site/Storybook-test-syntax-in-CSF-2566e816203480cb95ddc674ddfbf5d3?pvs=74

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-32455-sha-5e1c0619. Try it out in a new sandbox by running npx [email protected] sandbox or in an existing project with npx [email protected] upgrade.

More information
Published version 0.0.0-pr-32455-sha-5e1c0619
Triggered by @yannbf
Repository storybookjs/storybook
Branch feature/test-syntax-in-csf-sb10
Commit 5e1c0619
Datetime Wed Sep 24 08:15:30 UTC 2025 (1758701730)
Workflow run 17970662325

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 canary-release-pr.yml --field pr=32455

Greptile Summary

Updated On: 2025-09-15 09:49:43 UTC

This PR implements a major new feature for Storybook v10: CSF .test syntax that allows developers to write component tests using a familiar, Jasmine-like syntax directly within their story files. The implementation introduces a hierarchical story structure where tests can be attached to stories using a story.test() method (e.g., Primary.test('should render', () => {})).

The feature adds comprehensive infrastructure changes including:

  • Type System Updates: New subtype field distinguishes between regular stories (subtype: 'story') and test entries (subtype: 'test'), with API_TestEntry interface and parent-child relationships via parent and parentName fields
  • CSF Factories Enhancement: Extended csf-factories.ts with .test() method that creates child stories with test-fn and !autodocs tags, combining parent play functions with test functions
  • Story Indexing: Updated indexer to process both story and test entries, creating hierarchical relationships and proper ID generation using toTestId() with colon separator format (storyId:testName)
  • UI Integration: Modified sidebar components to support expandable/collapsible stories with children, new TestNode component with beaker icons, and enhanced tag filtering with inclusion/exclusion logic
  • Vitest Integration: Added transformer support for generating nested describe/test blocks and enhanced test utilities for executing individual story tests
  • Telemetry: Added metrics collection for test usage patterns including test counts per story and adoption statistics

The implementation maintains full backward compatibility while enabling a more organized testing workflow where tests are co-located with stories and displayed as expandable groups in the sidebar. Documentation has been updated to reference @latest instead of @next, indicating preparation for stable release.

Confidence score: 2/5

  • This PR introduces complex new functionality but contains several critical issues that could cause immediate problems in production
  • Score reflects the presence of duplicate function definitions, malformed URLs, and potential console logging that needs cleanup before merge
  • Pay close attention to scripts/tasks/sandbox-parts.ts (duplicate function), URL construction bugs in CLI migration files, and console.log statements in StoryStore.ts

Summary by CodeRabbit

  • New Features
    • Add experimental test syntax: define tests on stories, run in Vitest, and deep-link to individual tests.
    • Sidebar support for test items with dedicated icons, keyboard navigation, and status aggregation.
    • Revamped Tag filters: include/exclude modes, presets, and built-in filters (Documentation, Play, Testing).
    • Story index enriched with subtype and parent linkage; improved search and rendering of test entries.
  • Bug Fixes
    • Stability and typing improvements in navigation, status calculation, and story extraction.
  • Documentation
    • Updated init/upgrade commands to use latest; refined Vitest config examples; removed legacy TOC script.
  • Chores
    • Templates and configs enable experimentalTestSyntax by default in supported setups.

yannbf and others added 30 commits May 22, 2025 19:50
Telemetry: Send index stats on dev exit
(cherry picked from commit c5d386f)
…readonly

CLI: Fix throwing in readonly environments
(cherry picked from commit d87db5c)
Docs: Further improvements
(cherry picked from commit 84ea113)
Onboarding: Tweak referral wording in survey
(cherry picked from commit 74aa094)
…st-9-1

Docs: Fix incorrect @next version specifiers
Docs: Add `afterEach` guidance
(cherry picked from commit b6edefe)
Docs: Fix broken link in migration guide
(cherry picked from commit 8c8bdc5)
Angular: Inherit options from browserTarget
(cherry picked from commit b0f9e0d)
…nces

Docs: Fix essentials addon references
(cherry picked from commit ee184ba)
Addon Docs: Fix Symbol conversion issue in docs page and controls panel

(cherry picked from commit fef67c8)
Telemetry: Improve dev cancellation handling
(cherry picked from commit a65cd6b)
Angular: Fix `entry.polyfills` undefined error
(cherry picked from commit 9f75bbb)
Core: Improve addon detection in automigrations on windows
(cherry picked from commit 70fff63)
Next.js: Return mocked router instead of actual router in useRouter

(cherry picked from commit f0d9efe)
@yannbf yannbf assigned ndelangen and unassigned yannbf Oct 1, 2025
@yannbf yannbf removed the needs qa Indicates that this needs manual QA during the upcoming minor/major release label Nov 24, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ci:merged Run the CI jobs that normally run when merged. csf feature request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Tracking]: .test syntax preview in Storybook