All skills
antfu avatar

/vitest

@d02c484 official
by Anthony Fuantfu/skills5.9k stars
335

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.

Use this Skill: https://skilld.dev/gh/antfu/skills/vitest

This session only. Nothing lands on disk.

referencesfeatures-reporters.md

≈1k tokens on demand. Your agent reads this file only when SKILL.md points to it.

Reporters

Select reporters via --reporter or reporters config. Configuring reporters replaces the default list — spread configDefaults.reporters to keep them.

import { configDefaults, defineConfig } from 'vitest/config'

export default defineConfig({
  test: {
    reporters: ['verbose', ['junit', { suiteName: 'UI tests' }]],
    // keep defaults and add one:
    // reporters: ['json', ...configDefaults.reporters],
  },
})

Default Selection

When reporters is unset, Vitest auto-selects:

  • default for normal terminal runs
  • minimal (alias agent) when it detects an AI coding agent — only failed tests + errors, no summary or passing logs, optimized to cut token usage
  • github-actions is added when process.env.GITHUB_ACTIONS === 'true'

Built-in Reporters

Reporter Use
default Summary + collapses passing files; prints full tree for single/failing file
verbose One line per finished test (flat list in v4); only reporter that shows annotations on pass
tree Like default but always shows each test (the old v3 verbose)
dot One dot per test; details only for failures
minimal / agent Failures only; best for AI/LLM workflows
junit JUnit XML (templated, see below)
json Jest-compatible JSON; includes coverageMap when coverage enabled
tap / tap-flat TAP (nested / flat)
html Interactive UI report (needs @vitest/ui)
blob Serialized results for --merge-reports
github-actions Workflow annotations + job summary
hanging-process Lists processes preventing exit (debugging)

v4 removed the basic reporter (equivalent to ['default', { summary: false }]). The old verbose flat behavior moved here; use tree for the nested view.

Output Files

v5: the json and junit reporters now write to a file by default (.vitest/json/output.json, .vitest/junit/output.xml) instead of stdout. If you piped output (vitest --reporter=json | jq), read the artifact instead or opt back in with reporters: [['json', { stdout: true }]]. An explicit outputFile is still respected.

vitest --reporter=json --outputFile=./test-output.json
defineConfig({
  test: {
    reporters: ['junit', 'json'],
    outputFile: { junit: './junit.xml', json: './report.json' },
  },
})

JUnit Templating

reporters: [['junit', {
  suiteNameTemplate: '{title}',     // {title} {filename} {basename} {displayName}
  classnameTemplate: '{classname}', // {classname} {title} {suitename} {filename} ...
  titleTemplate: '{title}',
  ancestorSeparator: ' > ',
  addFileAttribute: true,
}]]

{filename} is the relative path (use {basename} for the bare name). Templates can also be functions receiving all variables.

HTML Report (v5 paths)

The HTML reporter writes a directory via outputDir (default .vitest); the entry is <outputDir>/index.html. Use singleFile: true for a self-contained shareable file (large; coverage not inlined).

reporters: [['html', { singleFile: true }]]

Blob & Merge (CI/sharding)

Blobs default to .vitest/blob/. Label environments with VITEST_BLOB_LABEL or the reporter label option:

vitest run --reporter=blob --outputFile=reports/blob-1.json
vitest --merge-reports=reports --reporter=junit --reporter=default

Blob reports don't include file attachments — merge attachmentsDir (.vitest/attachments/) separately. --reporter=blob/--merge-reports don't work in watch mode.

Key Points

  • Configuring reporters replaces defaults — spread configDefaults.reporters to keep them
  • The minimal/agent reporter is auto-selected for AI agents and minimizes token usage
  • Use tree for the nested per-test view (old v3 verbose)
  • v5 artifacts (blob, attachments, HTML) live under .vitest/
<!-- Source references: - https://vitest.dev/guide/reporters - https://vitest.dev/config/reporters -->

Source: SKILL.md on GitHub

No alerts3d5 checks · Risk SAFE
  • Gen Agent Trust Hub3d

    The skill provides comprehensive documentation and reference material for the Vitest testing framework. It covers configuration, CLI usage, mocking, coverage, and advanced features like type testing and benchmarking. No security issues were detected; the instructions follow standard development and testing practices.

  • Socket3d

    No alerts

  • Snyk3d

    Risk: LOW · No issues

  • Runlayer7mo

    1/18 files flagged

  • ZeroLeaks5mo

    Score: 93/100 · 2 sections analyzed

Signed by skilld at d02c484. This ties the file your Agent reads to that commit on GitHub. It does not review the instructions.

Last checked against GitHub 2 days ago.

Activeupdated 4 days ago
Other metadata
metadata
{
  "author": "Anthony Fu",
  "version": "2026.9.25",
  "source": "Generated from https://github.com/vitest-dev/vitest, scripts located at https://github.com/antfu/skills"
}

README badge

README badge for antfu/skills/vitest

Vitest is a Jest-compatible unit testing framework powered by Vite, with native ESM, TypeScript, and JSX support. Use it for writing tests with smart watch mode, mocking, fixtures, coverage reporting, and snapshot testing in projects already using Vite.

Generated from the current SKILL.md.

Is Vitest a drop-in replacement for Jest?
Mostly. Vitest provides a Jest-compatible API and can run most Jest test suites without modification, but it uses Vite's transformation pipeline instead of Jest's, so some edge cases may differ.
Does Vitest require configuration?
No. It natively supports ESM, TypeScript, and JSX out of the box and shares Vite's config, transformers, and resolvers, so many projects need minimal or no additional setup.
What coverage providers does Vitest support?
Vitest includes built-in coverage via V8 or Istanbul providers.
Can I run tests in parallel?
Yes. Vitest uses multi-threaded workers for parallel test execution and supports sharding across multiple processes.
What test environments are available?
Vitest supports node, jsdom, happy-dom, and custom environments.

Generated from the current SKILL.md. These answers refresh after source changes.