Test Writer Skill
Priorities
Correctness > Simplicity > Readability > Concision
Goal
Write and review tests that are maintainable, isolated, and follow modern testing principles. Apply flat structure with no nested describe blocks, composable setup functions instead of beforeEach, disposable fixtures for automatic cleanup, and AHA testing principles (avoid hasty abstractions, prefer duplication over wrong abstraction).
Constraints
- Flat structure: No nested describe blocks (max 1 level for grouping)
- Composable setup functions: Return objects, never mutate shared variables
- Disposable fixtures: Use
usingkeyword with Symbol.dispose for automatic cleanup - AHA testing: Prefer explicit tests over test generators, duplication over abstraction
- Descriptive test names: Describe behavior, not implementation
- Fresh state: Each test creates its own setup, no shared mutable state
- Framework-agnostic: Detect vitest/bun/jest from package.json
Modes
Write (default): Generate tests for a source file. Read the source, identify exports, analyze edge cases, write test file with setup functions and disposable fixtures.
Review: Analyze existing tests for anti-patterns. Flag nested describes, beforeEach with variable assignment, missing cleanup, over-abstraction, shared mutable state. Report findings with specific fixes.
Convert: Transform legacy tests to modern patterns. Flatten describes, convert beforeEach to setup functions, add disposables for resources.
Framework Detection
Read package.json to determine framework:
vitest→ Use Vitest patterns (import from 'vitest')bunwith "test" script → Use Bun patterns (import from 'bun:test')jest→ Recommend Vitest migration, use Vitest patterns
Mode Detection
Parse $ARGUMENTS to determine mode:
- First arg is
review→ Review mode - First arg is
convert→ Convert mode - Path to source file → Write mode (default)
- No args → Ask what to test
References
Load test patterns and code examples via:
Glob(pattern: "**/sdlc/**/skills/test/references/test-patterns.md", path: "~/.claude/plugins")→ Read result
Reference file contains:
- Setup function patterns
- Disposable fixture patterns
- Test naming conventions
- Anti-patterns to detect
- Transformation rules for Convert mode
Write Mode Process
- Read source file completely
- Identify exports (functions, classes, constants)
- Analyze inputs, outputs, edge cases, errors, dependencies
- Generate test file with setup functions section and tests section
- Use disposable fixtures for resources (servers, databases, files)
Review Mode Process
- Find test files matching
*.test.ts,*.spec.ts,*.test.tsx,*.spec.tsx - Analyze for anti-patterns: nested describes >1 level, beforeEach with variable assignment, missing cleanup, over-abstraction, shared mutable state
- Report findings with severity, line numbers, current code, and specific fixes
Convert Mode Process
- Read test file completely
- Parse structure: identifies describes, hooks, variable declarations
- Transform: flatten describes, convert beforeEach to setup functions, add disposables
- Write converted file or show diff
Arguments
$ARGUMENTS