$npx -y skills add PaulRBerg/agent-skills --skill vitestUse for Vitest in TypeScript React/Next.js: write, run, or debug unit/component tests, mocks, testing utilities, and coverage.
| 1 | # Vitest |
| 2 | |
| 3 | Follow the repository's Vitest configuration and test conventions before introducing generic patterns. |
| 4 | |
| 5 | ## Workflow |
| 6 | |
| 7 | 1. Inspect package scripts, Vitest config/projects, setup files, neighboring tests, path aliases, environment selection, |
| 8 | and repository instructions. Read [references/configuration.md](references/configuration.md) for config anatomy, |
| 9 | projects, environments, and setup files. |
| 10 | 2. Define the behavior or regression the test must prove. Prefer public behavior and observable outcomes over |
| 11 | implementation details. |
| 12 | 3. Match local file placement, naming, imports/globals, fixtures, cleanup, DOM utilities, and assertion style. Do not |
| 13 | enable globals, jsdom, coverage, or new setup merely because they are common defaults. |
| 14 | 4. Load conditional guidance only when needed: |
| 15 | - components, async behavior, snapshots, type tests, tables, fixtures, tags: |
| 16 | [references/testing-patterns.md](references/testing-patterns.md); |
| 17 | - spies, module mocks, timers, environment stubs: [references/mocking.md](references/mocking.md); |
| 18 | - config, projects, environments, coverage, reporters, v4 migration: |
| 19 | [references/configuration.md](references/configuration.md); |
| 20 | - timeouts, flaky tests, mock failures, resolution errors: |
| 21 | [references/troubleshooting.md](references/troubleshooting.md). |
| 22 | 5. Run the narrowest established command for the changed file or test name, then the affected package suite when shared |
| 23 | setup or contracts changed. Use `nlx vitest run ...` only when the repository has no preferred recipe/script. Prefer |
| 24 | `--reporter=agent` on Vitest 4.1+ for minimal agent-friendly output when the repository has no reporter convention. |
| 25 | |
| 26 | ## Defaults |
| 27 | |
| 28 | - Colocate tests when the repository does. |
| 29 | - Restore mocks, timers, environment, and mutable shared state using the local cleanup convention. |
| 30 | - Mock system boundaries, not the behavior under test. |
| 31 | - Add coverage configuration only when coverage is the requested outcome. |
| 32 | - Do not use jest-dom matchers unless setup imports `@testing-library/jest-dom`. |
| 33 | - In Effect-TS repositories, follow `@effect/vitest` conventions (`it.effect`, Layers, TestClock) instead of generic |
| 34 | patterns. |
| 35 | - For a bug fix, reproduce the failure before relying on the passing result when practical. |
| 36 | |
| 37 | Completion requires a focused test that meaningfully exercises the requested behavior and passes under the repository's |
| 38 | configuration. For a bug with observed red-before-green evidence, finish with `### 🧪 Regression covered`; otherwise use |
| 39 | `### 🧪 Tests verified`. Include a phase/command/result table with only the phases actually run. Report mock, timer, |
| 40 | environment, or shared-state cleanup only when the checks provide that evidence. Keep reporter output, snapshots, |
| 41 | assertions, failure text, commands, and diagnostics exact and undecorated. |