Repository navigation
Addon Vitest: Support Vitest 5 browser tests - #36270
Conversation
Users on Vitest 5 currently fail peer checks even though the addon is compatible once FEATURES is provided at runtime.
|
Pushed a follow-up that allows Vitest 5 in The FEATURES |
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Essentials Run ID: 📒 Files selected for processing (1)
Included review availability: Your plan provides up to 10 included reviews per hour; 9 remain after this review. WalkthroughThe Vitest plugin now provides typed Storybook feature flags. The setup file injects these flags into the global ChangesVitest feature injection
Sequence Diagram(s)sequenceDiagram
participant VitestPlugin
participant ProvidedContext
participant SetupFile
participant GlobalFEATURES
VitestPlugin->>ProvidedContext: provide resolved Storybook features
SetupFile->>ProvidedContext: read STORYBOOK_TEST_FEATURES_PROVIDE_KEY
SetupFile->>GlobalFEATURES: stub and refresh FEATURES
VitestPlugin->>SetupFile: run Vitest setup
Priority: ⬇️ Low Merge Risk: ⚪ Minimal · up to Vitest 5 compatibility is declared for the addon packages, so the change is ready to merge. Comment |
Frozen lockfile installs failed because package.json already allowed Vitest 5 but yarn.lock still recorded the old peer ranges.
Sandbox vitest jobs fail on this branch because FEATURES.experimentalTestSyntax is unset. That is already fixed on next in #36270.
What I did
Vitest 5 no longer exposes the
FEATURESVite define on the runtime global. React's experimental.test()stories therefore fail even whenexperimentalTestSyntax: trueis configured inmain.ts.Pass the configured flags through Vitest's
provide/injectAPI and initializeFEATURESin the test setup. Restore it before each test sounstubGlobals: trueworks too.Also allow Vitest 5 in
@storybook/addon-vitestpeer ranges (vitest,@vitest/browser,@vitest/browser-playwright,@vitest/runner). That was the only published package that listedvitestas a peer.Verified the same
test-fnstories in Chromium:Also passed 54 plugin unit tests, the addon typecheck, and lint with no errors.
Checklist for Contributors
Testing
The changes in this PR are covered in the following automated tests:
Manual testing
yarn task sandbox --template react-vite/default-ts --start-from auto.vitest@5.0.0and@vitest/browser-playwright@5.0.0versions. Keepfeatures.experimentalTestSyntax: truein.storybook/main.ts.yarn vitest run src/stories/renderers/react/test-fn.stories.tsx. All seven tests should pass.test.unstubGlobals: truein the Vitest config.Documentation
MIGRATION.MD
Checklist for Maintainers
When this PR is ready for testing, make sure to add
ci:normal,ci:mergedorci:dailyGH label to it to run a specific set of sandboxes. The particular set of sandboxes can be found incode/lib/cli-storybook/src/sandbox-templates.tsDeclare whether manual QA will be needed for this PR during the next release, through
qa:neededorqa:skipMake 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 - 🚫 Not run
This PR does not have a canary release associated.
In-repo PRs: add the
ci:canarylabel. Later pushes republish while the label remains.Fork PRs: the label does nothing (a later push must not auto-publish). A maintainer publishes from this repository with Run workflow and the
prinput.branchandshaare optional; if more than one is set, they must be the same commit. The fork author does not need to do anything.