Repo of the Day
vitest-dev/vitest
Published: Dec 21, 2021
Open repository ↗Testing library for apps running in Vite... its fast!
Summary
Vitest is a JavaScript and TypeScript testing framework that runs on top of Vite. It provides a Jest-compatible API (describe, it, expect, snapshots, mocks) while reusing Vite's configuration, transformers, and plugins to deliver faster startup and an HMR-style watch mode. The project is MIT-licensed and written in TypeScript.
What it is useful for
- Unit and integration tests in Vite-based applications, since it shares the app's build pipeline and plugins instead of duplicating them
- Component testing for Vue, React, Svelte, Lit, and Marko, with an opt-in browser mode that runs tests in a real browser
- Code coverage reporting using v8 or istanbul without third-party plugins
- DOM and browser API mocking through JSDOM or happy-dom
- Type-level assertions via expect-type, alongside out-of-the-box TypeScript and JSX support
- ESM-first projects that need top-level await inside test files
- Micro-benchmarks through the built-in Tinybench integration
- Large test suites that benefit from sharding, filtering, timeouts, and concurrent runs
How engineers can use it
Before adopting Vitest, check the documented prerequisites listed in the README: Vite >=v6.4.0 and Node >=v22.12.0. Projects on older toolchains will need to upgrade first, which is the most concrete constraint called out in the source.
Tests follow the familiar Jest-style structure shown in the README:
import { assert, describe, expect, it } from 'vitest'
describe('suite name', () => {
it('foo', () => {
expect(1 + 1).toEqual(2)
expect(true).to.be.true
})
it('snapshot', () => {
expect({ foo: 'bar' }).toMatchSnapshot()
})
})
Chai is bundled for assertions, so assert.equal(Math.sqrt(4), 2) works alongside the Jest-style expect API. The only CLI invocation explicitly shown in the README is npx vitest, which starts the smart watch mode. For coverage configuration, browser mode, multi-project setups, and other options, the README directs readers to the documentation at vitest.dev rather than enumerating every flag.
A notable documented limitation: the required Vite and Node versions mean Vitest is not a drop-in option for projects still on older toolchains, and some Jest plugins may not have direct equivalents without extra configuration.