-
-
Notifications
You must be signed in to change notification settings - Fork 9.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Core: Add support for beforeAll
hook
#28255
base: next
Are you sure you want to change the base?
Conversation
☁️ Nx Cloud ReportCI is running/has finished running commands for commit 6f660f0. As they complete they will appear below. Click to see the status, the terminal output, and the build insights. 📂 See all runs for this CI Pipeline Execution ✅ Successfully ran 1 targetSent with 💌 from NxCloud. |
3e86b57
to
1f6c183
Compare
beforeAll
hook to projectAnnotations
beforeAll
hook
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good!
Failed to publish canary version of this pull request, triggered by @ghengeveld. See the failed workflow run at: https://github.com/storybookjs/storybook/actions/runs/9644536695 |
e2e-dev is failing but not because of the work in this PR... |
Closes #28268
Depends on ComponentDriven/csf#96 ✅
What I did
This adds the concept of a
beforeAll
function, which runs when the Storybook preview is initialized or preview annotations are updated. In general,beforeAll
runs once, before any loaders, decorators or stories. The API is similar to Vitest's beforeAll (except that timeout is not supported):beforeAll
may be synchronous or asynchronous, and may return a cleanup function which may also be synchronous or asynchronous.beforeAll
may be specified as an export inpreview.js
(by addons or in user's Storybook config) or in a file referenced bypreviewAnnotations
inmain.js
.When multiple
beforeAll
hooks are specified, they will be executed sequentially (and awaited) in the following order:addons
array in.storybook/main.js
)previewAnnotations
array in.storybook/main.js
).storybook/preview.js
)The cleanup function acts like an "afterAll", but is not guaranteed to run because this code typically runs in the browser. However, the Storybook test runner may invoke this function to clean up between test runs. Also, when modifying
preview.js
or a previewAnnotations file, cleanup will run before reinitializingbeforeAll
. Cleanup functions are executed sequentially, in reverse order of initialization:Checklist for Contributors
Testing
The changes in this PR are covered in the following automated tests:
Manual testing
.storybook/before-all.js
with the example beforeAll hook below..storybook/preview.js
to addbeforeAll
(see below).storybook/main.js
to addpreviewAnnotations
(see below)before-all.js
goes first)preview.js
, then check your browser console againExample
beforeAll
hook:Update the log lines so you can distinguish between files (preview.js, before-all.js).
Documentation
MIGRATION.MD
Checklist for Maintainers
When this PR is ready for testing, make sure to add
ci:normal
,ci:merged
orci:daily
GH label to it to run a specific set of sandboxes. The particular set of sandboxes can be found incode/lib/cli/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-28255-sha-9d564a0d
. Try it out in a new sandbox by runningnpx [email protected] sandbox
or in an existing project withnpx [email protected] upgrade
.More information
0.0.0-pr-28255-sha-9d564a0d
beforeAll-hook
9d564a0d
1719237408
)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=28255