From harness-claude
Configures Vitest for workspaces, node/jsdom environments, coverage reports, TypeScript paths, setup files, and monorepo testing in new or existing Vite projects.
npx claudepluginhub intense-visions/harness-engineering --plugin harness-claudeThis skill uses the workspace's default tool permissions.
> Configure Vitest with workspaces, environments, coverage, and TypeScript integration
Configures Vitest for Vite projects with workspace setups, test environments (node/jsdom), coverage (v8/istanbul), performance pools, reporters, and mock options. Use for JS/TS testing setups.
Configures vitest.config.ts and writes unit/integration tests for Vite projects using describe/it, vi.fn/vi.mock, coverage thresholds, and parallel execution.
Guides Vitest testing for TypeScript/JavaScript projects: installation, config, running tests with watch/UI/coverage, assertions, and mocking.
Share bugs, ideas, or general feedback.
Configure Vitest with workspaces, environments, coverage, and TypeScript integration
// 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,
},
});
// 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'],
},
});
// At the top of a test file:
// @vitest-environment jsdom
// Or in config, per glob pattern:
test: {
environmentMatchGlobs: [
['src/components/**', 'jsdom'],
['src/services/**', 'node'],
],
},
// 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',
},
},
];
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,
},
},
},
import { defineConfig } from 'vitest/config';
import tsconfigPaths from 'vite-tsconfig-paths';
export default defineConfig({
plugins: [tsconfigPaths()],
test: {
// ...
},
});
// test/setup.ts
import '@testing-library/jest-dom';
import { cleanup } from '@testing-library/react';
import { afterEach } from 'vitest';
afterEach(() => {
cleanup();
});
{
"compilerOptions": {
"types": ["vitest/globals"]
}
}
test: {
pool: 'forks', // 'threads' | 'forks' | 'vmThreads'
poolOptions: {
forks: { maxForks: 4 },
},
fileParallelism: true, // Run test files in parallel
},
test: {
snapshotFormat: {
printBasicPrototype: false,
},
resolveSnapshotPath: (testPath, snapExtension) =>
testPath.replace('src/', '__snapshots__/') + snapExtension,
},
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 — Node.js runtime. For services, utilities, API testsjsdom — Browser-like DOM via jsdom. For React/Svelte/Vue component testshappy-dom — Faster alternative to jsdom with more Web API supportedge-runtime — Cloudflare Workers/Vercel Edge runtime simulationglobals: true makes describe, it, expect, vi available without imports. Cleaner test files but requires TypeScript types configuration.
Pool options:
threads (default) — worker threads, shared memory, fastest for CPU-bound testsforks — child processes, full isolation, best for tests with global state leaksvmThreads — VM contexts, lighter than forks, good middle groundPerformance tips:
pool: 'threads' for fastest executionfileParallelism: true to run files in parallel--reporter=dot in CI for minimal output--changed flag to run only tests affected by changed files