Skip to content
← Insights
Nov 15, 20263 min read

A faster Vitest run is useful only if the same tests still run

Correct the mock-hoisting myth and compare test scope, coverage policy and measured feedback time before migrating runners.

Two test-run trays with matching cards beside a stopwatch and a magnifying glass over a mock module block.

A faster watch run is worth investigating. It is also easy to celebrate a speedup after accidentally dropping part of the test suite.

A Jest-to-Vitest migration should begin with an inventory of what the existing command runs. Preserve that evidence while changing the runner. Then measure whether the new setup improves the feedback loop on the same work.

Establish the comparison before replacing the command

Record the current test-file count and the environments those files use. Save a successful CI result, including coverage configuration if coverage gates the build. Keep the existing command available during the trial.

Choose a representative part of the repository. A small utility package can establish that the basic setup works. It will tell you less about a frontend package with browser mocks and framework-specific transforms.

Measure a cold run separately from a watched rerun after an edit. Startup cost and repeated execution are different parts of the developer experience. Use the same machine and relevant configuration for the comparison.

The result should include failed attempts at migration. If one runner finishes quickly because an unsupported file pattern is excluded, the timing is answering the wrong question.

Correct the mock-hoisting assumption

Vitest's vi.mock reference states that calls are hoisted before imports. Moving the call visually to the top of a file is not a general fix for references that become unavailable after that transformation.

The same documentation provides vi.hoisted for values needed by a hoisted mock factory. It distinguishes vi.doMock, which is not hoisted and affects subsequent imports. Those choices change when the replacement takes effect.

Read a failing mock as a module-loading problem before rewriting it. Determine when the module was imported and which binding the code under test receives. A replacement that happens after the dependency has been loaded may never affect that reference.

CommonJS deserves explicit inspection too. The current vi reference says its module-mocking API does not support modules imported with require(). A test suite using that pattern needs a migration decision, even if its assertion syntax looks familiar.

Similar assertions do not establish equivalent behavior

Vitest's migration guide documents differences from Jest. Work through those that the repository actually uses. Global APIs and mock cleanup are configuration decisions, not details to infer from a passing trivial test.

Include a failure that must remain detectable. Temporarily reintroduce a known defect in the trial branch and confirm the migrated assertion catches it. That is more informative than accepting a new set of snapshots solely because the runner generated them.

Timers need particular attention in asynchronous code. A test can pass after a migration because its scheduling changed or because the awaited work no longer runs. Inspect the expected effect after advancing the clock.

For DOM tests, keep the chosen environment visible in the configuration. A simulated DOM and a real browser cover different behavior. Switching environments during the runner migration introduces another variable into the comparison.

Keep coverage's denominator visible

The current Vitest coverage guide describes V8 and Istanbul providers, along with configuration for including source files. Compare the set of files represented in each report before comparing percentages.

An uncovered module disappearing from the denominator can make the percentage rise without any new behavior being tested. Explicit source inclusion makes that decision reviewable.

Also check thresholds and exclusions. A report with the same headline percentage can enforce a different condition when per-file rules or branch handling change. Preserve the intended policy, then investigate numerical differences.

Jest's current ESM documentation still labels its ECMAScript module support experimental. That is relevant to an ESM migration. It does not establish that every Jest repository should change runners or that Vitest will be faster for your workload.

Finish the trial with the evidence the team will use: equivalent test scope, failures still detected and measured timings. Include any unsupported integration that remains. If the new runner improves the repeated work without weakening those checks, you have a reason to migrate. Keep the old command until the replacement can demonstrate that result in CI.

TestingJavaScriptVitest