-
-
Notifications
You must be signed in to change notification settings - Fork 9.8k
Addon-Vitest: Extra changes for Vitest 4 #32600
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
Open
valentinpalkovic
wants to merge
14
commits into
next
Choose a base branch
from
valentin/vitest-4-support
base: next
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+133
−197
Open
Changes from 1 commit
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
d236c85
apply extra fixes
yannbf 8071359
Fix: Don't add triple slash reference to vitest.config files
Copilot ad8d67f
Fix vitest addon to extract coverage config to top-level test object
Copilot 423d58b
Revert "Fix vitest addon to extract coverage config to top-level test…
yannbf 9f996c3
Update Vitest dependencies and refactor imports
ndelangen 10aba50
upgrade cypress in kitchen sink example
yannbf 2e5c563
try aliasing solution for browser context
yannbf 514e6d5
Merge branch 'yann/support-next-16' into valentin/vitest-4-support
ndelangen f155516
fix typing due to switching to use vitest 3 locally
ndelangen a97e3b5
Update viewport test to use internal vitest context alias
ndelangen 87a2680
Reduce parallelism for e2e-dev workflow from 29 to 28 in CircleCI con…
ndelangen 8bd56d2
Merge branch 'next' into valentin/vitest-4-support
yannbf d7fbb48
Merge branch 'next' into valentin/vitest-4-support
ndelangen 10e8b3e
Merge branch 'next' into valentin/vitest-4-support
ndelangen File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,24 @@ | ||
| import semver from 'semver'; | ||
|
|
||
| type VitestBrowserContext = typeof import('@vitest/browser/context'); | ||
|
|
||
| type VitestServerContext = VitestBrowserContext & { | ||
| server: { | ||
| commands: typeof import('@vitest/browser/context').server.commands & { | ||
| getInitialGlobals: () => Promise<Record<string, any>>; | ||
| }; | ||
| }; | ||
| }; | ||
|
|
||
| /** Gets the Vitest browser context based on which version of Vitest is installed. */ | ||
| export const getVitestBrowserContext = async (): Promise<VitestServerContext> => { | ||
| const vitestVersion = await import('vitest/package.json', { with: { type: 'json' } }).then( | ||
| (v) => v.version | ||
| ); | ||
|
|
||
| if (semver.major(vitestVersion) >= 4) { | ||
| return import('@vitest/browser') as unknown as Promise<VitestServerContext>; | ||
| } | ||
|
|
||
| return import('@vitest/browser/context') as Promise<VitestServerContext>; | ||
| }; | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
3 changes: 3 additions & 0 deletions
3
test-storybooks/portable-stories-kitchen-sink/react/.storybook/preview.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
🛠️ Refactor suggestion | 🟠 Major
Replace version sniffing with feature detection to improve robustness.
The current approach uses JSON import attributes and semver to detect Vitest version, but this has several drawbacks:
with: { type: 'json' }) are not universally supported across all Node versions and bundlers, and the module shape may vary (direct properties vsdefault.version).A previous review comment suggested using feature detection instead, which is more robust and eliminates the semver dependency.
Apply the feature detection approach suggested in the prior review:
Optionally, add caching to avoid repeated dynamic imports:
Also applies to: 15-20
🤖 Prompt for AI Agents