testing-plugin/skills/vitest-testing/SKILL.md
Vitest test runner — Vite-native, ESM, watch/UI mode, coverage, mocking, snapshots. Use when setting up tests for Vite projects, migrating from Jest, or needing fast execution.
npx skillsauth add laurigates/claude-plugins vitest-testingInstall this skill globally with one command. Works with Claude Code, Cursor, and Windsurf.
3 of 9 scanners reported clean
Some scanners were skipped, did not run, or reported a non-clean status. Review each row below.
Vitest is a modern test runner designed for Vite projects. It's fast, ESM-native, and provides a Jest-compatible API with better TypeScript support and instant HMR-powered watch mode.
| Use this skill when... | Use another skill instead when... | |------------------------|----------------------------------| | Setting up or configuring Vitest | Writing E2E browser tests (use playwright-testing) | | Writing unit/integration tests in TS/JS | Testing Python code (use python-testing) | | Migrating from Jest to Vitest | Analyzing test quality (use test-quality-analysis) | | Configuring coverage thresholds | Generating property-based tests (use property-based-testing) | | Using mocks, spies, or fake timers | Validating test effectiveness (use mutation-testing) |
bun add --dev vitest
bun add --dev @vitest/coverage-v8 # Coverage (recommended)
bun add --dev happy-dom # DOM testing (optional)
bunx vitest --version # Verify
import { defineConfig } from 'vitest/config';
export default defineConfig({
test: {
globals: true,
environment: 'node',
},
});
bunx vitest # Watch mode (default)
bunx vitest run # Run once (CI mode)
bunx vitest --coverage # With coverage
bunx vitest src/utils.test.ts # Specific file
bunx vitest -t "should add numbers" # Filter by name
bunx vitest related src/utils.ts # Related tests
bunx vitest -u # Update snapshots
bunx vitest bench # Benchmarks
bunx vitest --ui # UI mode
import { describe, it, expect } from 'vitest';
import { add, multiply } from './math';
describe('math utils', () => {
it('should add two numbers', () => {
expect(add(2, 3)).toBe(5);
});
it('should multiply two numbers', () => {
expect(multiply(2, 3)).toBe(6);
});
});
| Assertion | Description |
|-----------|-------------|
| toBe(value) | Strict equality |
| toEqual(value) | Deep equality |
| toStrictEqual(value) | Deep strict equality |
| toBeTruthy() / toBeFalsy() | Truthiness |
| toBeNull() / toBeUndefined() | Null checks |
| toBeGreaterThan(n) / toBeLessThan(n) | Numeric comparison |
| toBeCloseTo(n) | Float comparison |
| toMatch(regex) / toContain(str) | String matching |
| toHaveLength(n) | Array/string length |
| toHaveProperty(key) | Object property |
| toMatchObject(obj) | Partial object match |
| toThrow(msg) | Error throwing |
test('async test', async () => {
const data = await fetchData();
expect(data).toBe('expected');
});
test('promise resolves', async () => {
await expect(fetchData()).resolves.toBe('expected');
});
test('promise rejects', async () => {
await expect(fetchBadData()).rejects.toThrow('error');
});
import { vi, test, expect } from 'vitest';
// Mock function
const mockFn = vi.fn();
mockFn.mockReturnValue(42);
// Mock module
vi.mock('./api', () => ({
fetchUser: vi.fn(() => Promise.resolve({ id: 1, name: 'John' })),
}));
// Mock timers
vi.useFakeTimers();
vi.advanceTimersByTime(1000);
vi.restoreAllMocks();
// Spy on method
const spy = vi.spyOn(object, 'method');
test('snapshot test', () => {
expect(data).toMatchSnapshot();
});
test('inline snapshot', () => {
expect(result).toMatchInlineSnapshot('5');
});
// Update snapshots: bunx vitest -u
bun add --dev @vitest/coverage-v8
bunx vitest --coverage
Key config options: provider, reporter, include, exclude, thresholds.
| Context | Command |
|---------|---------|
| Quick test | bunx vitest --reporter=dot --bail=1 |
| CI test | bunx vitest run --reporter=junit |
| Coverage check | bunx vitest --coverage --reporter=dot |
| Single file | bunx vitest run src/utils.test.ts --reporter=dot |
| Failed only | bunx vitest --changed --bail=1 |
For detailed examples, advanced patterns, and best practices, see REFERENCE.md.
tools
Scaffold a new ComfyUI custom-node repo (pyproject, CI, release-please, vitest+pytest, JS extension skeleton) in the picker/gesture vein. Use when bootstrapping or init-ing a comfyui node pack.
tools
Orchestrate a ComfyUI node pack from idea to registry: scaffold, create + seed the repo, open the gitops adoption PR. Use when releasing or spinning up a new comfyui node pack.
testing
macOS EndpointSecurity/EDR high CPU & battery drain. Use when Kandji ESF / XProtect pegs a core; trace the exec storm via powermetrics + eslogger.
development
odiff pixel-by-pixel image diffing. Use when comparing screenshots, detecting visual regressions, diffing before/after PNGs, asserting golden images.