Generated banner for Vitest
Generated logo for Vitest

Vitest

Anthony FuCommunityCreated by Anthony Fu

  • Skill
  • Tool integration
  • Software development
  • MIT
  • No issues found

From the author

Vitest fast unit testing framework powered by Vite with Jest-compatible API. Use when writing tests, mocking, configuring coverage, or working with test filtering and fixtures.
— the description by Anthony Fu

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

  1. Download the skill as a ZIP:

    https://mp-staging.autogineer.com/agent-skills/antfu/vitest/download
  2. Unzip 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

TopicDescriptionReference
ConfigurationVitest and Vite config integration, defineConfig usagecore-config
CLICommand line interface, commands and optionscore-cli
Test APItest/it function, modifiers like skip, only, concurrentcore-test-api
Describe APIdescribe/suite for grouping tests and nested suitescore-describe
Expect APIAssertions with toBe, toEqual, matchers and asymmetric matcherscore-expect
HooksbeforeEach, afterEach, beforeAll, afterAll, aroundEachcore-hooks

Features

TopicDescriptionReference
MockingMock functions, modules, timers, dates with vi utilitiesfeatures-mocking
SnapshotsSnapshot testing with toMatchSnapshot and inline snapshotsfeatures-snapshots
CoverageCode coverage with V8 or Istanbul providersfeatures-coverage
Test ContextTest fixtures, context.expect, test.extend for custom fixturesfeatures-context
ConcurrencyConcurrent tests, parallel execution, shardingfeatures-concurrency
FilteringFilter tests by name, file patterns, tagsfeatures-filtering
Test TagsLabel tests with tags to filter runs and apply shared optionsfeatures-test-tags
ReportersBuilt-in reporters, default selection, CI/output configfeatures-reporters
BenchmarkingWrite benchmarks with the bench fixture (Tinybench)features-benchmarking

Advanced

TopicDescriptionReference
Vi Utilitiesvi helper: mock, spyOn, fake timers, hoisted, waitForadvanced-vi
EnvironmentsTest environments: node, jsdom, happy-dom, customadvanced-environments
Type TestingType-level testing with expectTypeOf and assertTypeadvanced-type-testing
ProjectsMulti-project workspaces, different configs per projectadvanced-projects

Files

references/features-context.md


name: test-context-fixtures description: Test context, custom fixtures with test.extend (builder pattern), scopes, and test.override

Test Context & Fixtures

Built-in Context

Every test receives context as its first argument:

test('context', ({ task, expect, skip, signal, annotate }) => {
  console.log(task.name)        // Test metadata (readonly)
  expect(1).toBe(1)             // Expect bound to this test
  skip(condition, 'reason')     // Skip dynamically
})

Properties:

  • task — test metadata (name, file, etc.)

  • expect — expect bound to this test (required for concurrent snapshot tests)

  • skip(condition?, message?) — skip the test

  • signal (3.2+) — AbortSignal aborted on timeout/cancel/bail

  • annotate(message, type?, attachment?) (3.2+) — attach reporter annotations

  • onTestFinished(fn) / onTestFailed(fn) — per-test cleanup/handlers

  • bench (v5) — benchmark fixture (only in *.bench.ts files)

.extend(name, options?, fixture) infers types automatically. Use onCleanup for teardown:

import { test as baseTest } from 'vitest'

export const test = baseTest
  // Plain value — type inferred as { port: number; host: string }
  .extend('config', { port: 3000, host: 'localhost' })
  // Function fixture — can read previously defined fixtures
  .extend('server', async ({ config }, { onCleanup }) => {
    const server = await startServer(config)
    onCleanup(() => server.close()) // runs after test/scope ends
    return server
  })

test('uses server', ({ config, server }) => {
  expect(server.url).toContain(String(config.port))
})

onCleanup can be called once per fixture. For multiple resources, split into separate fixtures.

Fixture Options
const test = baseTest
  .extend('metrics', { auto: true }, () => new Metrics())       // runs for every test
  .extend('config', { scope: 'worker' }, () => loadConfig())    // once per worker
  .extend('db', { scope: 'file' }, async ({ config }, { onCleanup }) => {
    const db = await createDatabase(config)
    onCleanup(() => db.close())
    return db
  })
  .extend('baseUrl', { injected: true }, () => 'http://localhost:3000') // overridable via config

Object Syntax (Playwright-compatible)

Uses the use() callback; types must be declared manually:

const test = baseTest.extend<{ page: Page; baseUrl: string }>({
  page: async ({}, use) => {
    const page = await browser.newPage()
    await use(page)        // test runs here
    await page.close()     // cleanup after
  },
  baseUrl: 'http://localhost:3000',
})

Tuple form sets options: fixture: [async ({}, use) => {…}, { scope: 'file' }].

Fixture Scopes (3.2+)

ScopeLifetimeCan access
test (default)each testworker + file + test fixtures + built-in context
fileonce per fileworker + file fixtures
workeronce per worker processonly worker fixtures

Only test-scoped fixtures can access the built-in context (task, expect, …). In file/worker fixtures use expect.getState().testPath for the file path. By default every file is its own worker, so file and worker behave the same unless isolation is disabled.

Injected Fixtures (per-project values)

// fixtures.ts
const test = baseTest.extend('url', { injected: true }, '/default')

// vitest.config.ts — provide per project
defineConfig({
  test: {
    projects: [
      { test: { name: 'prod', provide: { url: 'https://prod' } } },
    ],
  },
})

Read raw provided values without fixtures via import { inject } from 'vitest'.

Overriding Fixtures — test.override (4.1+)

test.override replaces fixture values for a suite and its children (replaces the deprecated test.scoped):

describe('production', () => {
  test
    .override('config', { port: 8080, host: 'api.example.com' })
    .override('debug', false)        // chainable

  test('uses prod config', ({ server }) => {
    expect(server.url).toBe('http://api.example.com:8080')
  })
})

// Function override (reads other fixtures) with cleanup
test.override('db', async ({ config }, { onCleanup }) => {
  const db = await createTestDatabase(config)
  onCleanup(() => db.drop())
  return db
})

You cannot introduce new fixtures or change scope/auto via override; use test.extend for new fixtures.

Composing & Hooks

Extend an already-extended test, and use type-aware hooks on the extended test:

import { test as dbTest } from './db-test'

export const test = dbTest.extend('user', ({ db }) => db.createUser())

test.beforeEach(({ db }) => db.seed())            // sees fixtures
test.beforeAll(({ db }) => db.migrate())          // file/worker fixtures only (4.1+)
test.aroundAll(async (run, { db }) => db.tx(run))

Key Points

  • Prefer the builder pattern — types are inferred, cleanup via onCleanup

  • Fixtures are lazy — only initialized when destructured

  • Always destructure { db } (not context.db)

  • Use { scope: 'file' | 'worker' } for expensive shared resources

  • Use test.override (not test.scoped) to vary fixture values per suite

  • Use { injected: true } + project provide for per-project values

<!-- Source references: - https://vitest.dev/guide/test-context.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.

Download ZIP

The ZIP holds the skill’s files, its licence files and an ATTRIBUTION.md. Download vitest.zip