AddonVitest: Improve perf & fix loading incorrect .env file#33469
Merged
Conversation
…itest "mode" the plugin becomes a no-op. This is important, because users can configure their vite config in such a way that this addon is evaluated during every vite command, not just vitest/test
… be removed in the implementation
…le prior to vitest's `mode`
Contributor
📝 WalkthroughWalkthroughVitest plugin initialization now returns an empty plugin array when the VITEST env flag is falsy. Env resolution is deferred into the plugin config hook via Changes
Sequence Diagram(s)sequenceDiagram
%% Styling for clarity
participant CLI as CLI/Env
participant Presets as Presets
participant VitestPlugin as Vitest Plugin (index.ts)
participant VitestCfg as Vitest Config
participant Transformer as Transform
rect rgb(240,248,255)
CLI->>VitestPlugin: load plugin (with env flags, mode)
alt VITEST falsy
VitestPlugin-->>CLI: return [] (no plugin)
else VITEST truthy
VitestPlugin->>VitestPlugin: enter config hook
VitestPlugin->>Presets: presets.apply('env', {})
Presets-->>VitestPlugin: env object
VitestPlugin->>VitestCfg: set BUILD_TARGET = mode (if present)
VitestPlugin->>VitestCfg: merge env into config
VitestCfg-->>VitestPlugin: finalized config
VitestPlugin->>Transformer: register transform (no VITEST runtime guard)
end
end
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Possibly related PRs
✨ Finishing touches
📜 Recent review detailsConfiguration used: Organization UI Review profile: CHILL Plan: Pro 📒 Files selected for processing (1)
🚧 Files skipped from review as they are similar to previous changes (1)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (3)
Comment |
|
View your CI Pipeline Execution ↗ for commit 75ea041
☁️ Nx Cloud last updated this comment at |
|
View your CI Pipeline Execution ↗ for commit 4021d8d ☁️ Nx Cloud last updated this comment at |
JReinhold
reviewed
Jan 6, 2026
Co-authored-by: Jeppe Reinhold <jeppe@chromatic.com>
JReinhold
approved these changes
Jan 6, 2026
This was referenced Jan 6, 2026
8 tasks
This was referenced Jan 20, 2026
Merged
valentinpalkovic
pushed a commit
that referenced
this pull request
Jan 26, 2026
…on-plugin AddonVitest: Improve perf & fix loading incorrect `.env` file (cherry picked from commit e5d2edd)
8 tasks
8 tasks
This was referenced Apr 30, 2026
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Closes #33101
What I did
I am doing 2 things in this PR:
1: I'm improving the performance of the addon-vitest package, by only evaluating what config to add/change when the code is being called in a vitest environment.
2: Fix a bug where the incorrect .env file is loaded
Checklist for Contributors
Testing
The changes in this PR are covered in the following automated tests:
Manual testing
I discussed with @JReinhold about how to approach testing this, and though we discussed options like, extending a sandbox in some way or writing a unit-test for the function, both would be rather hard to do.
So I'm going to do a manual test using a canary release.
Here's my plan:
🦋 Canary release
This pull request has been released as version
0.0.0-pr-33469-sha-4021d8de. Try it out in a new sandbox by runningnpx storybook@0.0.0-pr-33469-sha-4021d8de sandboxor in an existing project withnpx storybook@0.0.0-pr-33469-sha-4021d8de upgrade.More information
0.0.0-pr-33469-sha-4021d8denorbert/improve-vitest-addon-plugin4021d8de1767695541)To request a new release of this pull request, mention the
@storybookjs/coreteam.core team members can create a new canary release here or locally with
gh workflow run --repo storybookjs/storybook publish.yml --field pr=33469Summary by CodeRabbit
✏️ Tip: You can customize this high-level summary in your review settings.