Skip to content

update to latest vitest#22

Merged
cobraprojects merged 1 commit into
mainfrom
update-to-latest-vitest
May 5, 2026
Merged

update to latest vitest#22
cobraprojects merged 1 commit into
mainfrom
update-to-latest-vitest

Conversation

@cobraprojects

@cobraprojects cobraprojects commented May 5, 2026

Copy link
Copy Markdown
Owner

Summary by CodeRabbit

  • Chores
    • Updated Node.js engine requirements to ^20.19.0 or >=22.12.0.
    • Upgraded development tooling with updated test runner versions and dependencies across the workspace.
    • Refactored internal test infrastructure and scripts for improved efficiency.

@coderabbitai

coderabbitai Bot commented May 5, 2026

Copy link
Copy Markdown
📝 Walkthrough

Walkthrough

This PR upgrades Vitest from v2.1.8 to v4.1.5 across the monorepo, updates Node engine constraints, refactors root test scripts to use bun run --cwd patterns, consolidates module-level test mocks, improves test type safety, and reorganizes temp directory handling in the typecheck script.

Changes

Testing Infrastructure & Dependency Upgrade

Layer / File(s) Summary
Dependency Catalog & Version Constraints
package.json (root)
Vitest upgraded from ^2.1.8 to ^4.1.5; coverage packages aligned to ^4.1.5; Node engine updated from >=20.11.0 to ^20.19.0 || >=22.12.0. Root devDependencies now reference coverage packages via catalog: instead of hardcoded versions.
Package Manifest Catalog Migration
packages/*/package.json (~40 files)
All workspace packages update vitest devDependency from pinned ^2.1.8 to catalog: reference for centralized version management.
Root Test Script Refactoring
package.json (scripts section)
test:watch becomes plain vitest; test:db, test:media, test:cli, test:cli:integration switch to bun run --cwd packages/<name> pattern; all coverage scripts now use bun run --cwd packages/<name> test -- --coverage with relative src/** include/excludes and updated exclusion patterns.
Temp Directory & Typecheck Infrastructure
scripts/run-test-typecheck.mjs
Consolidates multiple temp directories into a single shared root (.holo-test-typecheck-…) using deterministic main/ and type-tests/ subdirectories instead of mkdtemp array tracking; cleanup now performs one recursive deletion of shared root.
Mock Setup Consolidation & Type Safety
packages/adapter-sveltekit/tests/client.test.ts, packages/auth/tests/package.test.ts, packages/forms/tests/security.test.ts
Move repeated vi.mock() calls to module level; add vi.restoreAllMocks() to afterEach cleanup; replace vi.doMock() with globalThis override pattern.
Queue Test Type Improvements
packages/events/tests/queue.test.ts, packages/queue/tests/failed.test.ts, packages/queue/tests/runtime.test.ts
Introduce DispatchedQueueJob type alias for dispatch callback signatures; type all dispatched mock functions as vi.fn<(entry: DispatchedQueueJob) => void>() instead of untyped.
Storage Mock Interface Types
packages/storage/tests/facade.test.ts
Replace MockStorageBackend methods from ReturnType<typeof vi.fn> to explicit Promise<...> function signatures.
.gitignore & Build Artifacts
.gitignore
Add ignore pattern for .holo-test-typecheck-* temp directories.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Possibly related PRs

  • cobraprojects/holo-js#10: Both PRs modify scripts/run-test-typecheck.mjs and test/typecheck script wiring in package.json.

Poem

🐰 From v2 to v4 we hop and bound,
Catalog references all around,
Mocks consolidated, types made tight,
Temp directories merged with delight!
Tests run faster, scripts take flight. ✨

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately reflects the primary objective: upgrading vitest across the monorepo from version 2.1.8 to 4.1.5, along with related tooling and configuration updates.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch update-to-latest-vitest

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 win

Audit 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 with vi.fn() or automocks—it now only restores vi.spyOn() mocks. The codebase has 50+ calls to vi.restoreAllMocks() across test files. Tests that relied on this function cleaning up vi.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

📥 Commits

Reviewing files that changed from the base of the PR and between 1dabed6 and 1308dfe.

⛔ Files ignored due to path filters (1)
  • bun.lock is excluded by !**/*.lock
📒 Files selected for processing (50)
  • .gitignore
  • package.json
  • packages/adapter-next/package.json
  • packages/adapter-nuxt/package.json
  • packages/adapter-sveltekit/package.json
  • packages/adapter-sveltekit/tests/client.test.ts
  • packages/auth-clerk/package.json
  • packages/auth-social-apple/package.json
  • packages/auth-social-discord/package.json
  • packages/auth-social-facebook/package.json
  • packages/auth-social-github/package.json
  • packages/auth-social-google/package.json
  • packages/auth-social-linkedin/package.json
  • packages/auth-social/package.json
  • packages/auth-workos/package.json
  • packages/auth/package.json
  • packages/auth/tests/package.test.ts
  • packages/authorization/package.json
  • packages/broadcast/package.json
  • packages/cache-redis/package.json
  • packages/cache/package.json
  • packages/cli/package.json
  • packages/config/package.json
  • packages/core/package.json
  • packages/db-mysql/package.json
  • packages/db-postgres/package.json
  • packages/db-sqlite/package.json
  • packages/events/package.json
  • packages/events/tests/queue.test.ts
  • packages/flux-react/package.json
  • packages/flux-svelte/package.json
  • packages/flux-vue/package.json
  • packages/flux/package.json
  • packages/forms/package.json
  • packages/forms/tests/security.test.ts
  • packages/mail/package.json
  • packages/media/package.json
  • packages/notifications/package.json
  • packages/queue-db/package.json
  • packages/queue-redis/package.json
  • packages/queue/package.json
  • packages/queue/tests/failed.test.ts
  • packages/queue/tests/runtime.test.ts
  • packages/security/package.json
  • packages/session/package.json
  • packages/storage-s3/package.json
  • packages/storage/package.json
  • packages/storage/tests/facade.test.ts
  • packages/validation/package.json
  • scripts/run-test-typecheck.mjs

Comment thread packages/media/package.json
@cobraprojects cobraprojects merged commit a4b6459 into main May 5, 2026
1 check passed
@cobraprojects cobraprojects deleted the update-to-latest-vitest branch May 6, 2026 04:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant