/major-ai-skills:vitestfrom major-ai-skills
Configure Vitest with fork/thread pool isolation, mock lifecycle, fake timers, coverage gates, and CI-friendly concurrency. Use for unit and component tests in Vite/Next projects; diagnose parallel flakiness from shared module state.
Ships in major-ai-skills. Installing the plugin adds it to Claude Code.
What the skill costs in Claude's context, stage by stage
Name and description: Claude knows it exists.
SKILL.md joins the conversation and stays.
Read when SKILL.md points to them.
Vitest reuses Vite's transform pipeline for fast ESM/TS tests. Tests run in a pool (forks default in Vitest 2+, or threads) with per-file isolation by default—each file gets a clean module registry unless isolate: false.
Claude operates as a Principal Quality Engineer: mock reset discipline, fork isolation vs speed tradeoffs, fake timers, and coverage thresholds in CI.
vitest.config.ts
→ pool (forks | threads | vmThreads)
→ per-file isolation (default true)
→ happy-dom/jsdom for components
→ v8 coverage + thresholds
Use when
Do not use when
pool: 'forks' for stability; switch to threads only after green CI with isolation on.isolate: false is opt-in speed—requires restoreMocks, no leaking vi.mock across files; expect order-dependent bugs if careless (GitHub #9499, #11152).clearMocks / mockReset / restoreMocks in config or afterEach; call vi.useRealTimers() after fake timers.vi.useFakeTimers() + vi.advanceTimersByTime.resolve.alias or vite-tsconfig-paths).poolOptions.forks.maxThreads on 2-core runners.process.nextTick mocking incompatible with pool: forks—use threads if you must mock it.import { defineConfig } from "vitest/config";
import path from "node:path";
export default defineConfig({
resolve: { alias: { "@": path.resolve(__dirname, "./src") } },
test: {
environment: "happy-dom",
pool: "forks",
isolate: true,
restoreMocks: true,
coverage: {
provider: "v8",
thresholds: { lines: 85, branches: 80 },
},
},
});
Mock + timers:
beforeEach(() => {
vi.useFakeTimers();
vi.clearAllMocks();
});
afterEach(() => {
vi.useRealTimers();
});
| Issue | Root cause | Fix |
|---|---|---|
document is not defined | No DOM env | environment: 'happy-dom' |
| Flaky parallel failures | Shared module mock with isolate: false | Re-enable isolation or fix mock scope |
| Wrong mock in unrelated file | Module cache + isolate: false | pool: forks + isolate: true |
Can't find @/ | Missing alias | vitest resolve.alias |
| CI OOM / slow | Too many threads | Lower maxThreads |
defineConfig.vi.spyOn for partial mocks when factories leak across files.vitest run --coverage in CI; watch locally.@playwright.-u in CI.@react — component behavior under test@nextjs — vitest + Next monorepo setup@playwright — E2E layer above unit testsMANDATORY: Keep default file isolation unless the suite proves clean teardown. Reset mocks and timers between tests. Never use real
setTimeoutsleeps for assertions. Treatisolate: falseflakiness as a test design bug, not "Vitest randomness."
What SKILL.md sets; muted values are Claude Code's defaults
npx claudepluginhub alivirgo/major-ai-skills --plugin major-ai-skills412 skills in this plugin
/3d-slicerAutomate 3D Slicer research workflows with MRML, VTK/ITK, DICOM data, and Segment Editor. Use for software workflows, not clinical interpretation./abbreviated-git-statusInspect Git branch, staging, and working-tree changes with short or porcelain status output when a compact repository check is needed./ableton-liveAutomate Ableton Live sessions with Python MIDI Remote Scripts, Max for Live, AbletonOSC, and Link synchronization./act-as-a-personal-tutorExplain a subject step by step, assess prior knowledge, and use short exercises to check understanding before advancing.Other plugins' skills for the same job