Vitest

From Asymmetric-al/core · View interactive version

Vitest is an AI agent skill from the GitHub repository Asymmetric-al/core. Write, review, filter, mock, and debug Core unit tests with the repository's installed Vitest 5 configuration. Use for tests under Core's Vitest include paths, `vi.mock`/spies/timers, jsdom component tests, coverage output, focused reruns, or unit-test failures. Do not use for browser E2E flows or a

How to use this skill

Skill file

Vitest in Core

Use the repository harness as the source of truth. Core currently resolves

Vitest 5.0.5 from bun.lock; verify the exact version before relying on a newly

introduced API.

Authority and test surface

Read these before changing tests or configuration:

timeouts, mock clearing, setup, and the supported V8 coverage provider.

Do not use bun test; that selects Bun's test runner. Use Vitest through the

committed scripts or bunx vitest.

Commands

# Full CI-equivalent unit suite with the supported V8 coverage provider
bun run test:unit

# Focused file or directory while iterating
bunx vitest run tests/unit/path/to/example.test.ts

# Focused test name
bunx vitest run tests/unit/path/to/example.test.ts -t "expected behavior"

# Watch a focused surface
bunx vitest tests/unit/path/to/example.test.ts

# Structured failure report and targeted reruns
bun run test:unit:feedback

Workflow

  1. Choose the boundary. Test observable behavior at the smallest stable

public boundary. Prefer pure logic/unit coverage; use Playwright when the

claim depends on a real browser, routing, hydration, or an async Server

Component.

  1. Place the test in an included path. Match the existing tests/unit,

packages/api/tests/unit, or packages/auth conventions from

vitest.config.mts; do not invent a disconnected test root.

  1. Control the environment. The default is node. Add

// @vitest-environment jsdom only to files that need DOM APIs, and clean up

rendered components and mutated globals.

  1. Mock boundaries, not the unit's internals. Remember that vi.mock is

hoisted. Use vi.hoisted for shared mock state, dynamic imports when a module

must load after mocks, and vi.importActual for intentional partial mocks.

  1. Reset all changed state. clearMocks: true clears call history but does

not restore globals, timers, dates, env values, or spy implementations. Undo

those changes in hooks.

  1. Run focused, then full. Iterate on the smallest file/name filter and run

bun run test:unit before handoff.

Core-specific guardrails

services. Use deterministic fakes at repository boundaries.

placeholders and intentionally clear the Supabase service-role key.

implementation order unless that order is itself the contract.

loss of required coverage.

measured line, statement, branch and function reports. The default denominator

is imported source under the configured filters, not all repository files.

Do not infer whole-repository coverage or retrofit measured percentages onto

historical fallback reports. Missing, malformed or zero-total reports are

unavailable. The isolated-suite regression proves remapping and threshold

enforcement; keep it passing when changing providers or worker behavior.

Checklist

Provenance

See references/upstream.md for the reviewed upstream

source, version compatibility decision, license, and refresh workflow.

Use this skill with your AI agent: Open on Skill Issue to copy, download, or add to your library. Works with Claude, ChatGPT, Gemini, Cursor, Windsurf and more.