Core: Implement afterEach - #29584
Conversation
☁️ Nx Cloud ReportCI is running/has finished running commands for commit e038e8b. 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. |
There was a problem hiding this comment.
14 file(s) reviewed, 10 comment(s)
Edit PR Review Bot Settings | Greptile
| }, | ||
| "dependencies": { | ||
| "@storybook/csf": "^0.1.11", | ||
| "@storybook/csf": "0.1.12--canary.109.4d1d54a.0", |
There was a problem hiding this comment.
logic: Pinning to a canary version (0.1.12--canary.109.4d1d54a.0) instead of using ^0.1.11 could cause version conflicts. Consider if this specific version is required or if a caret range would be more appropriate.
| }, | ||
| "dependencies": { | ||
| "@storybook/csf": "^0.1.11", | ||
| "@storybook/csf": "0.1.12--canary.109.4d1d54a.0", |
There was a problem hiding this comment.
logic: Using a canary version (0.1.12--canary) in production dependencies could introduce instability. Consider waiting for a stable release.
|
|
||
| await story.applyAfterEach(context); |
There was a problem hiding this comment.
logic: afterEach should run even if playFunction throws an error. Consider wrapping the play function in try/finally to ensure afterEach always executes.
| if (context.abortSignal.aborted) { | ||
| return; | ||
| } |
There was a problem hiding this comment.
style: Consider handling errors from finalizers to ensure all cleanup runs even if one fails
| }, | ||
| "dependencies": { | ||
| "@storybook/csf": "^0.1.11", | ||
| "@storybook/csf": "0.1.12--canary.109.4d1d54a.0", |
There was a problem hiding this comment.
style: Pinning to a canary version in production dependencies could cause issues if the canary version has bugs or breaking changes. Consider waiting for a stable release.
| "@babel/types": "^7.24.0", | ||
| "@storybook/core": "workspace:*", | ||
| "@storybook/csf": "^0.1.11", | ||
| "@storybook/csf": "0.1.12--canary.109.4d1d54a.0", |
There was a problem hiding this comment.
style: Using a canary version in production dependencies could cause instability. Consider waiting for a stable release.
| }, | ||
| "dependencies": { | ||
| "@storybook/csf": "^0.1.11", | ||
| "@storybook/csf": "0.1.12--canary.109.4d1d54a.0", |
There was a problem hiding this comment.
style: Using a canary version in production dependencies can be unstable. Consider waiting for a stable release or document the rationale for using this specific pre-release version.
| }, | ||
| "dependencies": { | ||
| "@storybook/csf": "^0.1.11", | ||
| "@storybook/csf": "0.1.12--canary.109.4d1d54a.0", |
There was a problem hiding this comment.
style: Using a specific canary version instead of a caret range could cause issues if other packages depend on different versions of @storybook/csf
| "@storybook/core": "workspace:*", | ||
| "@storybook/core-webpack": "workspace:*", | ||
| "@storybook/csf": "0.1.11", | ||
| "@storybook/csf": "0.1.12--canary.109.4d1d54a.0", |
There was a problem hiding this comment.
logic: Using a canary version (0.1.12--canary.109.4d1d54a.0) in production dependencies could lead to instability. Consider using a stable version instead.
| "dependencies": { | ||
| "@storybook/components": "workspace:*", | ||
| "@storybook/csf": "^0.1.11", | ||
| "@storybook/csf": "0.1.12--canary.109.4d1d54a.0", |
There was a problem hiding this comment.
style: using a canary version in production dependencies could cause instability - consider waiting for a stable release
| await this.runPhase(abortSignal, 'afterEach', async () => { | ||
| await applyAfterEach(context); | ||
| }); | ||
|
|
There was a problem hiding this comment.
I would assume that this phase runs after the played event in line 327
|
Merged into |
Closes #
What I did
Working on top of this csf canary:
ComponentDriven/csf#109
To implement this RFC:
#29583
Checklist for Contributors
Testing
The changes in this PR are covered in the following automated tests:
Manual testing
This section is mandatory for all contributions. If you believe no manual test is necessary, please state so explicitly. Thanks!
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.tsMake 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 PR does not have a canary release associated. You can request a canary release of this pull request by mentioning the
@storybookjs/coreteam here.core team members can create a canary release here or locally with
gh workflow run --repo storybookjs/storybook canary-release-pr.yml --field pr=<PR_NUMBER>Greptile Summary
Here's my summary of the PR implementing afterEach functionality in Storybook:
Adds afterEach lifecycle hook to Storybook's story execution pipeline, allowing cleanup operations to be performed after each story runs, with proper phase management and error handling.
applyAfterEachtoPreparedStorytype and implementation to execute finalizers in reverse order (story -> component -> project)RenderPhaseand updatedStoryRenderto run afterEach hooks before transitioning to 'played' or 'errored' statesafterEachfield tocomposeConfigsreturn object using existinggetArrayFieldhelperstory.applyAfterEach(context)call inrunStoryfunction with proper abort signal handling