# Vitest — card for AI agents

Next-generation testing framework powered by Vite with native ESM.

Category: Testing · npm package `vitest` · latest version 5.0.5 (checked 2026-11-01)
Install: `npm install vitest`
License: MIT (permissive)

In your own product (generator, app, hosted service): **yes**. Permissive license: ship it inside your own product, closed or open source, and keep its license and copyright notice.

## Rules for AI agents (paste into AGENTS.md or CLAUDE.md)

## Vitest
- Install as a dev dependency (`npm install -D vitest`). Check that the project has Vite >=v6.4.0 and Node >=v22.12.0.
- Name test files with `.test.` or `.spec.` in the file name. By default, other files are not picked up as tests.
- Put test settings in the existing `vite.config.*`. Create a separate `vitest.config.*` only for test-specific settings.
- Use `vitest run` to run tests once without watching. Plain `vitest` runs in watch mode, which is the default.
- Import test APIs explicitly, for example `import { describe, expect, it } from 'vitest'`.
- Add `.vitest/` to `.gitignore`, because Vitest and its integrations store generated artifacts there.
- On Bun, run tests with `bun run test`, never `bun test`.

## Agent Skills for it
- vitest from midudev/autoskills: `npx skills add midudev/autoskills --skill vitest`
- vitest from antfu/skills: `npx skills add antfu/skills --skill vitest`

## Docs written for agents
- [llms.txt (index of the docs)](https://vitest.dev/llms.txt)

## What it is
- Vitest is a test framework built on Vite. The docs describe it as "a test runner that uses the same configuration as your app". It reads `vite.config.*` and shares one transformation pipeline across dev, build and test. The repository was created in December 2021 and is MIT licensed.
- You do not need Vite to use it. The site says Vitest is Jest-compatible and "works for backend code too." Assertions use Chai, which is built in, alongside Jest `expect` compatible APIs. Watch mode is on by default. Tests can run in Node against simulated DOMs such as jsdom or happy-dom, or natively in a real browser through Browser Mode.
- The maintainers want it to be "the Test Runner of choice for Vite projects". They also pitch it as an alternative for projects that do not use Vite. Their case for it is that Jest and Vite duplicate a lot of work, "forcing users to configure two different pipelines."

## Caveats
- Recent Vite and Node only: The current docs state that Vitest requires Vite `>=v6.4.0` and Node `>=v22.12.0`.
- Browser Mode is not an E2E runner: The docs call Browser Mode "Not a Drop-In Replacement" for standalone end-to-end runners. They recommend adding WebdriverIO, Cypress or Playwright.
- Browser Mode is slower to start: A provider and a browser must start before any test runs. The docs warn this can mean longer initialization than other testing patterns.
- jsdom and happy-dom can mislead: The docs warn that simulated DOMs are not real browsers. Tests run against them can give false positives or false negatives.
- No globals unless you ask: A migration write-up notes that, unlike Jest, Vitest does not provide global test values by default. That team set `globals: true` to ease the move. Because Vitest is ESM first, they also had to load actual modules asynchronously in mocks.

## Numbers (AgentGid data)
- Gid Score: 86.0 (#30 of all tools, 2 of 122 in its category)
- Used in 1,312 public projects set up for AI coding agents (21.0%)
- Downloads last week: 193,983,069 (as of 2026-11-24), +49.4% over 4 weeks
- GitHub stars: 17,433 (as of 2026-11-24)
- Last push: 2026-11-24

## Often used with
jsdom 41.4%, TypeScript 93.7%, Vite 50.5%, Testing Library 36.1%, ESLint 63.0%, Playwright (JavaScript) 41.9%

## Checked alternatives (same job)
- Jest: https://agentgid.com/tools/jest/agent.md
- Nx Jest Plugin: https://agentgid.com/tools/nx-jest/agent.md

## Links
- AgentGid page: https://agentgid.com/tools/vitest/
- Homepage: https://vitest.dev
- Repository: https://github.com/vitest-dev/vitest
- Source: https://github.com/vitest-dev/vitest#readme
- Source: https://github.com/vitest-dev/vitest
- Source: https://github.com/vitest-dev/vitest/releases
- Source: https://vitest.dev
- Source: https://vitest.dev/guide/why.md
- Source: https://vitest.dev/guide.md
- Source: https://vitest.dev/guide/browser/why.md


## Vitest: automatic tests for JavaScript and TypeScript apps

Vitest is a free tool that runs automatic tests for JavaScript and TypeScript code. You or your AI assistant write small checks such as "adding 1 and 2 gives 3", and Vitest runs them again on every change and shows what broke. It fits projects built with Vite and reads the same settings.

### Where to use it
- Check that your functions still work: Write a few small checks for prices, dates or form rules; every change reruns them and a red line shows what broke.
- Keep AI-written code honest: Ask your assistant to add tests with each change, then review them; the guide explains what good prompts and good tests look like.
- Test page parts without a browser: Check that a form or button component renders and reacts, using a simulated page that runs fast in the terminal.
- Test in a real browser: For parts that depend on real layout or browser behaviour, run the same tests inside Chromium through Playwright.
- See which code no test touches: A coverage report lists the lines your tests never ran, so you know where a bug could hide.
- Move an old Jest project over: Existing Jest tests mostly keep working, so a project can switch runners with a few small edits.

### How to start
- Add Vitest to the project as a development tool (it needs Node.js 22.12 or newer and Vite 6.4 or newer).

```
npm install -D vitest
```

- Add a test script to package.json and run it.

```
{
  "scripts": {
    "test": "vitest"
  }
}
```

- In CI or for one-off checks, run once instead of watching.

```
npx vitest run
```


### License
Free to use in any project, paid or not, under the MIT license. No visible credit is needed; keep the license notice with copies of its files.

### Good to know
- Version 5 needs Node.js 22.12 or newer and Vite 6.4 or newer; older setups are not supported.
- By default it keeps watching files during development and runs once on a CI server.
- Simulated browsers (jsdom or happy-dom) are extra packages you install; tests run in plain Node.js unless you choose one.
- The real-browser mode needs an extra provider package; Playwright is the suggested one for CI.
- AI tools tend to fake too much in tests; tell them what not to fake and review the result.

Checked 2026-11-10 against: https://vitest.dev/guide/, https://vitest.dev/guide/why, https://vitest.dev/guide/features, https://vitest.dev/guide/environment, https://vitest.dev/guide/browser/, https://vitest.dev/guide/coverage, https://vitest.dev/guide/mocking/requests, https://vitest.dev/guide/mocking/modules, https://vitest.dev/guide/migration/, https://vitest.dev/guide/migration/jest, https://vitest.dev/guide/learn/writing-tests-with-ai, https://vitest.dev/guide/common-errors, https://vitest.dev/guide/comparisons, https://github.com/vitest-dev/vitest/blob/main/LICENSE, https://registry.npmjs.org/vitest, https://registry.npmjs.org/vitest/5.1.0

### Mistakes to avoid
- Don't: Calling describe, it and expect without importing them (Jest habit) → Do: import { describe, it, expect, vi } from 'vitest' in each file, or set test.globals: true in the config (Vitest does not turn global test functions on by default.)
- Don't: vi.mock('./calculator') inside a describe or test callback → Do: Put vi.mock at the top level of the file (or use vi.doMock where it must run in place) (vi.mock is hoisted to the top of the file; since 5.0 a nested call throws instead of warning.)
- Don't: expect(promise).resolves.toBe(1) without await → Do: await expect(promise).resolves.toBe(1) (Since 5.0 an unawaited async assertion fails the test instead of printing a warning.)
- Don't: Expecting a mock to keep calls recorded in a setup file or beforeAll for later tests → Do: Record calls inside the test, or set test.clearMocks: false to get the 4.x behaviour (Since 5.0 clearMocks defaults to true and wipes call history before every test.)
- Don't: vi.mock('./some-path', () => 'hello') (Jest-style factory) → Do: vi.mock('./some-path', () => ({ default: 'hello' })) (In Vitest the factory returns an object with every export, including default.)

### Questions
- Do I have to use Vite to use Vitest? No. It is built for Vite projects, and the docs call it a solid alternative for projects without Vite too.
- Can I keep my Jest tests? Mostly yes. Differences include no global test functions by default and a different module mock factory shape.
- How do I fake network requests in tests? The docs recommend Mock Service Worker (MSW), which intercepts requests without changes to your app code.
- Which coverage tool does it use? V8 by default, or Istanbul if you choose it; both come as optional extra packages.
- Is it maintained? Yes. Version 5.1.0 was published on 2026-11-02, after the 5.0 release with its own migration guide.

---
AgentGid's catalog is curated: every entry was checked against the maker's official pages (registry, repository, license and pricing pages) on the date shown; a license value shows the quote it stands on wherever AgentGid has one. Usage numbers come from AgentGid's own scan of public repositories set up for AI coding agents. Claims by makers are reported, not tested by AgentGid.
