Vitest
Anthony FuCommunityCreated by Anthony Fu
- Skill
- Tool integration
- Software development
- MIT
- No issues found
AutoGineer summary
Written by AutoGineer from the skill’s own files, not by the author
Vitest is a testing framework built for the Vite ecosystem. It provides a Jest-compatible API and supports ESM, TypeScript, and JSX by default. It shares configuration, transformers, and plugins with Vite applications, allowing for integrated testing workflows. The framework includes features for mocking, snapshot testing, code coverage, and multi-threaded test execution.
What it does
- Provides a Jest-compatible API for writing and running unit tests
- Supports native ESM, TypeScript, and JSX without additional configuration
- Enables mocking of functions, modules, timers, and dates
- Offers built-in code coverage reporting using V8 or Istanbul
- Supports multi-project workspaces and varied test environments like Node, jsdom, and happy-dom
- Includes utilities for snapshot testing, test filtering, and benchmarking
When to use it
- When you need a testing framework that integrates directly with your Vite configuration
- When migrating existing test suites that rely on Jest-compatible APIs
- When you require specific test environments like jsdom or happy-dom for DOM-related testing
- When managing complex test setups across monorepos or multiple projects
Advantages
- Shares configuration and plugins with Vite projects
- Supports parallel test execution via multi-threaded workers
- Provides flexible test environment configuration per file or project
- Includes built-in support for snapshot testing and mocking utilities
Usage examples
- “How do I configure Vitest to use the jsdom environment for my tests?”
- The agent provides the vitest.config.ts configuration snippet using the environment: 'jsdom' property and explains how to install the necessary jsdom package.
- “Can I run different test configurations in the same Vitest process?”
- The agent explains how to use the projects field in the vitest.config.ts file to define multiple test suites with different environments or include patterns.
Install
Download the skill as a ZIP:
https://autogineer.com/agent-skills/antfu/vitest/downloadUnzip it into the cross-client skills folder of your project:
mkdir -p .agents/skills && unzip vitest.zip -d .agents/skills
Documentation by Anthony Fu
Vitest is a next-generation testing framework powered by Vite. It provides a Jest-compatible API with native ESM, TypeScript, and JSX support out of the box. Vitest shares the same config, transformers, resolvers, and plugins with your Vite app.
Key Features:
Vite-native: Uses Vite's transformation pipeline for fast HMR-like test updates
Jest-compatible: Drop-in replacement for most Jest test suites
Smart watch mode: Only reruns affected tests based on module graph
Native ESM, TypeScript, JSX support without configuration
Multi-threaded workers for parallel test execution
Built-in coverage via V8 or Istanbul
Snapshot testing, mocking, and spy utilities
The skill is based on Vitest 5.1.0-beta.1, generated at 2026-10-23.
Core
| Topic | Description | Reference |
|---|---|---|
| Configuration | Vitest and Vite config integration, defineConfig usage | core-config |
| CLI | Command line interface, commands and options | core-cli |
| Test API | test/it function, modifiers like skip, only, concurrent | core-test-api |
| Describe API | describe/suite for grouping tests and nested suites | core-describe |
| Expect API | Assertions with toBe, toEqual, matchers and asymmetric matchers | core-expect |
| Hooks | beforeEach, afterEach, beforeAll, afterAll, aroundEach | core-hooks |
Features
| Topic | Description | Reference |
|---|---|---|
| Mocking | Mock functions, modules, timers, dates with vi utilities | features-mocking |
| Snapshots | Snapshot testing with toMatchSnapshot and inline snapshots | features-snapshots |
| Coverage | Code coverage with V8 or Istanbul providers | features-coverage |
| Test Context | Test fixtures, context.expect, test.extend for custom fixtures | features-context |
| Concurrency | Concurrent tests, parallel execution, sharding | features-concurrency |
| Filtering | Filter tests by name, file patterns, tags | features-filtering |
| Test Tags | Label tests with tags to filter runs and apply shared options | features-test-tags |
| Reporters | Built-in reporters, default selection, CI/output config | features-reporters |
| Benchmarking | Write benchmarks with the bench fixture (Tinybench) | features-benchmarking |
Advanced
| Topic | Description | Reference |
|---|---|---|
| Vi Utilities | vi helper: mock, spyOn, fake timers, hoisted, waitFor | advanced-vi |
| Environments | Test environments: node, jsdom, happy-dom, custom | advanced-environments |
| Type Testing | Type-level testing with expectTypeOf and assertType | advanced-type-testing |
| Projects | Multi-project workspaces, different configs per project | advanced-projects |
Files
- ATTRIBUTION.mdAdded by AutoGineer895 B
- GENERATION.md136 B
- LICENSELicence file added by AutoGineer1.1 KiB
- SKILL.md3.6 KiB
- references/advanced-environments.md4.9 KiB
- references/advanced-projects.md7.4 KiB
- references/advanced-type-testing.md4.6 KiB
- references/advanced-vi.md5.8 KiB
- references/core-cli.md4.9 KiB
- references/core-config.md7.7 KiB
- references/core-describe.md3.5 KiB
- references/core-expect.md8.8 KiB
- references/core-hooks.md4.8 KiB
- references/core-test-api.md5.5 KiB
- references/features-benchmarking.md3.9 KiB
- references/features-concurrency.md4.7 KiB
- references/features-context.md5.3 KiB
- references/features-coverage.md5.0 KiB
- references/features-filtering.md4.8 KiB
- references/features-mocking.md9.8 KiB
- references/features-reporters.md4.0 KiB
- references/features-snapshots.md5.2 KiB
- references/features-test-tags.md3.6 KiB
references/features-concurrency.md
name: concurrency-parallelism description: Concurrent tests, parallel execution, and sharding
Concurrency & Parallelism
File Parallelism
By default, Vitest runs test files in parallel across workers:
defineConfig({
test: {
// Run files in parallel (default: true)
fileParallelism: true,
// Max concurrent workers (v4: replaces maxThreads/maxForks; minWorkers removed)
maxWorkers: 4,
// Pool type: 'forks' (default), 'threads', 'vmForks', 'vmThreads'
pool: 'forks',
},
})v4 pool rework:
poolOptionswas removed — all pool settings are now top-level.singleThread/singleForkbecomemaxWorkers: 1, isolate: false. VMmemoryLimitisvmMemoryLimit. These can now be set per project.
Concurrent Tests
Run tests within a file in parallel:
// Individual concurrent tests
test.concurrent('test 1', async ({ expect }) => {
expect(await fetch1()).toBe('result')
})
test.concurrent('test 2', async ({ expect }) => {
expect(await fetch2()).toBe('result')
})
// All tests in suite concurrent
describe.concurrent('parallel suite', () => {
test('test 1', async ({ expect }) => {})
test('test 2', async ({ expect }) => {})
})Important: Use { expect } from context for concurrent tests.
Opting Out of Concurrency
test.sequential/describe.sequential were removed in v5. Use { concurrent: false }:
describe.concurrent('mostly parallel', () => {
test('parallel 1', async () => {})
// Opt this test out of inherited concurrency
test('must run alone', { concurrent: false }, async () => {})
})
// Or an entire suite
describe('sequential suite', { concurrent: false }, () => {
test('first', () => {})
test('second', () => {})
})Set sequence.concurrent: true to make all tests concurrent by default.
Max Concurrency
Limit concurrent tests:
defineConfig({
test: {
maxConcurrency: 5, // Max concurrent tests per file
},
})Isolation
Each file runs in isolated environment by default:
defineConfig({
test: {
// Disable isolation for faster runs (less safe)
isolate: false,
},
})Sharding
Split tests across machines:
# Machine 1
vitest run --shard=1/3
# Machine 2
vitest run --shard=2/3
# Machine 3
vitest run --shard=3/3CI Example (GitHub Actions)
jobs:
test:
strategy:
matrix:
shard: [1, 2, 3]
steps:
- run: vitest run --shard=${{ matrix.shard }}/3 --reporter=blob
merge:
needs: test
steps:
- run: vitest --merge-reports --reporter=junitMerge Reports
# Each shard outputs blob
vitest run --shard=1/3 --reporter=blob --coverage
vitest run --shard=2/3 --reporter=blob --coverage
# Merge all blobs
vitest --merge-reports --reporter=json --coverageTest Sequence
Control test order:
defineConfig({
test: {
sequence: {
// Run tests in random order
shuffle: true,
// Seed for reproducible shuffle
seed: 12345,
// Hook execution order
hooks: 'stack', // 'stack', 'list', 'parallel'
// All tests concurrent by default
concurrent: true,
// Order projects/groups run in (3.2+); lower runs first
groupOrder: 0,
},
},
})Shuffle Tests
Randomize to catch hidden dependencies:
// Via CLI
vitest --shuffle
// Per suite
describe.shuffle('random order', () => {
test('test 1', () => {})
test('test 2', () => {})
test('test 3', () => {})
})Pools (v4)
poolOptions was removed; pool settings are now top-level and can be set per project:
defineConfig({
test: {
pool: 'forks', // 'forks' (default) | 'threads' | 'vmForks' | 'vmThreads'
maxWorkers: 8,
isolate: true, // threads/forks only; vm* pools are always isolated
vmMemoryLimit: '512MB',
},
})For per-project parallelism/isolation settings, see advanced-projects.
Bail on Failure
Stop after first failure:
vitest --bail 1 # Stop after 1 failure
vitest --bail # Stop on first failure (same as --bail 1)Key Points
Files run in parallel by default (
pool: 'forks'); tests within a file run sequentially unless.concurrentconcurrentonly speeds up tests that await (I/O, timers); pure sync tests still block the threadAlways use context's
expectin concurrent testsUse
{ concurrent: false }(not.sequential) to opt outmaxWorkers(notmaxThreads/maxForks);poolOptionsremoved in v4Sharding splits tests across CI machines;
--merge-reportscombines blob results
<!-- Source references: - https://vitest.dev/guide/parallelism.html - https://vitest.dev/guide/improving-performance.html -->
Requirements and compatibility
Works with: Claude Code, Claude apps, OpenAI Codex, GitHub Copilot, Cursor, Gemini CLI, Kiro, OpenCode, Goose, Amp, Roo Code, JetBrains Junie, Factory Droid, Devin (ex-Windsurf), Mistral Vibe, OpenHands, Letta
“Works with” means the tool reads the open Agent Skills format; a skill written for one tool may use features others lack.
Needs: Needs Node.js
Security
No issues found by our static scan· No issues found
A static scan is not a guarantee. Skills are third-party content: review a skill before you let an agent use it.
Attribution and licence
- Created by
- Anthony Fu
- Publisher
- Anthony Fu (Community)
- Source
- antfu/skills · skills/vitest · commit f63e9ec
- Licence
- MIT License (redistribution allowed)
- LICENSE (added by AutoGineer from LICENSE.md)
- ATTRIBUTION.md (written by AutoGineer)
- Synced
AutoGineer is not affiliated with or endorsed by Anthony Fu or Anthony Fu.
Download ZIP
The ZIP holds the skill’s files, its licence files and an ATTRIBUTION.md. Download vitest.zip