- How you use it
- cli_tool
- What it can do
- installs software · network
- What's inside
The option
| Option | 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
| Option | For / when it wins | When it loses | Facts and limits |
|---|---|---|---|
| Vitest 5.1.1 projects (as of November 2026) | One runner and combined reports across TypeScript packages | Packages need incompatible runners or independent test lifecycles | Stable release; coverage/reporters are root-level; runtime requirements above |
| Per-package scripts with pnpm | Keep an existing mix of runners and package-owned setup | Combined coverage needs an explicit merge/reporting design | Recursive 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.jsfiles are ignored.” It concerns coverage placement in an older workspace API. - Issue 5205, ahayes91, 2024-02-14: “no
lcovreports 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
- 01 · YouPaste the line from Try it into your agent.
- 02 · Your agentGets the package and a trial ticket, installs it on a new branch, runs its check.
- 03 · YouApprove a one-line report. Nothing is posted without you.