install
source · Clone the upstream repo
git clone https://github.com/Intense-Visions/harness-engineering
Claude Code · Install into ~/.claude/skills/
T=$(mktemp -d) && git clone --depth=1 https://github.com/Intense-Visions/harness-engineering "$T" && mkdir -p ~/.claude/skills && cp -r "$T/agents/skills/claude-code/test-vitest-config" ~/.claude/skills/intense-visions-harness-engineering-test-vitest-config && rm -rf "$T"
manifest:
agents/skills/claude-code/test-vitest-config/SKILL.mdsource content
Test Vitest Config
Configure Vitest with workspaces, environments, coverage, and TypeScript integration
When to Use
- Setting up Vitest in a new or existing project
- Configuring test environments (node, jsdom, happy-dom)
- Setting up workspaces for monorepo testing
- Integrating coverage, globals, and TypeScript paths
Instructions
- Basic configuration:
// vitest.config.ts import { defineConfig } from 'vitest/config'; export default defineConfig({ test: { globals: true, environment: 'node', include: ['src/**/*.test.ts'], exclude: ['node_modules', 'dist', 'e2e'], setupFiles: ['./test/setup.ts'], testTimeout: 10_000, }, });
- Share config with Vite (if already using Vite):
// vite.config.ts import { defineConfig } from 'vite'; import react from '@vitejs/plugin-react'; export default defineConfig({ plugins: [react()], test: { globals: true, environment: 'jsdom', setupFiles: ['./test/setup.ts'], }, });
- Environment per file using comments or config:
// At the top of a test file: // @vitest-environment jsdom // Or in config, per glob pattern: test: { environmentMatchGlobs: [ ['src/components/**', 'jsdom'], ['src/services/**', 'node'], ], },
- Workspace configuration for monorepos:
// vitest.workspace.ts export default [ 'packages/*/vitest.config.ts', // Or inline: { test: { name: 'unit', include: ['src/**/*.test.ts'], environment: 'node', }, }, { test: { name: 'components', include: ['src/**/*.test.tsx'], environment: 'jsdom', }, }, ];
- Coverage configuration:
test: { coverage: { provider: 'v8', reporter: ['text', 'html', 'lcov'], include: ['src/**/*.ts'], exclude: ['src/**/*.test.ts', 'src/**/*.d.ts'], thresholds: { branches: 80, functions: 80, lines: 80, }, }, },
- Path aliases — sync with tsconfig:
import { defineConfig } from 'vitest/config'; import tsconfigPaths from 'vite-tsconfig-paths'; export default defineConfig({ plugins: [tsconfigPaths()], test: { // ... }, });
- Setup files for global test configuration:
// test/setup.ts import '@testing-library/jest-dom'; import { cleanup } from '@testing-library/react'; import { afterEach } from 'vitest'; afterEach(() => { cleanup(); });
- Type support — add vitest types to tsconfig:
{ "compilerOptions": { "types": ["vitest/globals"] } }
- Parallel execution and pooling:
test: { pool: 'forks', // 'threads' | 'forks' | 'vmThreads' poolOptions: { forks: { maxForks: 4 }, }, fileParallelism: true, // Run test files in parallel },
- Snapshot configuration:
test: { snapshotFormat: { printBasicPrototype: false, }, resolveSnapshotPath: (testPath, snapExtension) => testPath.replace('src/', '__snapshots__/') + snapExtension, },
Details
Vitest is a Vite-native test framework that shares Vite's configuration, plugins, and transform pipeline. This means your tests use the same module resolution, path aliases, and transforms as your application code.
Environment options:
— Node.js runtime. For services, utilities, API testsnode
— Browser-like DOM via jsdom. For React/Svelte/Vue component testsjsdom
— Faster alternative to jsdom with more Web API supporthappy-dom
— Cloudflare Workers/Vercel Edge runtime simulationedge-runtime
makes globals: true
describe, it, expect, vi available without imports. Cleaner test files but requires TypeScript types configuration.
Pool options:
(default) — worker threads, shared memory, fastest for CPU-bound teststhreads
— child processes, full isolation, best for tests with global state leaksforks
— VM contexts, lighter than forks, good middle groundvmThreads
Performance tips:
- Use
for fastest executionpool: 'threads' - Set
to run files in parallelfileParallelism: true - Use
in CI for minimal output--reporter=dot - Exclude unnecessary files from test discovery
- Use
flag to run only tests affected by changed files--changed
Source
Process
- Read the instructions and examples in this document.
- Apply the patterns to your implementation, adapting to your specific context.
- Verify your implementation against the details and edge cases listed above.
Harness Integration
- Type: knowledge — this skill is a reference document, not a procedural workflow.
- No tools or state — consumed as context by other skills and agents.
Success Criteria
- The patterns described in this document are applied correctly in the implementation.
- Edge cases and anti-patterns listed in this document are avoided.