Skip to main content

Vitest Setup

Register shared Vitest hooks so test isolation behavior stays synchronized across projects.

Summary

  • Suppresses console calls and writes to process.stdout and process.stderr during each test.
  • Clears process.exitCode before each test and restores every Vitest mock afterward.
  • Receives the consumer's active Vitest functions so hooks bind to the runtime driving the suite.

Why Use This Battery?

  1. Centralizes the shared setup policy so behavior changes propagate without copying hook bodies between projects.
  2. Uses the suite's active Vitest runtime so linked packages and monorepos don't register hooks against a different instance.
  3. Leaves the local setup file available for project-specific hooks without forking the shared baseline.

Usage

Settings

SettingTypeDefaultDescription
afterEachVitest afterEachRequiredRegisters shared cleanup after every test.
beforeEachVitest beforeEachRequiredRegisters shared isolation before every test.
viVitest viRequiredCreates and restores spies in the active runtime.

Output Examples