update to latest vitest#22
Conversation
📝 WalkthroughWalkthroughThis PR upgrades Vitest from v2.1.8 to v4.1.5 across the monorepo, updates Node engine constraints, refactors root test scripts to use ChangesTesting Infrastructure & Dependency Upgrade
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 minutes Possibly related PRs
Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 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.
Actionable comments posted: 1
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (1)
packages/mail/package.json (1)
46-51:⚠️ Potential issue | 🟠 Major | ⚡ Quick winAudit tests using
vi.restoreAllMocks()for mock state leakage with Vitest v4.Vitest v4 changed
vi.restoreAllMocks()behavior: it no longer resets or restores mocks created withvi.fn()or automocks—it now only restoresvi.spyOn()mocks. The codebase has 50+ calls tovi.restoreAllMocks()across test files. Tests that relied on this function cleaning upvi.fn()stubs will silently retain state across tests, potentially causing false positives or negatives.🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@packages/mail/package.json` around lines 46 - 51, Tests currently call vi.restoreAllMocks(), but in Vitest v4 that only restores vi.spyOn() spies and does not reset vi.fn() mocks, causing mock state leakage; search for all uses of vi.restoreAllMocks() and replace them with vi.resetAllMocks() (or add afterEach(() => vi.resetAllMocks())) where tests rely on clearing vi.fn() stubs, and keep vi.restoreAllMocks() only when you explicitly need spy restoration; update test helpers/setup files that register global afterEach hooks (look for afterEach(() => vi.restoreAllMocks()) or similar) to call vi.resetAllMocks() instead so vi.fn() mocks are properly reset between tests.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@packages/media/package.json`:
- Line 33: The Vitest upgrade introduces breaking changes: vi.restoreAllMocks()
no longer clears automocks created with vi.mock(), and Vitest 4 requires Vite
>=6; update the "vitest" entry in packages/media/package.json to a proper v4
semver, ensure the repo resolves Vite >=6, then update tests in
packages/media/tests/media.test.ts to explicitly clean mocks you create (replace
usages of vi.restoreAllMocks() that rely on automock cleanup with
vi.unmock('<module>') or explicitly reset each automock with
vi.mocked(<import>).mockReset()/mockRestore() for the modules you call vi.mock()
on). Run the test suite to confirm behavior and adjust any remaining tests that
assumed automocks were cleared by vi.restoreAllMocks().
---
Outside diff comments:
In `@packages/mail/package.json`:
- Around line 46-51: Tests currently call vi.restoreAllMocks(), but in Vitest v4
that only restores vi.spyOn() spies and does not reset vi.fn() mocks, causing
mock state leakage; search for all uses of vi.restoreAllMocks() and replace them
with vi.resetAllMocks() (or add afterEach(() => vi.resetAllMocks())) where tests
rely on clearing vi.fn() stubs, and keep vi.restoreAllMocks() only when you
explicitly need spy restoration; update test helpers/setup files that register
global afterEach hooks (look for afterEach(() => vi.restoreAllMocks()) or
similar) to call vi.resetAllMocks() instead so vi.fn() mocks are properly reset
between tests.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: 5fffa7cd-faed-4c0f-9cc6-a43110fdcfeb
⛔ Files ignored due to path filters (1)
bun.lockis excluded by!**/*.lock
📒 Files selected for processing (50)
.gitignorepackage.jsonpackages/adapter-next/package.jsonpackages/adapter-nuxt/package.jsonpackages/adapter-sveltekit/package.jsonpackages/adapter-sveltekit/tests/client.test.tspackages/auth-clerk/package.jsonpackages/auth-social-apple/package.jsonpackages/auth-social-discord/package.jsonpackages/auth-social-facebook/package.jsonpackages/auth-social-github/package.jsonpackages/auth-social-google/package.jsonpackages/auth-social-linkedin/package.jsonpackages/auth-social/package.jsonpackages/auth-workos/package.jsonpackages/auth/package.jsonpackages/auth/tests/package.test.tspackages/authorization/package.jsonpackages/broadcast/package.jsonpackages/cache-redis/package.jsonpackages/cache/package.jsonpackages/cli/package.jsonpackages/config/package.jsonpackages/core/package.jsonpackages/db-mysql/package.jsonpackages/db-postgres/package.jsonpackages/db-sqlite/package.jsonpackages/events/package.jsonpackages/events/tests/queue.test.tspackages/flux-react/package.jsonpackages/flux-svelte/package.jsonpackages/flux-vue/package.jsonpackages/flux/package.jsonpackages/forms/package.jsonpackages/forms/tests/security.test.tspackages/mail/package.jsonpackages/media/package.jsonpackages/notifications/package.jsonpackages/queue-db/package.jsonpackages/queue-redis/package.jsonpackages/queue/package.jsonpackages/queue/tests/failed.test.tspackages/queue/tests/runtime.test.tspackages/security/package.jsonpackages/session/package.jsonpackages/storage-s3/package.jsonpackages/storage/package.jsonpackages/storage/tests/facade.test.tspackages/validation/package.jsonscripts/run-test-typecheck.mjs
Summary by CodeRabbit
^20.19.0or>=22.12.0.