Esta página se muestra en inglés. Una traducción al español está en curso.
ConfigsApr 11, 2026·2 min de lectura

Vitest — Next Generation Testing Framework Powered by Vite

Vitest is a blazing-fast unit testing framework powered by Vite, with native ESM, TypeScript, and JSX support. Jest-compatible API, instant HMR for tests, and in-source testing make it the go-to test runner for Vite projects.

Introducción

Vitest is a next-generation testing framework powered by Vite. Jest-compatible API with massive performance gains thanks to Vite ESM-native dev server and Rollup bundling. Default choice for Vite projects (Vue, Svelte, Solid, React+Vite).

What Vitest Does

  • Unit tests — Jest-compatible describe/test/expect
  • Watch mode — instant re-run via Vite HMR
  • TypeScript — native, no ts-jest
  • ESM — native ES modules
  • Mocksvi.fn(), vi.mock() matching Jest API
  • Snapshots — inline and file-based
  • Coverage — v8 or istanbul providers
  • Browser mode — run tests in real browser via Playwright
  • In-source testing — tests next to code with if (import.meta.vitest)

Architecture

Uses the same vite.config.ts as the app. Test files transformed by Vite plugins (same as dev). Workers spin up for parallel test execution. Vite dep pre-bundling caches third-party libs for fast startup.

Self-Hosting

Dev tool. Install as devDependency. CI example:

- run: npm ci
- run: npx vitest run --coverage

Key Features

  • Jest-compatible API (easy migration)
  • Native TS/JSX/ESM
  • Vite HMR-powered watch
  • UI mode (browser dashboard)
  • Browser mode (real browser tests)
  • In-source testing
  • Workspace support (monorepos)
  • Benchmark mode (bench/describe)

Comparison

Runner Speed TS ESM Vite
Vitest Fast Native Native Integrated
Jest Slow ts-jest Experimental No
Mocha Medium ts-node Yes No
Bun test Fastest Native Native No

FAQ

Q: Is migration from Jest hard? A: The API is nearly identical. For most projects you just swap imports from jest to vi and replace jest.config with the test field in vite.config.

Q: Can I use Vitest without Vite? A: Yes. Vitest only needs the vite.config config fields — it doesn't need Vite to build the application. But Vite projects get the biggest benefit.

Q: Does it conflict with Playwright? A: No. Vitest handles unit/component tests; Playwright handles E2E. They coexist just fine.

Sources & Credits

Discusión

Inicia sesión para unirte a la discusión.
Aún no hay comentarios. Sé el primero en compartir tus ideas.

Activos relacionados