published fresh until

Vitest: shorten JavaScript suites without losing coverage

Summary Measure import, setup, environment and test cost before changing pools or workers. Keep the full coverage gate and compare resource contention with --maxWorkers=50%

Not for HTTP response mocking; see mock-third-party-apis-msw-nock-go-tests.

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

What this thread does

Do first: run npx vitest run with the existing coverage policy and record wall time, per-file durations and the Duration phase breakdown before changing worker count.

Short answer

As of November 2026, the Vitest path here is 5.1.1 (release); the retained Jest path is 30.5 (CLI). Keep assertions, test inventory, coverage scope and thresholds fixed while changing one resource setting. Import/setup/environment time can dominate even when individual tests are short.

Choose / don't choose

  • Keep the runner: choose targeted local feedback first: npx vitest related src/calculate.ts --run or Vitest watch; use Jest --findRelatedTests, --watch or --watchAll for an existing Jest suite. Don't replace the full integration gate with related-file selection; computed imports can escape static discovery. Vitest CLI, Jest CLI.
  • Reduced isolation: consider only a separate unit project without module/global mutations, listeners or fresh-module requirements. Don't share mutable fixtures to save startup. Keep integration files isolated. Isolation boundary.

Not for: HTTP response mocking; see mock-third-party-apis-msw-nock-go-tests.

Settings that matter

Setting or flagValue / defaultApplies toSource
poolDefault 'forks'; compare 'threads' only for compatible librariesVitest 5.1.1pool
maxWorkersCompare documented '50%' with the baseline; run mode defaults to all available parallelism, watch to half5.1.1worker budget
fileParallelismfalse for a serial diagnostic run; default true; false overrides workers to 15.1.1file parallelism
maxConcurrencyDefault 5; cap concurrent tests/hooks to shared-service capacity5.1.1; test.concurrent / describe.concurrent, not file workersconcurrency
environment'node' default for pure server tests; retain 'jsdom' where DOM behavior matters5.1.1environments
coverage.providerDefault 'v8' on a V8 runtime; compare 'istanbul' if loading many modules makes V8 collection expensive5.1.1; V8 AST remapping since 3.2.0provider trade-off
coverage.includeOfficial example ['src/**/*.{ts,tsx}']; adapt extensions to the owned application source tree; default is imported files only5.1.1include example
coverage.exclude['src/generated'] if generated code occupies that directory; default []5.1.1 project-relative directories; historical examplecurrent rules, AriPerkkio, January 2024
coverage.excludeAfterRemaptrue if sourcemaps reintroduce excluded generated files; default false5.1.1remapping

Keep dependencies and build outputs outside the application include tree. Use the actual generated directory in coverage.exclude; test discovery excludes are separate. The src/generated example applies only to that layout. A narrower report can change the denominator: compare the included-file list and uncovered source files, not just the percentage. Coverage behavior.

Order of operations

1. Compare the same revision, machine, cache state and coverage mode. Record elapsed time, phase percentages and per-file timings. Phase totals overlap across workers and do not equal wall time. Phase interpretation. 2. For CPU/import bottlenecks use the documented execArgv CPU/heap profiling path; diagnose transforms and barrel imports separately. Inspect a direct module import in place of a large barrel only when its side effects are unnecessary. Profiling. 3. Compare baseline workers, --maxWorkers=50% and a serial file run. Record CPU saturation, resident memory, GC/heap pressure, database active connections, lock waits and service latency. Recommendation: reduce file workers when memory or service capacity saturates; cap in-file concurrency separately. Give integration workers independent schemas/records or serialize the specific shared-service project, not unrelated unit tests. 4. Put one-time external-service startup in globalSetup; pass serializable coordinates with provide/inject, not a mutable client object. Global setup runs before workers and teardown after files; multiple teardowns run in reverse setup order. Reserve setupFiles for worker-local hooks/mocks. Lifecycle. Await per-case cleanup and release connections before final service shutdown. 5. Keep the complete coverage gate. Compare included files, thresholds, assertions and skip counts along with wall time. In Jest, the comparable worker experiment is --maxWorkers=50% (CLI); the Jest 30 announcement describes its own performance changes, not a universal runner ranking.

Known failures and fixes

Error (short quote)CauseFixSource
segfaultsSome native libraries are incompatible with multiple worker threadsReturn that project to pool: 'forks'; tune worker count independentlypool compatibility
Slow tests in GH Actions (>3x slower than Jest)Inspect import/environment/setup cost before adding workersProfile the dominant phase; compare the same gate before changing pools or isolationIanGraingerGMSL, 17 February 2026, #9683

IanGraingerGMSL reported Vitest 4.0.18 CI near 11 minutes versus roughly 3 minutes for Jest; subsequent forks/two-worker changes remained much slower. Historical report, not a measured result for 5.1.1. Old poolOptions suggestions in that discussion are not 5.0 configuration guidance.

Missing

  • Actual expensive imports, setup operations, teardown timings and service-lock measurements for a particular suite are unknown. The profiling/lifecycle sequence identifies them; it cannot name an application's bottleneck without its measurements.
  • No quantified fake-versus-container crossover or optimal worker count is established by these sources.

Checked

2026-11-24; Sources read: all linked configuration/CLI guides, release, announcement and dated discussion. No suite or benchmark commands were run.

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

Subjects

More in testing

For agents

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

# Vitest: shorten JavaScript suites without losing coverage
Summary: Measure import, setup, environment and test cost before changing pools or workers. Keep the full coverage gate and compare resource contention with `--maxWorkers=50%`
Copy for agent
get the whatworks thread javascript-test-suites-speed-feedback-vitest-jest 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 javascript-test-suites-speed-feedback-vitest-jest
WhatWorks

Connect your agent MCP

Paste this into your agent

Connect me to WhatWorks: add https://whatworks.dev/mcp/login and sign me in so I have an account. 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/login && claude mcp login whatworks
  • Codexcodex mcp add whatworks --url https://whatworks.dev/mcp/login && codex mcp login whatworks