Agent SkillsAgent Skills
BjornMelin

vitest-dev

@BjornMelin/vitest-dev
BjornMelin
2
0 forks
Updated 4/1/2026
View on GitHub

World-class Vitest QA/test engineer for TypeScript + Next.js (local + CI performance focused)

Installation

$npx agent-skills-cli install @BjornMelin/vitest-dev
Claude Code
Cursor
Copilot
Codex
Antigravity

Details

Pathskills/vitest-dev/SKILL.md
Branchmain
Scoped Name@BjornMelin/vitest-dev

Usage

After installing, this skill will be available to your AI coding assistant.

Verify installation:

npx agent-skills-cli list

Skill Instructions


name: vitest-dev metadata: version: 0.1.0 description: World-class Vitest QA/test engineer for TypeScript + Next.js (local + CI performance focused)

vitest-dev

A Claude Code skill for producing high-signal, low-flake, fast Vitest suites (TypeScript + Next.js 16) and for shaping Vitest configuration for optimal local DX and CI throughput.

Core outcomes

  1. Correctness first: tests encode business behavior (not implementation details).
  2. Deterministic: no network, no clocks, no global leakage, no order dependencies.
  3. Fast:
    • fast feedback locally (watch mode + smart filtering)
    • scalable CI (parallel workers + sharding + cache + machine-readable reports)
  4. Actionable failures: failures localize root cause quickly.

Default operating procedure

When asked to add or improve tests:

  1. Map the unit under test
    • Identify public API / observable behavior
    • Identify boundaries: I/O, time, randomness, network, database, filesystem, env, global state
  2. Choose the lightest test that gives confidence
    • Pure unit test (no framework/runtime) → preferred
    • Component test in jsdom (React) when DOM behavior is essential
    • Integration test in Node when multiple modules must cooperate
    • Browser Mode (real browser) only when DOM fidelity matters (layout/visuals, real events)
  3. Design a minimal test matrix
    • happy path(s)
    • boundary conditions
    • error paths
    • key invariants (idempotency, caching semantics, auth gates, etc.)
  4. Implement tests
    • arrange/act/assert clarity
    • isolate side effects and restore mocks
    • prefer stable assertions (toHaveTextContent, role-based queries, etc.)
  5. Run locally and fix
    • run smallest scope first (single file / name filtering)
  6. Harden
    • remove flakiness vectors (timers, concurrency, random, hidden network)
    • ensure tests pass in “run mode” (CI-like)
  7. Optimize
    • reduce expensive setup per test file
    • tune Vitest config: pool, isolate, workers, cache, deps optimization, sharding
  8. Deliver
    • include config + scripts changes needed for local + CI
    • include README notes if non-obvious

Naming and structure conventions

  • Place tests next to code for discoverability:
    • src/foo.tssrc/foo.test.ts
    • src/components/Button.tsxsrc/components/Button.test.tsx
  • Use __tests__ for framework-driven routes when colocation is awkward (Next example uses this convention).
  • Prefer describe('<unit>') with focused it('does X when Y').

Vitest execution modes and what to target

  • Local development: vitest (watch mode by default when TTY is detected).
  • CI: vitest run (forces a single run and is non-interactive).

From the Vitest CLI guide, Vitest defaults to watch mode when process.stdout.isTTY is true and falls back to run mode otherwise, while vitest run always runs once. (See: https://vitest.dev/guide/cli)

Configuration baseline

Recommended “default” config goals

  • Use TypeScript path aliases (monorepos and Next apps frequently need this).
  • Choose an environment per project:
    • node for backend/unit tests
    • jsdom (or happy-dom) for React component tests
  • Keep setup lightweight.

Pool choice (speed vs compatibility)

Vitest runs test files using a pool (forks, threads, vmThreads, vmForks). By default (Vitest v4 docs) it uses forks. threads can be faster but may break libraries that use native bindings; forks uses child_process and supports process APIs like process.chdir(). (See: https://vitest.dev/config/pool)

Rule of thumb:

  • Prefer threads for “pure JS/TS” unit tests.
  • Use forks if you use:
    • native addons (e.g. Prisma, bcrypt, canvas)
    • process.* APIs that are not available in threads
  • Avoid VM pools unless you have measured wins and understand the tradeoffs.

Isolation (speed vs global leakage)

test.isolate defaults to true. Disabling can improve performance when tests don’t rely on side effects (often true for Node-only units). (See: https://vitest.dev/config/isolate)

Rule of thumb:

  • Keep isolate: true for frontend/component tests (jsdom) and any suite that touches global state.
  • Consider isolate: false for Node-only pure units after you have strong isolation discipline.

File-level and test-level parallelism

Cache (CI win)

Vitest caching is enabled by default and uses node_modules/.vite/vitest. (See: https://vitest.dev/config/cache)

For CI, persist this directory between runs (per branch key) for significant speedups.

Next.js 16 integration defaults

Use Next’s recommended baseline:

  • Install (TypeScript): vitest, @vitejs/plugin-react, jsdom, @testing-library/react, @testing-library/dom, vite-tsconfig-paths.
  • Configure test.environment = 'jsdom' with the React + tsconfigPaths plugins.

(See: https://nextjs.org/docs/app/guides/testing/vitest)

Important limitation noted by Next.js: Vitest currently does not support async Server Components; for async components, use E2E tests instead. (See the same Next.js guide above.)

Mocking & test doubles discipline

Preferred hierarchy (from most realistic to most isolated)

  1. Real pure functions (no mocking)
  2. In-memory fakes (e.g., fake repo with a Map)
  3. Contract-driven stubs (minimal, stable)
  4. Spies (vi.spyOn) for verifying interactions
  5. Module mocks (vi.mock) only when necessary

Mock reset policy

  • Default: clean up per test file:
    • afterEach(() => vi.restoreAllMocks())
  • If you use global stubs (env/globals), clean them up in afterEach too.

Timers

Use fake timers to avoid slow sleeps. Vitest’s docs show using vi.useFakeTimers() with vi.runAllTimers() / vi.advanceTimersByTime() to speed time-based code. (See: https://vitest.dev/guide/mocking/timers)

Advanced note: if you configure fakeTimers.toFake to include nextTick, it is not supported with --pool=forks because Node’s child_process uses process.nextTick internally and can hang; it is supported with --pool=threads. (See: https://vitest.dev/config/faketimers)

CI reporting and sharding

Reporters

Sharding (multi-machine parallel CI)

Use --shard with the blob reporter and merge at the end. Vitest recommends the blob reporter for sharded runs and provides --merge-reports. (See: https://vitest.dev/guide/reporters)

Using test projects for multi-environment suites

Use test.projects to run multiple configurations in one process (monorepos or mixed environments). Vitest notes the older “workspace” name is deprecated in favor of projects. (See: https://vitest.dev/guide/projects)

Patterns:

  • project A: environment: 'node', pool: 'threads', isolate: false
  • project B: environment: 'jsdom', isolate: true

Deliverables this skill produces

When invoked, this skill can generate or update:

  • Vitest config(s): vitest.config.ts, multi-project configs, CI overrides
  • Test setup: setupTests.ts, test utils, mocks
  • Tests: unit, integration, React component tests, type tests
  • CI scripts: sharding + merging reports, coverage, flake detection
  • Performance tuning recommendations with measurable steps

Output quality gates

Before finalizing, ensure:

  • No test uses real timers (setTimeout waits), real network, or real clock time without explicit control.
  • All mocks/stubs are restored.
  • Tests pass with:
    • vitest
    • vitest run
  • On CI, tests emit machine-readable artifacts (JUnit, JSON, blob merge) if requested.
  • Coverage settings match team goals and don’t create “coverage theater”.

Where to look for authoritative details (official docs)

More by BjornMelin

View all
ai-sdk-agents
2

Expert guidance for building AI agents with ToolLoopAgent (AI SDK v6+). Use when creating agents, configuring stopWhen/prepareStep, callOptionsSchema/prepareCall, dynamic tool selection, tool loops, or agent workflows (sequential, routing, evaluator-optimizer, orchestrator-worker). Triggers: ToolLoopAgent, agent loop, stopWhen, stepCountIs, prepareStep, callOptionsSchema, prepareCall, hasToolCall, InferAgentUIMessage, agent workflows.

zod-v4
2

Expert guidance for Zod v4 schema validation in TypeScript. Use when designing schemas, migrating from Zod 3, handling validation errors, generating JSON Schema/OpenAPI, using codecs/transforms, or integrating with React Hook Form, tRPC, Hono, or Next.js. Covers all Zod v4 APIs including top-level string formats, strictObject/looseObject, metadata, registries, branded types, and recursive schemas.

streamdown
2

Expert guidance for Vercel's Streamdown library - a streaming-optimized react-markdown replacement for AI applications. Use when: (1) Rendering AI-generated markdown from useChat/streamText, (2) Building chat UIs with streaming responses, (3) Migrating from react-markdown to streaming-friendly rendering, (4) Configuring code blocks (Shiki), math (KaTeX), diagrams (Mermaid), (5) Handling incomplete markdown during AI streaming (remend preprocessor), (6) Customizing markdown styling with Tailwind/CSS variables, (7) Securing AI output with rehype-harden (link/image protocols). Triggers: Streamdown, streaming markdown, AI chat markdown, react-markdown replacement, AI Elements Response, incomplete markdown, remend, Shiki themes, Mermaid diagrams, KaTeX math, rehype-harden, isAnimating, markdown streaming.

dmc-py
2

Expert guidance for building Dash applications with Dash Mantine Components (DMC) v2.x. Use when creating dashboards, forms, data visualization apps with DMC. Covers: MantineProvider theming, style props (m, p, c, bg, w, h), Styles API, callbacks (basic, pattern-matching ALL/MATCH/ALLSMALLER, clientside, background), multi-page apps with Dash Pages, charts (LineChart, BarChart, DonutChart), date pickers, modals, and all 100+ components. Triggers on: dash-mantine-components, DMC, MantineProvider, dmc.Button, dmc.Select, dmc.Modal, dmc.BarChart, Mantine theme, Dash UI components, Dash callbacks, multi-page Dash app, pattern-matching callbacks, clientside callbacks, AppShell.