Adetayo Akinsanya unkletayo.dev

Vitest Workspaces: Multi-Project Monorepo Test Execution Isolation

Configuring vitest.workspace.ts to manage frontend, backend, and shared packages in monorepos.

Adetayo Akinsanya (unkletayo) 2026-10-23

Part 13 in Series — Catch up on the previous article: Coverage Engines: Bytecode Coverage via V8 AST Counters vs AST Instrumentation with Istanbul (Part 12) before diving into this post.

In large monorepos (Turborepo, Nx, pnpm workspaces), different packages often require distinct test environments. For example, @repo/ui needs happy-dom, while @repo/backend needs node with a real database instance.

Vitest Workspaces allows configuring multiple projects inside a single runner process using a vitest.workspace.ts file.

// vitest.workspace.ts
import { defineWorkspace } from 'vitest/config';

export default defineWorkspace([
  'packages/*',
  {
    test: {
      name: 'unit-backend',
      root: './services/api',
      environment: 'node',
      include: ['src/**/*.spec.ts'],
    },
  },
  {
    test: {
      name: 'frontend-components',
      root: './apps/web',
      environment: 'happy-dom',
      include: ['src/**/*.test.tsx'],
    },
  },
]);

Running vitest from the monorepo root automatically executes all projects in parallel while isolating their environment configs.

Up Next in Series →

Part 14: Capstone Project: Building a Custom Vitest Plugin & Test Runner Reporter

Continue to Part 14 →