Running Vitest?

Vitest hanging or coverage empty? We clear it up.

Vitest replaces Jest comfortably on most projects until the day a worker hangs, mocks leak between files, or a Jest-era import suddenly does not resolve under native ESM. We fix the specific failure, align the config with your Vite build, and leave you with a fast test command the team can trust.

  • Since 2015Fixing technology
  • FreeEstimates
  • US teamReal engineers

vitest.log

still failing

What it is

Vitest at a glance

Vitest is a unit test framework built on top of Vite, released by Anthony Fu and the Vite ecosystem in 2021. It shares the same transform pipeline as the dev server, which means TypeScript, JSX, Vue, Svelte and alias configuration work the same way in tests as they do in the application. It ships with a watcher, a UI, coverage via c8 or v8, in-source testing, and a Jest-compatible API surface including vi.mock, vi.spyOn, vi.fn and expect.

The Vitest 1.0 release in late 2023 formalised stability guarantees, and version 2 and 3 added workspaces, improved browser mode, and better concurrent test support. It has become the default testing tool for new Vite, Nuxt, SvelteKit and Astro projects, and a frequent target for teams migrating off Jest.

Type
Vite-native unit test runner
First released
2021
License
MIT, open source
Maintained by
The Vitest and Vite contributors
Typically used for
Unit testing, component testing in jsdom or happy-dom, in-source tests, coverage reports, replacing Jest on Vite projects

The honest version

Vitest pros and cons

No technology is all upside. This is where Vitest earns its place and where it tends to cause trouble.

Where Vitest is strong

  • The same transforms as your appTypeScript, JSX, path aliases and plugins that work in the dev server work in the tests without a second config. The quiet class of failures that used to happen at the Jest boundary disappears.
  • Significantly faster than JestCold runs on a typical project land in seconds rather than minutes, and watch mode re-runs only the affected tests, which keeps the feedback loop tight.
  • Jest-compatible APIdescribe, it, expect and vi.mock behave the way Jest users expect, so most existing suites port with minor changes rather than a rewrite.
  • Great watch and UI modesThe interactive UI, the TUI and the IDE integrations make it painless to run the one test you care about, with hot module replacement for test files.
  • In-source testing is unusual and usefulWriting tests next to the code they cover, enabled by import.meta.vitest, keeps simple utilities honest without a separate test file.
  • Native ESM without workaroundsNo Jest-style transformer gymnastics around ESM-only dependencies. Tests run under the same module system the production code does.

Where Vitest bites

  • Mock hoisting bites in subtle waysvi.mock is hoisted to the top of the file at transform time, which means any variable it references must also be hoisted. The error message is not always clear about why.
  • Migration from Jest is not completely silentjest.requireActual, auto-mocked modules, timers and module boundaries differ enough that a straight sed-replace will leave some tests broken.
  • Browser mode is still maturingRunning tests in a real browser rather than jsdom is a recent feature. It works, but the edges around component libraries and complex DOM APIs are not fully smoothed yet.
  • Coverage tooling changed handsProjects pinned to @vitest/coverage-c8 need to move to @vitest/coverage-v8, and reports can look different between major versions in ways that trip CI thresholds.
  • Parallel workers can hangA test that deadlocks, a worker that cannot deserialise a native module, or a leaked timer will leave Vitest waiting silently rather than failing loudly.
  • Hiring signal is thinner than JestMost developers coming to the project know Jest. Vitest is familiar quickly, but the body of blog posts and Stack Overflow answers is smaller for edge cases.

Sound familiar?

Common Vitest problems we fix

The Vitest problems that bring people to us, and what you have once each one is fixed.

Vitest hangs: 1 test file pending

The run hangs with no output

An unresolved promise, a timer not advanced, or a handle left open on a database connection leaves one worker waiting forever and the whole suite stuck.

Hung workers found, root cause closed

ERR_REQUIRE_ESM

A dependency refuses to load under ESM

A library ships ESM-only, a stray require in test setup tries to load it, and the resolver throws instead of transforming. Jest hid this; Vitest will not.

Imports clean, modules load

vi is not defined

Jest tests mostly work but not quite

A migrated test uses jest.fn or jest.spyOn without the Jest API, or forgets to import vi. Either enable globals or explicitly import, consistently.

Globals consistent across the suite

vi.mock hoisted but references non-hoisted variable

