-
-
Notifications
You must be signed in to change notification settings - Fork 9.5k
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
Conversation
☁️ Nx Cloud ReportCI is running/has finished running commands for commit df3ab6f. 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
…ew, in that order
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!
c4eb0f5
to
d8507f7
Compare
d8507f7
to
f56d8f8
Compare
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.
PR Summary
- Added
beforeAll
hook support in/code/core/src/preview-api/modules/preview-web/Preview.tsx
- Introduced
composeBeforeAllHooks
in/code/core/src/preview-api/modules/store/csf/beforeAll.ts
- Added unit tests for
beforeAll
in/code/core/src/preview-api/modules/store/csf/beforeAll.test.ts
- Updated
composeConfigs
andportable-stories
to integratebeforeAll
hooks - Added end-to-end tests for
beforeAll
in/code/e2e-tests/storybook-hooks.spec.ts
15 file(s) reviewed, 1 comment(s)
Edit PR Review Bot Settings
…js/yarn.lock
…t/yarn.lock
…t/yarn.lock
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.
PR Summary
(updates since last review)
- Added
beforeAll
hook support in/code/core/src/preview-api/modules/preview-web/Preview.tsx
- Introduced
composeBeforeAllHooks
in/code/core/src/preview-api/modules/store/csf/beforeAll.ts
- Added unit tests for
beforeAll
in/code/core/src/preview-api/modules/store/csf/beforeAll.test.ts
- Updated
composeConfigs
andportable-stories
to integratebeforeAll
hooks - Added end-to-end tests for
beforeAll
in/code/e2e-tests/storybook-hooks.spec.ts
No file(s) reviewed, no comment(s)
Edit PR Review Bot Settings
…te/yarn.lock
…/yarn.lock
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.
PR Summary
(updates since last review)
- Added
beforeAll
hook support in/code/core/src/preview-api/modules/preview-web/Preview.tsx
- Introduced
composeBeforeAllHooks
in/code/core/src/preview-api/modules/store/csf/beforeAll.ts
- Added unit tests for
beforeAll
in/code/core/src/preview-api/modules/store/csf/beforeAll.test.ts
- Updated
composeConfigs
andportable-stories
to integratebeforeAll
hooks - Added end-to-end tests for
beforeAll
in/code/e2e-tests/storybook-hooks.spec.ts
No file(s) reviewed, no comment(s)
Edit PR Review Bot Settings
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.
PR Summary
(updates since last review)
- Added
beforeAll
hook support in/code/core/src/preview-api/modules/preview-web/Preview.tsx
- Introduced
composeBeforeAllHooks
in/code/core/src/preview-api/modules/store/csf/beforeAll.ts
- Added unit tests for
beforeAll
in/code/core/src/preview-api/modules/store/csf/beforeAll.test.ts
- Updated
composeConfigs
andportable-stories
to integratebeforeAll
hooks - Added end-to-end tests for
beforeAll
in/code/e2e-tests/storybook-hooks.spec.ts
No file(s) reviewed, no comment(s)
Edit PR Review Bot Settings
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.
PR Summary
(updates since last review)
- Removed constructor enabling production mode based on NODE_ENV in
/code/frameworks/angular/src/client/angular-beta/AbstractRenderer.ts
- Potential impact on Angular application bootstrapping in different environments
- Watch for changes in performance and debugging capabilities
1 file(s) reviewed, no comment(s)
Edit PR Review Bot Settings
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.
PR Summary
(updates since last review)
- Added
Canvas
type toStoryContext
in/code/core/src/preview-api/modules/store/StoryStore.ts
- Updated
mount
function call to pass props in/code/renderers/svelte/src/public-types.test.ts
- Updated
mount
function call to includeprops
object in/code/renderers/vue3/src/public-types.test.ts
No major changes found since last review.
3 file(s) reviewed, no comment(s)
Edit PR Review Bot Settings
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.
PR Summary
(updates since last review)
- Modified CI environment check in
/code/core/src/core-server/withTelemetry.ts
- Added 'format' parameter support in
/code/frameworks/angular/src/client/docs/sourceDecorator.ts
- Updated
ErrorStory
for consistent stack traces in/code/lib/blocks/src/examples/Button.stories.tsx
3 file(s) reviewed, no comment(s)
Edit PR Review Bot Settings
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.
PR Summary
(updates since last review)
- Updated key generation logic in
/code/addons/interactions/src/components/MethodCall.tsx
for unique keys inArrayNode
- Enhanced Webpack configuration in
/code/frameworks/angular/src/server/plugins/storybook-normalize-angular-entry-plugin.js
to prevent multiple runtime bundle issues - Updated import paths in
/code/lib/blocks/src/blocks/Source.tsx
for improved module structure and maintainability
3 file(s) reviewed, no comment(s)
Edit PR Review Bot Settings
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.
PR Summary
(updates since last review)
- Added end-to-end tests for
beforeAll
hook incode/e2e-tests/storybook-hooks.spec.ts
- Tests ensure correct
beforeAll
execution on load and HMR - Verified sequence of
beforeAll
and cleanup calls
1 file(s) reviewed, 1 comment(s)
Edit PR Review Bot Settings
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 storybook@0.0.0-pr-28255-sha-9d564a0d sandbox
or in an existing project withnpx storybook@0.0.0-pr-28255-sha-9d564a0d 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