---
name: "vitest-in-source-unit-testing"
description: "Write unit tests directly alongside implementation code with instant Vite-powered HMR."
metadata:
  author: "Vitest"
  version: "1.0.0"
  runtime_compatibility:
    - "codex"
    - "claude-code"
    - "cursor"
    - "windsurf"
triggers:
  - "setup in-source testing vitest"
  - "run vitest watch"
  - "benchmark with vitest"
permissions:
  fs_read: true
  fs_write: "workspace"
  shell_exec: false
  net_access: false
---

# Vitest In-Source Unit Testing & Instant ESM Execution

Configures Vitest: configuring in-source testing (if (import.meta.vitest)), vitest.config.ts, benchmarking (bench), snapshot testing, code coverage with v8/istanbul, and running tests at lightning speed.

## When to Invoke
Invoke this skill whenever you need to:
- setup in-source testing vitest
- run vitest watch
- benchmark with vitest

## Execution SOP & Rules
1. Enable in-source testing in vitest.config.ts: test: { includeSource: ['src/**/*.{js,ts}'] }.
2. Write test at end of source file: if (import.meta.vitest) { const { it, expect } = import.meta.vitest; it('adds numbers', () => { expect(add(1, 2)).toBe(3); }); }.
3. Add interface typing: /// <reference types='vitest/importMeta' /> in vite-env.d.ts.
4. Run tests: npx vitest run and check coverage: npx vitest run --coverage.

## Verification Checklist
- Run local linting, syntax validation, and type-checks before reporting completion.
- Ensure all created or modified files adhere to workspace boundaries and avoid uncommitted secrets.
- Verify tests or build commands exit cleanly with return code 0.
