-
-
Notifications
You must be signed in to change notification settings - Fork 9.8k
Test: Refactor .test prototype #32314
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
Test: Refactor .test prototype #32314
Conversation
…into kasper/refactor-test-prototype
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.
38 files reviewed, 5 comments
| stories: Record<StoryId, NormalizedStoryAnnotations<TRenderer>>; | ||
| stories: Record< | ||
| StoryId, | ||
| NormalizedStoryAnnotations<TRenderer> & { testFunction?: TestFunction<TRenderer> } |
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.
logic: Type parameter inconsistency: NormalizedStoryAnnotations uses TestFunction<TRenderer, TRenderer['args']> but CSFFile uses TestFunction<TRenderer> without the args parameter
| NormalizedStoryAnnotations<TRenderer> & { testFunction?: TestFunction<TRenderer> } | |
| NormalizedStoryAnnotations<TRenderer> & { testFunction?: TestFunction<TRenderer, TRenderer['args']> } |
| run: ( | ||
| context?: Partial<StoryContext<TRenderer, Partial<TArgs>>>, | ||
| testName?: string | ||
| test?: (context: StoryContext<TRenderer>) => void | Promise<void> |
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.
style: The test parameter uses the full StoryContext<TRenderer> type while the context parameter uses Partial<TArgs> - verify this type inconsistency is intentional
| export function normalizeStory<TRenderer extends Renderer>( | ||
| key: StoryId, | ||
| storyAnnotations: StoryAnnotationsOrFn<TRenderer>, | ||
| storyAnnotations: StoryAnnotationsOrFn<TRenderer> & { testFunction?: any }, |
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.
style: Using any type for testFunction reduces type safety. Consider defining a proper TestFunction type from the CSF types.
| @@ -1,3 +1,4 @@ | |||
| //* @vitest-environment happy-dom */ | |||
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.
syntax: Comment syntax is incorrect - should use // instead of //*
| //* @vitest-environment happy-dom */ | |
| // @vitest-environment happy-dom */ |
| // @ts-ignore TODO: Kasper to figure out later | ||
| this.input.__tests![name] = testStory; | ||
| const annotations = typeof overridesOrTestFn !== 'function' ? overridesOrTestFn : {}; | ||
| const testFunction = typeof overridesOrTestFn !== 'function' ? testFn! : overridesOrTestFn; |
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.
logic: Using non-null assertion testFn! assumes testFn is always provided when overridesOrTestFn is not a function, but TypeScript overloads don't guarantee this at runtime
| const testFunction = typeof overridesOrTestFn !== 'function' ? testFn! : overridesOrTestFn; | |
| const testFunction = typeof overridesOrTestFn !== 'function' ? testFn : overridesOrTestFn; |
|
View your CI Pipeline Execution ↗ for commit 8e74582
☁️ Nx Cloud last updated this comment at |
Package BenchmarksCommit: The following packages have significant changes to their size or dependencies:
|
| Before | After | Difference | |
|---|---|---|---|
| Dependency count | 198 | 199 | 🚨 +1 🚨 |
| Self size | 191 KB | 191 KB | 0 B |
| Dependency size | 29.59 MB | 29.73 MB | 🚨 +146 KB 🚨 |
| Bundle Size Analyzer | Link | Link |
Closes #
What I did
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
This PR introduces a major new testing feature for Storybook that allows test functions to be co-located with stories using a new CSF4 (Component Story Format 4) API. The refactor adds comprehensive support for story-level testing through several key components:
Core Infrastructure Changes:
TestFunctiontype definitions across the CSF type system (code/core/src/csf/story.ts,code/core/src/types/modules/csf.ts)meta.story()andstory.test()APIs for defining stories and their associated testsTesting API Implementation:
story.test(name, testFunction)with optional story annotation overridestoTestId()function generates hierarchical test IDs using colon separator (e.g.,story-id:test-name)run()method that can execute specific tests by nameVitest Integration:
UI Enhancements:
CSF Processing:
__definePreviewThe feature enables developers to write tests directly alongside their stories using familiar testing patterns while leveraging Storybook's component context and utilities. Tests inherit story configuration but can override args, parameters, and globals as needed.
Confidence score: 2/5