Mocks fail with a baffling error

A factory passed to vi.mock refers to a top-level const that is not declared with vi.hoisted, and the transformer cannot wire it up at parse time.

Mocks hoisted correctly

No inline snapshot found

Snapshot tests behave strangely

Inline snapshots were migrated from Jest but the whitespace or escaping differs, so the snapshot either never writes or does not match on the next run.

Snapshots stable across runs

coverage-c8 not supported

Coverage reports are empty

An older c8 reporter is pinned, or the reporter is listed but not installed, so vitest run --coverage finishes with a zero-line report.

Coverage generated, thresholds honest

expected to have been called once

jsdom timers make tests unreliable

A component uses setTimeout or requestAnimationFrame and the test does not advance the mock clock, so the assertion runs before the callback fires.

Timers controlled, assertions deterministic

Cannot find module './setup.ts'

Config file cannot find the setup file

A path in vitest.config.ts is relative to the wrong root, or a monorepo workspace has not picked up the inherited config correctly.

Paths resolved, config loads

What we do

Vitest help, from migration to maintenance

Call us for one hung run, or let us handle the whole test pipeline.

Rescue
A suite that hangs, a watch mode that never settles, or a coverage report that refuses to populate. We get it finishing before deciding what to change.
Jest to Vitest migration
A full port from Jest, with mocks, timers, snapshots, module boundaries and CI reports verified against the new runner before anything else gets merged.
First-time setup
A new Vitest project wired up correctly: environment, setup files, mocks, aliases, coverage, and the right scripts for local and CI.
Component testing
React, Vue, Svelte or Solid components tested in jsdom, happy-dom or Vitest browser mode, with the trade-offs picked for your stack.
Performance
Workers, isolate settings, test timeouts, shard configuration and reporter choice tuned so CI runs quickly and failures still land with clear output.
Managed Tech
Regular upkeep of the test runner across minor and major releases, and a trusted hand when something in the suite starts going sideways mid-sprint.

How it works

From first message to fixed

  1. Look Free estimate

    Tell us what's going wrong. We look at it, then tell you plainly what's wrong and what it will cost.

  2. Fix

    We fix the cause, not the symptom. If something is down, getting it back up comes first.

  3. Harden

    Backups, monitoring, updates and access, so the same problem can't quietly come back.

  4. Hand back or stay on

    You get a plain-language write-up. Or we stay on for hosting, upkeep and new work.

Often found together

Running Vitest alongside something else?

We work on the whole stack, so the problem can be wherever it actually is.

Questions

Vitest questions

Something else? Call+1 737 727 7327

Can you migrate our Jest suite to Vitest?

Yes, and this is a common request. We map jest globals to the Vitest equivalents, port mocks and timers, handle snapshot formatting differences, and run the suite side by side with Jest on a branch until the two agree. The CI switchover is the last step rather than the first.

Why does our Vitest run hang with no output?

Usually an unresolved promise or a native handle, like a database connection, a WebSocket or a timer, that nobody closed in a test. We run with --reporter verbose to find the pending file, and the stack trace points at the test that forgot to clean up. The fix is almost always one afterEach hook.

Should we use Vitest or stick with Jest?

For projects on Vite, SvelteKit, Nuxt or modern Next.js, Vitest usually wins on speed and on the amount of config you have to maintain. Projects on Create React App or older Webpack stacks with a working Jest setup often do not get enough benefit to justify the migration. We tell you which category you are in before any work is proposed.

Why is coverage showing zero lines?

The common causes are an older @vitest/coverage-c8 reporter that does not work on the current runner, a missing include pattern, or the coverage provider line in vitest.config.ts pointing at something not installed. Once v8 or istanbul is wired up correctly, reports come back in full.

Can Vitest test our React components properly?

Yes. Most teams pair it with Testing Library and jsdom or happy-dom, which covers the vast majority of component tests. For scenarios that genuinely need a real browser, like canvas or layout-dependent code, Vitest browser mode runs the same tests against a real browser instance.

How much does Vitest help cost?

The estimate is at no charge. Send over the current test config and a failing run, and a written price arrives within the day.

Free estimate

Vitest misbehaving in CI?

Tell us what you're running and what's going wrong. A person reads it and comes back with an estimate.

  • No charge to find out what it will take
  • If it's urgent, say so

Replies come from a person. By sending, you authorize us to email you back. No marketing.