src/orchestrator/plugins/vitest/SKILL.md
Vitest unit and integration testing patterns, commands, mocking (vi.mock), and coverage. Use when writing .test.ts files, configuring the test runner, or adding coverage thresholds.
npx skillsauth add monkilabs/opencastle vitest-testingInstall this skill globally with one command. Works with Claude Code, Cursor, and Windsurf.
3 of 9 scanners reported clean
Some scanners were skipped, did not run, or reported a non-clean status. Review each row below.
For project-specific test configuration, see testing-config.md.
npx vitest # Run in watch mode
npx vitest run # Run once (CI)
npx vitest run --coverage # Run with coverage report
npx vitest run src/utils/ # Run specific directory
npx vitest run auth.test.ts # Run specific file
npx vitest run -t "should validate" # Filter by test name
npx vitest --ui # Open Vitest UI
npx vitest --reporter=json # JSON output for CI
npx vitest typecheck # Run type-checking tests
src/
├── utils/
│ ├── format.ts
│ └── format.test.ts # Co-located test
├── components/
│ ├── Button.tsx
│ └── Button.test.tsx # Component test
└── __tests__/ # Integration tests
└── auth-flow.test.ts
import { describe, it, expect, vi, beforeEach, afterEach } from 'vitest';
import { formatPrice } from './format';
describe('formatPrice', () => {
it('should format USD prices', () => {
expect(formatPrice(9.99, 'USD')).toBe('$9.99');
});
it('should handle zero', () => {
expect(formatPrice(0, 'USD')).toBe('$0.00');
});
it('should throw for negative values', () => {
expect(() => formatPrice(-1, 'USD')).toThrow('Price cannot be negative');
});
});
import { vi, describe, it, expect } from 'vitest';
// Mock entire module
vi.mock('./database', () => ({
getUser: vi.fn().mockResolvedValue({ id: '1', name: 'Alice' }),
}));
// Mock specific export
vi.mock('./config', async (importOriginal) => {
const original = await importOriginal<typeof import('./config')>();
return { ...original, API_URL: 'http://test-api.example.com' };
});
import { vi, describe, it, expect } from 'vitest';
describe('notifications', () => {
it('should call the API', async () => {
const fetchSpy = vi.spyOn(globalThis, 'fetch').mockResolvedValue(
new Response(JSON.stringify({ ok: true }))
);
await sendNotification('Hello');
expect(fetchSpy).toHaveBeenCalledWith('/api/notify', expect.objectContaining({
method: 'POST',
}));
fetchSpy.mockRestore();
});
});
import { vi, describe, it, expect, beforeEach, afterEach } from 'vitest';
describe('debounce', () => {
beforeEach(() => vi.useFakeTimers());
afterEach(() => vi.useRealTimers());
it('should debounce calls', () => {
const fn = vi.fn();
const debounced = debounce(fn, 300);
debounced();
debounced();
debounced();
expect(fn).not.toHaveBeenCalled();
vi.advanceTimersByTime(300);
expect(fn).toHaveBeenCalledOnce();
});
});
import { defineConfig } from 'vitest/config';
export default defineConfig({
test: {
globals: true, // Use describe/it/expect without imports
environment: 'jsdom', // 'node' | 'jsdom' | 'happy-dom'
include: ['src/**/*.test.{ts,tsx}'],
coverage: {
provider: 'v8',
reporter: ['text', 'json', 'html'],
include: ['src/**/*.{ts,tsx}'],
exclude: ['src/**/*.test.{ts,tsx}', 'src/**/*.d.ts'],
thresholds: {
branches: 80,
functions: 80,
lines: 80,
statements: 80,
},
},
setupFiles: ['./src/test-setup.ts'],
},
});
*.test.ts adjacent to the source file.vi.mock() before imports; restore in afterEach with vi.restoreAllMocks().npx vitest run <file> — fix failures.npx vitest run <file> --reporter=verbose to inspect, fix, re-run.npx vitest run --coverage --reporter=json (CI) or npx vitest run --coverage --reporter=text (local) to generate coverage reports. Inspect coverage/coverage-final.json or the human-readable summary to find uncovered files/branches. If coverage is below thresholds, add targeted tests for uncovered branches, then re-run npx vitest run --coverage until thresholds pass.development
Defines 10 sequential validation gates: secret scanning, lint/test/build checks, blast radius analysis, dependency auditing, browser testing, cache management, regression checks, smoke tests. Use when running pre-deploy validation or CI checks, CI/CD pipelines, deployment pipeline validation, pre-merge checks, continuous integration, or pull request validation.
development
Generates test plans, writes unit/integration/E2E test files, identifies coverage gaps, flags common testing anti-patterns. Use when writing tests, creating test suites, planning test strategies, mocking dependencies, measuring code coverage, or test planning.
development
Provides model routing rules, validates delegation prerequisites, supplies cost tracking templates, defines dead-letter queue formats for Team Lead orchestration. Load when assigning tasks to agents, choosing model tiers, starting delegation session, running multi-agent workflow, delegating work, choosing which model to use, or assigning tasks.
testing
Saves, restores session state including task progress, file changes, delegation history. Use when saving progress, resuming interrupted work, picking up where you left off, or checkpointing current work.