Skip to content

perf: split vitest into unit and integration projects#286

Open
southpolesteve wants to merge 1 commit intomainfrom
improve/vitest-workspace-split
Open

perf: split vitest into unit and integration projects#286
southpolesteve wants to merge 1 commit intomainfrom
improve/vitest-workspace-split

Conversation

@southpolesteve
Copy link
Collaborator

Summary

  • Splits the vitest config into two projects: unit (28 files) and integration (24 files)
  • Adds test:unit and test:integration npm scripts for targeted runs
  • No changes to CI (full suite still runs via pnpm test)

Motivation

The full vitest suite takes ~2 minutes because fileParallelism: false forces all 52 test files to run serially. This is necessary for integration tests (they race on Vite's deps optimizer cache), but the 28 unit test files don't start dev servers and don't need serial execution.

With vitest 3.x, fileParallelism is a global-only setting (it cannot be set per-project), so both projects still run serially when you invoke pnpm test. The practical win is that developers and agents can now run subsets:

Command What runs Time
pnpm test All 52 files (serial) ~100s
pnpm test:unit 28 unit files only (serial) ~14s
pnpm test:integration 24 integration files only (serial) ~97s
pnpm test -- tests/routing.test.ts Single file ~3s

When multiple agents are working on the repo simultaneously, pnpm test:unit provides a fast feedback loop without the overhead of spinning up Vite dev servers.

Integration test classification

Tests are classified as integration if they call startFixtureServer(), import createServer from Vite, or spawn dev server subprocesses. The integrationTests array in vitest.config.ts documents this and includes guidance for future test authors.

Future improvement

When vitest adds per-project fileParallelism support (tracked in vitest 4.x), unit tests can run in parallel while integration tests remain serial. This would further reduce the full suite runtime.

/bigbonk review this

Test files are now categorized into two vitest projects:

- unit (28 files): Pure logic tests that don't start Vite dev servers.
  Run with: pnpm test:unit (~14s)
- integration (24 files): Tests that spin up Vite dev servers against
  shared fixture directories. Run with: pnpm test:integration (~97s)

fileParallelism remains globally disabled (vitest 3.x limitation, it
cannot be set per-project). The practical win is that agents and
developers can now run 'pnpm test:unit' or 'vitest run --project unit'
to skip integration tests entirely, getting feedback in seconds instead
of minutes.

Full suite (pnpm test) still runs everything, and CI is unchanged.
@pkg-pr-new
Copy link

pkg-pr-new bot commented Mar 6, 2026

Open in StackBlitz

npm i https://pkg.pr.new/vinext@286

commit: 402905e

@github-actions
Copy link

github-actions bot commented Mar 6, 2026

Example Preview Production Original
app-router-cloudflare preview production
pages-router-cloudflare preview production
app-router-playground preview production original
realworld-api-rest preview production
nextra-docs-template preview production
benchmarks preview production
hackernews preview production original

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant