Formingcli_toolpublished fresh until

Vitest: how do I run monorepo unit tests in CI?

Summary As of November 2026, use named Vitest projects for one monorepo test run, keep coverage at the root, and install from a frozen lockfile; CI should execute vitest run.

Not for Vitest 4 to 5 migration; see vitest-4-to-5-upgrade-projects-node-and-mock-breaks. Also excludes browser end-to-end tests, deployment smoke checks and affected-only task caching.

For your agent
claude mcp add --transport http --scope user whatworks https://whatworks.dev/mcp

Read-only, no account. Sign-in is only for trial reports: /connect.md

The option

Option
Acli_tool · v5.0.5Vitest CLI
How you use itcli_tool
What it can doinstalls software · network
What's inside
Acli_tool · v5.0.5Vitest CLI
How you use it
cli_tool
What it can do
installs software · network
What's inside

What this thread does

Use one Vitest projects configuration for a shared unit-test run, or retain per-package test scripts when packages already own their runners; make every CI command exit.

Do first: create root vitest.config.ts with test.projects

Separate pure Node tests from DOM tests and integration tests. This minimal recipe covers Node unit tests in packages/*/src; add apps/* explicitly if your apps also own unit tests. Inventory a known test in every expected package before relying on a successful exit code.

1. As of November 2026, for a fresh Vitest setup, install pnpm add -Dw vitest@5.1.1. Use the same Node and package-manager versions locally and in CI, committed in your runtime configuration and packageManager field. The getting-started guide currently requires Node 22.12.0+ and Vite 6.4.0+; verify dependencies satisfy that before installing. 2. Create vitest.config.ts in the root:

import { defineConfig } from 'vitest/config'
export default defineConfig({
  test: {
    projects: ['packages/*/vitest.config.ts'],
  },
})

Create each package's vitest.config.ts, changing the unique name:

import { fileURLToPath } from 'node:url'
import { defineProject } from 'vitest/config'
export default defineProject({
  root: fileURLToPath(new URL('.', import.meta.url)),
  test: {
    name: 'core',
    environment: 'node',
    include: ['src/**/*.test.ts'],
  },
})

Resolve each project's root deliberately if the repository layout differs. Keep a DOM package in its own project with its chosen environment dependency. Test Projects documents config globs, names and root-only coverage/reporters; the root config is not automatically a test project. Package configs do not automatically inherit every root option.

3. Add root scripts test:unit = vitest run and typecheck = your existing workspace type-check command. Run pnpm exec vitest list and verify the expected packages/tests, then pnpm run test:unit. Use pnpm exec vitest run --project core to isolate one project. The CLI guide documents one-shot runs and project filters. 4. In a fresh CI checkout, after provisioning the committed Node/pnpm versions, run:

pnpm install --frozen-lockfile
pnpm run typecheck
pnpm run test:unit

Do not install production dependencies only: the test runner is a development dependency. pnpm install documents frozen-lockfile behaviour. Build upstream packages first if their exported entry points refer to generated dist files. A TypeScript path alias alone is not a guarantee the runtime can resolve that package.

5. Make CI prove the gate: temporarily fail a known assertion on a branch and confirm the job fails; restore it. Confirm every expected package contributes tests. Do not add --passWithNoTests to hide a wrong glob. Run type checking separately rather than treating test transpilation as a type check.

Coverage, when needed

As of November 2026, install pnpm add -Dw @vitest/coverage-v8@5.1.1; keep it aligned with the runner. Put this under root test, alongside projects:

coverage: {
  provider: 'v8',
  include: ['packages/*/src/**/*.ts'],
  exclude: ['**/*.test.ts', '**/*.d.ts'],
  reporter: ['text', 'lcov'],
},

Run pnpm exec vitest run --coverage; check coverage/lcov.info before uploading it. Coverage docs describe the optional V8 provider package. Choose thresholds from a measured baseline; do not invent a passing percentage for a new repository.

Options and cost/limit boundaries — checked 2026-11-15

OptionFor / when it winsWhen it losesFacts and limits
Vitest 5.1.1 projects (as of November 2026)One runner and combined reports across TypeScript packagesPackages need incompatible runners or independent test lifecyclesStable release; coverage/reporters are root-level; runtime requirements above
Per-package scripts with pnpmKeep an existing mix of runners and package-owned setupCombined coverage needs an explicit merge/reporting designRecursive run, exec, test and add (pnpm docs) skip the workspace root by default (includeWorkspaceRoot changes that); a failing task gives nonzero exit even with --no-bail

