fix(vitest-environment): avoid vitest/environments import warning in vitest4.1#1627
fix(vitest-environment): avoid vitest/environments import warning in vitest4.1#1627yamachi4416 wants to merge 3 commits intonuxt:mainfrom
vitest/environments import warning in vitest4.1#1627Conversation
commit: |
📝 WalkthroughWalkthroughThe Estimated code review effort🎯 2 (Simple) | ⏱️ ~12 minutes 🚥 Pre-merge checks | ✅ 3✅ Passed checks (3 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
🧹 Nitpick comments (1)
src/environments/vitest/index.ts (1)
70-74: Consider caching module selection once at module scope.
resolveModulePath(..., { try: true })is currently re-evaluated per setup call. Caching this once avoids repeated sync resolution work.♻️ Proposed refactor
+const vitestEnvironmentPkg = + resolveModulePath('vitest/runtime', { try: true }) ? 'vitest/runtime' : 'vitest/environments' + // This can be removed when dropping support for vitest 4.0.x (We can static import from 'vitest/runtime') async function importVitestEnvironments() { - const pkg = resolveModulePath('vitest/runtime', { try: true }) ? 'vitest/runtime' : 'vitest/environments' - return await import(pkg) as typeof import('vitest/environments') + return await import(vitestEnvironmentPkg) as typeof import('vitest/environments') }🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@src/environments/vitest/index.ts` around lines 70 - 74, The call to resolveModulePath inside importVitestEnvironments is being re-evaluated on every setup call; cache the chosen package name at module scope so resolution runs once. Add a top-level const (e.g., vitestEnvPkg) that computes resolveModulePath('vitest/runtime', { try: true }) ? 'vitest/runtime' : 'vitest/environments' and then update importVitestEnvironments to simply import that cached vitestEnvPkg; keep the return typing as typeof import('vitest/environments').
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Nitpick comments:
In `@src/environments/vitest/index.ts`:
- Around line 70-74: The call to resolveModulePath inside
importVitestEnvironments is being re-evaluated on every setup call; cache the
chosen package name at module scope so resolution runs once. Add a top-level
const (e.g., vitestEnvPkg) that computes resolveModulePath('vitest/runtime', {
try: true }) ? 'vitest/runtime' : 'vitest/environments' and then update
importVitestEnvironments to simply import that cached vitestEnvPkg; keep the
return typing as typeof import('vitest/environments').
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: e6bf591f-a319-4053-af40-07af3bf1e9c4
📒 Files selected for processing (1)
src/environments/vitest/index.ts
🔗 Linked issue
📚 Description
the following warning appeared when importing
vitest/environmentsin Vitest 4.1