
Vitest 4 arrived in October 2025, followed by 4.1 in March 2026, and Vitest 5 was released on September 3, 2026. The jump between the two majors is mostly about performance, but it also changes several defaults that affect existing suites. This guide compares the two versions on requirements, behaviour and tooling, then lays out a migration order that surfaces problems early during a lengthy production dependency upgrade.
Requirements
Vitest 4 supported Node.js 20 and Vite 6 and 7, with 4.1 adding Vite 8 support and switching to the project's installed Vite instead of a separate copy. Vitest 5 raises the floor to Node.js 22.12 and Vite 6.4, and the package manifest lists Node 24 and 26 as supported. If your CI runners or Docker images are still on Node 20, the Node upgrade is the first and most disruptive step of the migration, before making any test changes.
Performance changes
The Vitest team built a public benchmark suite for the 5.0 release and reported improvements that ranged from a few percent on CPU-bound suites to roughly half the wall-clock time on dependency-heavy suites running in vmThreads. The gains come from several internal changes: inline projects that do not change the Vite config now share the root Vite server, the on-disk module cache that was experimental in 4.x is now the fsModuleCache option, warm modules reach workers in a single round trip, and the vm pools reuse compiled code and support require of ESM. Browser mode prebundles its runtime and prewarms the browser during Vite startup. Setups dominated by environment setup, such as isolated forks with jsdom, stay roughly the same, so do not expect every project to speed up equally.
Two new diagnostics help you find the right configuration. The reporter prints a duration breakdown with percentages, and performance hints appear when timings suggest a faster setting. The new vitest doctor command runs the suite under alternative configurations and recommends the fastest.
Default behaviour changes
clearMocks is on
In Vitest 4, mock call history accumulated unless you cleared it. Vitest 5 calls vi.clearAllMocks before every test by default. Tests that asserted on counts built up across several tests will fail; move those assertions into the test that makes the calls, or set clearMocks to false to keep the old behaviour while you refactor.
Unawaited assertions fail
Forgetting await on expect().resolves, expect().rejects or toMatchFileSnapshot produced a warning in Vitest 4. In Vitest 5 the test fails. This catches real bugs where an assertion never ran, but it also means previously green tests can turn red for the right reason.
Strict browser locators
In browser mode, locators are exact by default. getByText with the string Item no longer matches an element containing Item 1. Locator errors now print an ARIA snapshot alongside the HTML, controlled by the errorFormat option, which makes mismatches easier to diagnose.
Benchmarks moved
bench is no longer a top-level import. It is a fixture on the test context inside regular test calls, which gives benchmarks access to fixtures, hooks and retries. Baseline comparison arrives through bench.compare and bench.from, and the Tinybench provider can be swapped for a custom one. Any file that imports bench from vitest must be rewritten.
One .vitest folder
The html, json and junit reporters, attachments, failure screenshots and traces now write to a single .vitest directory at the project root. Add it to .gitignore and update any CI step that collected reports from the old locations.
Type-level changes
The Matchers and Assertion types now take the return type first and the received type second. Custom matcher declarations written against the Vitest 4 ordering produce type errors until the generics are swapped. Custom matchers also gain access to the underlying Chai assertion object.
New features worth adopting
vi.when defines per-argument behaviour on spies with deep equality and asymmetric matchers, supports thenReturnOnce and a times option, and pairs with the toHaveBeenExhausted assertion. Fake timers now mock Temporal alongside Date. Trace View records browser-mode interactions as DOM snapshots for replay. Nested projects let a referenced config declare its own projects, inline projects inherit the root config without extends, and the --project filter has a -p shorthand. The --repeats flag runs tests multiple times to expose flakiness, and the html reporter's singleFile option produces one portable file.
A migration order that works
First, upgrade Node.js and Vite in a separate change and confirm the Vitest 4 suite still passes. Second, bump vitest and every @vitest scoped package together, including the UI, coverage and browser packages, so versions match. Third, run the suite once and sort failures into buckets: mock counts, unawaited assertions, locator strictness, bench imports and type errors. Fourth, fix the buckets one at a time with focused commits. Fifth, update CI to collect from the .vitest folder and try vitest doctor to tune the pool configuration. Finally, remove any temporary clearMocks false setting once the tests are restructured.
Should you upgrade now?
If you can meet the Node and Vite requirements, yes. The previous major receives only important fixes on its latest minor, and the behaviour changes in 5 mostly catch real mistakes. Projects stuck on older Node should plan the runtime upgrade first and stay on the last 4.1 patch meanwhile.
Smaller changes you may notice
expect.poll now rejects when it does not settle within its timeout and passes an AbortSignal to its callback. The injectCjsGlobals option can stop Vitest from injecting module, exports, require and the path globals into ES modules. Test titles and inspected values use pretty-format, and test.for placeholders accept non-ASCII characters. The coverage.autoAttachSubprocess option tracks child processes with the v8 provider, and TestCase.logs exposes per-test console output to custom reporters.
Conclusion
Vitest 5 is a performance release with a handful of deliberate default changes: clearMocks on, unawaited assertions failing, strict locators, bench as a fixture and a single .vitest output folder. Compared with Vitest 4 it requires Node.js 22.12 and Vite 6.4, and it adds vi.when, Trace View, nested projects and vitest doctor. Upgrading in the order described here, runtime first and then packages, keeps the migration predictable and leaves you with a faster and stricter suite.

