alivirgo/major-ai-skills/vitest
Claude Code and agent skill by alivirgo/major-ai-skills
- community
Checking that the SKILL.md file is still in the repository.
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.
Install
npx vskill@latest install alivirgo/major-ai-skills/vitestSKILL.md
Vitest High-Performance Testing AI Skill Guide (Claude)
Overview & Engine Architecture
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.
When to use / when not to
Use when
- Vite, Vitest-native, or Next.js projects already on Vite tooling.
- Fast watch mode and ESM-native mocking.
Do not use when
- Jest is mandated with custom transformers the team won't migrate—don't dual-run without reason.
Operational Capabilities & Agent Directives
- Default `pool: 'forks'` for stability; switch to
threadsonly after green CI with isolation on. - `isolate: false` is opt-in speed—requires
restoreMocks, no leakingvi.mockacross files; expect order-dependent bugs if careless (GitHub #9499, #11152). - `clearMocks` / `mockReset` / `restoreMocks` in config or
afterEach; callvi.useRealTimers()after fake timers. - No real sleeps—
vi.useFakeTimers()+vi.advanceTimersByTime. - Path aliases must match Vite (
resolve.aliasorvite-tsconfig-paths). - CI cores: cap
poolOptions.forks.maxThreadson 2-core runners. - `process.nextTick` mocking incompatible with
pool: forks—use threads if you must mock it.
Production config sketch
Mock + timers:
Technical Troubleshooting Matrix
| 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 |
Best practices
- Share Vite plugins with app config via merged
defineConfig. - Prefer
vi.spyOnfor partial mocks when factories leak across files. - Component tests: Testing Library + roles.
- Run
vitest run --coveragein CI; watch locally.
Limitations
- Not a browser E2E runner—pair with
@playwright. - Native modules may require forks over threads.
- Snapshot churn—review intentionally, don't blind
-uin CI.
Related skills
@react— component behavior under test@nextjs— vitest + Next monorepo setup@playwright— E2E layer above unit tests
Agent Operational Directive
MANDATORY: Keep default file isolation unless the suite proves clean teardown. Reset mocks and timers between tests. Never use realsetTimeoutsleeps for assertions. Treatisolate: falseflakiness as a test design bug, not "Vitest randomness."
Sources
Security
- Security scanPassed, 100 of 100Pattern checks on the skill's files.
- Model reviewNot runA model review is scheduled for the next rescan.
Quality evaluation
- Task evaluationNot runNo evaluation yet. Run one in Skill Studio.
Source
- SKILL.md in the repositoryCheckingskills/vitest/SKILL.md
Popularity
- Repository stars
- 2
- Repository forks
- 1
- 7-day trend score
- 3
Stars and forks are for the whole GitHub repository, not this skill alone. Not refreshed yet.
Works with
Any agent vskill installs to: 56 targets in all. These 39 have a page on this site.
- Claude Code
- Cursor
- GitHub Copilot
- Windsurf
- Codex
- Gemini CLI
- Cline
- Amp
- Roo Code
- Goose
- Continue
- Kilo Code
- Junie
- Trae
- OpenHands
- Qwen Code
- AI Agent
- Tabnine Chat
- Sourcegraph Cody
- Amazon Q
- Firebase Genkit
- Sweep
- Devin
- Phind
- Mentat
- Claude Desktop
- Aider
- GPT Pilot
- Plandex
- bolt.new
- v0
- Replit Agent
- Anse
- TypingMind
- BetterChatGPT
- LibreChat
- Warp AI
- Pieces
- Fig AI
Embed badge
[](https://verified-skill.com/skills/alivirgo/major-ai-skills/vitest)