Green coverage bars inside a reporting dashboard

A test suite tells you whether the code you tested works. Coverage tells you which code you did not test, and reporters decide how both facts reach people and machines. Vitest supports two coverage providers, a set of built-in reporters for terminals, dashboards and CI systems, and in version 5 a single output folder that simplifies artefact collection. This guide explains how to choose and configure each piece.

Choosing a coverage provider

Vitest does not bundle coverage; you install one of two providers. @vitest/coverage-v8 uses the V8 engine's built-in coverage data, needs no instrumentation step and is the default choice for most projects. @vitest/coverage-istanbul instruments the code with Istanbul, which can be more precise for some branch cases and is familiar to teams coming from Jest. In Vitest 5 the Istanbul tooling moved into a scoped package and both providers send less data between workers, while the v8 provider merges reports with bounded memory on large suites. Install the provider that matches your installed vitest major.

Enabling coverage

Run vitest run --coverage, or set coverage.enabled to true in the config for a dedicated script. The provider option selects v8 or istanbul. Coverage slows runs because every file is tracked, so most teams keep it off in watch mode and on in CI or in a separate test:coverage script.

Deciding what to measure

By default coverage includes files that were imported during the run. Set coverage.include to your source folders and coverage.exclude to tests, type declarations, generated code and configuration so the percentages describe the code you care about. Vitest can also report on files that were never imported when you point include at the full source tree, which exposes modules with no tests at all.

Thresholds

coverage.thresholds sets minimum percentages for lines, functions, branches and statements. When a run falls below a threshold the process exits with a failure, which makes CI enforce the standard. Vitest 5 lets thresholds.perFile take an object so each metric can be enforced per file, and thresholds.autoUpdate can raise the stored thresholds when coverage improves, receiving the previous value so you can decide how aggressively to ratchet. Start with realistic numbers from a baseline run rather than aspirational targets.

Coverage reporters

coverage.reporter accepts a list. text prints a table in the terminal, html produces a browsable report, lcov writes the format consumed by most coverage services, json and json-summary feed custom tooling, and clover and cobertura serve older CI integrations. Combine text for humans with lcov or cobertura for machines. In Vitest 5 the coverage.autoAttachSubprocess option lets the v8 provider track spawned child processes and worker threads, useful for CLI tools and servers that fork.

Test reporters

Separate from coverage, test reporters format the pass/fail output. default is the interactive terminal view, verbose lists every test, dots is compact, tap and tap-flat emit the Test Anything Protocol, json writes a machine-readable summary, junit produces XML that CI dashboards render, and html generates a static version of the Vitest UI. Reporters are set with the --reporter flag or the reporters option and can be combined, for example default in the terminal plus junit for the pipeline. Vitest 5 adds jest-junit-compatible naming options to the junit reporter and a filterMeta field to the json reporter, and third-party reporters can use vitest.createReport to write their own output.

The .vitest output folder

Vitest 5 writes html, json and junit reports, attachments, failure screenshots and browser traces to a .vitest directory at the project root. Add it to .gitignore, point your CI artefact step at it, and use the html reporter's singleFile option when you want one self-contained file to upload. The HTML coverage report still goes to the coverage directory unless you change reportsDirectory.

Sharded and merged runs

Large suites can be split across machines with --shard and then combined with --merge-reports. Vitest 5 extends merging to non-sharded runs across multiple environments, so a suite that runs once in jsdom and once in a browser can produce one combined report. Coverage data from shards is merged the same way when the blob reporter is used.

Reading the numbers honestly

High line coverage does not prove correctness; it proves execution. Branch coverage is the more useful metric for logic-heavy code, and a drop in coverage on a pull request is more informative than the absolute figure. Use thresholds to prevent regressions and the html report to find untested paths, but review the tests themselves for meaningful assertions.

Coverage in watch mode and the UI

Coverage can run in watch mode, and the Vitest UI embeds the html report in a dedicated tab when it is enabled, which is a convenient way to watch a percentage climb while writing tests for a single module. Because instrumentation adds overhead to every rerun, most developers enable it only for that focused session and keep the default watch command lean.

Excluding generated and vendored code

Generated clients, migration files, storybook stories and type declaration files inflate the denominator without representing testable logic. List them in coverage.exclude alongside the test files themselves. Vitest ships sensible defaults for common patterns, and your additions extend rather than replace them unless you override the whole list.

Coverage services

Hosted services consume the lcov or cobertura output and annotate pull requests with changed-line coverage. Upload the file from the coverage directory in a CI step after vitest run completes. If your pipeline runs shards, merge first so the service receives one complete report rather than several partial ones.

During review, inspect uncovered branches in affected files first. A targeted assertion about an error path often gives more confidence than another broad snapshot.

Conclusion

Vitest coverage starts with installing the v8 or Istanbul provider and enabling it for a dedicated run. Include and exclude patterns define the code that counts, thresholds turn the numbers into a CI gate, and reporters such as text, html and lcov deliver results to people and services. Test reporters handle pass/fail output in parallel, from the default terminal view to junit for dashboards, and Vitest 5 gathers everything under one .vitest folder with merge support across shards and environments. Configured this way, coverage becomes a reliable signal rather than a vanity metric.