Skip to content

fix: restore vitest 4 mock isolation + drop EOL Node 18#25

Merged
GeiserX merged 2 commits into
mainfrom
fix/vitest4-clear-mocks
Jun 1, 2026
Merged

fix: restore vitest 4 mock isolation + drop EOL Node 18#25
GeiserX merged 2 commits into
mainfrom
fix/vitest4-clear-mocks

Conversation

@GeiserX
Copy link
Copy Markdown
Owner

@GeiserX GeiserX commented Jun 1, 2026

Summary

vitest 4 (merged in #24, the critical GHSA-5xrq-8626-4rwp fix) introduced two breakages on main:

  1. Mock call history leaked across tests. vitest 4 changed vi.restoreAllMocks() to only restore vi.spyOn mocks, no longer resetting vi.fn() call history. The test beforeEach blocks relied on it, so call counts accumulated and 9 tests failed. Fixed with clearMocks: true in vitest config.
  2. Node 18 incompatible. vitest 4 uses node:util styleText (Node 20.12+ only). Node 18 is EOL (Apr 2025). Dropped Node 18 from the CI matrix and bumped engines to >=20.

Test plan

  • npx vitest run -> 96/96 pass locally
  • CI Node 20, 22, coverage, docker green
  • Node 18 removed from matrix

vitest 4 changed restoreAllMocks() to no longer reset vi.fn() call
history (only restores spies), causing mock call counts to accumulate
across tests. Enable clearMocks to restore per-test isolation.
@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented Jun 1, 2026

Review Change Stack

📝 Walkthrough

Walkthrough

This PR enables Vitest's automatic mock clearing by adding clearMocks: true to the test configuration. This ensures mocks are reset between tests, improving test isolation and reducing state leakage.

Changes

Vitest Configuration Update

Layer / File(s) Summary
Enable automatic mock clearing
vitest.config.ts
Added clearMocks: true to the Vitest test configuration to automatically reset mocks between test runs.

Estimated code review effort

🎯 1 (Trivial) | ⏱️ ~2 minutes

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Title check ⚠️ Warning The title mentions restoring mock isolation and dropping Node 18, but the PR only addresses mock isolation via clearMocks; no Node 18 changes are present. Update the title to focus solely on the actual change: 'fix: restore vitest 4 mock isolation' or 'fix: enable clearMocks for vitest 4 compatibility'.
✅ Passed checks (4 passed)
Check name Status Explanation
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
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.
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.

✏️ 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 fix/vitest4-clear-mocks

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.

@codecov
Copy link
Copy Markdown

codecov Bot commented Jun 1, 2026

Welcome to Codecov 🎉

Once you merge this PR into your default branch, you're all set! Codecov will compare coverage reports and display results in all future pull requests.

Thanks for integrating Codecov - We've got you covered ☂️

vitest 4 uses node:util styleText, available only on Node 20.12+.
Node 18 reached end-of-life in April 2025. Bump engines and CI matrix
to Node 20/22.
@GeiserX GeiserX changed the title test: restore mock isolation for vitest 4 fix: restore vitest 4 mock isolation + drop EOL Node 18 Jun 1, 2026
@GeiserX GeiserX merged commit 0612d63 into main Jun 1, 2026
8 checks passed
@GeiserX GeiserX deleted the fix/vitest4-clear-mocks branch June 1, 2026 23:09
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