Skip to content
Search

Vitest

lastmod 2026-09-23created 2022-04-203 edits

Features

  • Vite's config, transformers, resolvers, and plugins.
  • Use the same setup from your app to run the tests!
  • Smart & instant watch mode, like HMR for tests!
  • Components testing for Vue, React, Svelte, Lit and more
  • Out-of-box TypeScript / JSX support
  • ESM first, top level await
  • Workers multi-threading via tinypool
  • Filtering, timeouts, concurrent for suite and tests
  • Jest Snapshot
  • Chai built-in for assertions + Jest expect compatible APIs
  • Tinyspy built-in for mocking
  • happy-dom or jsdom for DOM mocking
  • Native code coverage via c8
  • Rust like in-source testing

Static imports not available in vi.hoisted

It says "IMPORTS ARE NOT AVAILABLE" in huge letters.

Reducing the number of Vitest workers

One-off: run flags

./npm run test:run -- --maxWorkers=4
./npm run test:run -- --maxWorkers=25%       # 코어 대비 비율
./npm run test:run -- --no-file-parallelism  # 파일을 하나씩 순차 실행

Permanent: config file

In Vitest 4, use maxWorkers directly under test instead of the old poolOptions.threads.maxThreads.

test: {
  maxWorkers: process.env.CI ? undefined : '50%',
  // ...
}

OS-level resource limits

Reliably constrains CPU and memory regardless of Vitest settings.

Tool

Effect

Notes

systemd-run

Limits total CPU and memory via cgroup

On memory overrun, only the test process is killed; the system stays up

nice

Only lowers priority

Still uses all cores, but other tasks run first, so perceived stutter is reduced

taskset

Pins to specified cores only

Reliable limit in units of core count

systemd-run --user --scope -p CPUQuota=400% -p MemoryMax=12G ./npm run test:run
nice -n 19 ./npm run test:run
taskset -c 0-3 ./npm run test:run

Per-worker Node heap limit

NODE_OPTIONS=--max-old-space-size=2048 ./npm run test:run

Note that a worker hitting the limit dies with OOM (out of memory) and the test fails.

See also

author Zer0 sitemap