The CheckOps Engineer home

Tools directory

V

The CheckOps Engineer

Vitest

Vitest is a free, open-source unit test runner that reuses a Vite project's config, transforms, and plugins.

Visit website

Latest public signals

Not refreshed yet. Refresh reads the public site and, when the entry has a GitHub repository, the latest release.

Visit Website

Introduction

Vitest is a unit test runner built for Vite. It loads the same vite.config plugins and transforms as the application, so a TypeScript or JSX file under test is compiled the way the app compiles it. The API is deliberately close to Jest: describe, it, expect, and vi in place of jest.

The project is MIT-licensed and developed in vitest-dev/vitest. Tests default to a Node environment. Browser mode runs them in a real browser. Coverage uses V8 or Istanbul. Vitest is a unit and component runner, not a cross-browser end-to-end product.

Features

  1. Vite-native transforms: TypeScript, JSX, and CSS handled by Vite plugins are available in tests without a separate Babel config.
  2. Jest-shaped API: describe, it, expect, snapshots, and fake timers. vi.fn, vi.mock, and vi.spyOn cover the common Jest mock calls.
  3. Watch mode: The runner reruns affected tests as modules change, using Vite’s module graph rather than a file-name heuristic alone.
  4. Environments: node, happy-dom, and jsdom are config options. Browser mode runs the suite in Chromium, Firefox, or WebKit.
  5. Workspace projects: One Vitest config can describe several projects (unit, storybook, browser) and run them together or alone.
  6. Coverage: @vitest/coverage-v8 or @vitest/coverage-istanbul report line and branch coverage and can fail on thresholds.
  7. UI and reporters: vitest --ui opens a local results UI. Reporters include default, JSON, JUnit, and HTML.
  8. Type tests: expectTypeOf checks TypeScript types as part of the suite when type testing is enabled.

Pros

  1. The app and the tests share one pipeline: Alias, plugins, and env handling do not get reimplemented in a Jest transform.
  2. Fast feedback on Vite apps: Watch mode stays responsive because unchanged modules are already transformed.
  3. Migration from Jest is mostly mechanical: Many jest.* calls map to vi.*. Snapshots and expect matchers are familiar.
  4. A real browser is optional, not required: Node or happy-dom is enough for logic tests. Browser mode is there when DOM behavior matters.
  5. Free: The MIT license has no seat or snapshot fee.

Cons

  1. Best fit is a Vite project: Other bundlers can run Vitest, but you give up the “same config as the app” reason to pick it.
  2. Not a drop-in for every Jest config: Custom transformers, jest.resetModules timing, and some mock hoisting behavior differ. Large suites need a trial migration, not a rename.
  3. Browser mode is a second setup: It needs a browser provider and is slower than the Node environment. It still is not a full user-journey runner.
  4. Ecosystem age: Jest recipes and Stack Overflow answers still outnumber Vitest ones for older React and Node setups.
  5. Workspace config can sprawl: Multiple projects, environments, and coverage providers recreate the config surface Jest monorepos already have.
npm install --save-dev vitest
npx vitest
npx vitest run
npx vitest --coverage
import { expect, test } from "vitest";
import { add } from "./add";

test("adds two numbers", () => {
  expect(add(1, 2)).toBe(3);
});

vitest run executes once and exits, which is what CI should call. npx vitest stays in watch mode. Put test options in vite.config.ts or a vitest.config.ts if the app config should stay untouched.

Resources:

Pricing

  1. Free: Vitest is MIT-licensed. There is no Vitest cloud plan and no per-test charge.
  2. You pay for CI and browsers: Browser mode uses a local or CI browser. Coverage providers are npm packages, not a subscription.
  1. Vite applications (Vue, React, Svelte, Solid, and others) that already have a vite.config.
  2. New JavaScript or TypeScript libraries that want a Jest-like API without Babel.
  3. Teams leaving Jest after a spike shows that mocks and snapshots port cleanly.
  4. Component tests that can run in happy-dom or jsdom, with browser mode reserved for layout-sensitive cases.

Conclusion

Vitest is the practical default unit runner for a Vite codebase: one transform pipeline, a Jest-like API, and a watch mode that stays fast. It does not retire Playwright or Cypress, and an existing Jest suite should move only after the mock and timer differences are checked. The runner itself stays free.