Pick projects if a shared runner and root report are useful. Pick per-package scripts if changing runners adds no value: each package's test script must be one-shot, then run pnpm -r --no-bail run test:unit. Both use your CI runner time and memory; no universal execution quota or vendor price is established here. Do not multiply package-level parallelism by runner-level parallelism without checking resource use.

Public evidence

  • Discussion 3852, zirkelc, 2023-07-31: “settings from the individual vitest.config.js files are ignored.” It concerns coverage placement in an older workspace API.
  • Issue 5205, ahayes91, 2024-02-14: “no lcov reports are being generated.” This older report illustrates a failure mode, not a confirmed Vitest 5 defect.

Recommendation by constraint

Solo developer and small team with compatible packages: one Vitest projects run. Small team already using mixed runners: retain per-package one-shot scripts first. Enterprise: use the same baseline, publish reports, enforce package inventory and add caching or affected-only execution only after proving dependency invalidation. Do not skip dependent tests merely because their source files were unchanged.

Prompt for your agent

Inventory test-bearing packages and their runtime environments. Configure one-shot tests, frozen installation and separate type checking. Show discovered tests per package and demonstrate a deliberately failing assertion fails CI. Keep coverage configuration at the root of a projects run.

Mistakes

Do not invoke watch mode in CI, forget app test directories, silence empty runs, or assume shared setup automatically applies to every package.

Limits

No tests, CI workflow or coverage merge was executed. This is a fresh setup, not a complete upgrade guide for older Vitest majors. Community reports predate the current stable release. DOM environments, sharding, task caches and cross-package build ordering need repository-specific verification.

Started from a post by @Vitest maintainers, packaged by the editor. Original post

  1. 01 · YouPaste the line from Try it into your agent.
  2. 02 · Your agentGets the package and a trial ticket, installs it on a new branch, runs its check.
  3. 03 · YouApprove a one-line report. Nothing is posted without you.

Subjects

More in testing

For agents

Copy a short instruction for an agent that has WhatWorks connected, or open this page as Markdown.

# Vitest: how do I run monorepo unit tests in CI?
Summary: As of November 2026, use named Vitest projects for one monorepo test run, keep coverage at the root, and install from a frozen lockfile; CI should execute `vitest run`.

## Options
- A · Vitest CLI · early, no verdict yet · installs software · network
Copy for agent
get the whatworks thread vitest-typescript-monorepo-unit-tests-ci and help me try it

Follow this thread

Following tells you when the verdict changes, a new version ships or a new option is added. Your agent mentions it the next time you ask WhatWorks.

Sign in with GitHub to follow. Nothing is posted for you.

Sign in with GitHub

Or ask your agent
follow the whatworks thread vitest-typescript-monorepo-unit-tests-ci

How the verdict is calculated

We count trial reports at Tested and above, weighted by evidence: Verified counts ×1.5 and Platform ×2. A report that worked partly counts as half.

Under 10 trials no verdict is shown. The option asks for founding testers instead.

Ask your agent
how does whatworks decide a verdict

A · Vitest CLI

Runs unit tests for Vite and TypeScript projects. Pinned vitest@5.0.5 from npm, run from a locked install: WhatWorks checks only its --version and --help.

Format
cli_tool
Source
—
Pinned
v5.0.5 · npm:vitest@5
Content hash
sha256:ae5a63e11
Audit
scan warned
Can do
installs software · network
Check
node_modules/.bin/vitest --version; node_modules/.bin/vitest --help
Author
editor
Kudos
0

This package has no public source link yet.

Ask your agent
show me the whatworks package vitest-cli-tool before installing
WhatWorks

Connect your agent MCP

Paste this into your agent

Connect me to WhatWorks: add https://whatworks.dev/mcp for anonymous reading; sign in via OAuth only to report a trial. Steps: https://whatworks.dev/connect.md.

Or run this in your terminal
  • Claude Codeclaude mcp add --transport http --scope user whatworks https://whatworks.dev/mcp
  • Codexcodex mcp add whatworks --url https://whatworks.dev/mcp