.agents/skills/frontend-testing/references/workflow.md
This guide defines the workflow for generating tests, especially for complex components or directories with multiple files.
This guide addresses multi-file workflow (how to process multiple test files). For coverage requirements within a single test file, see web/docs/test.md § Coverage Goals.
| Scope | Rule |
|---|---|
| Single file | Complete coverage in one generation (100% function, >95% branch) |
| Multi-file directory | Process one file at a time, verify each before proceeding |
When testing a directory with multiple files, NEVER generate all test files at once. Use an incremental, verify-as-you-go approach.
| Batch Approach (❌) | Incremental Approach (✅) |
|---|---|
| Generate 5+ tests at once | Generate 1 test at a time |
| Run tests only at the end | Run test immediately after each file |
| Multiple failures compound | Single point of failure, easy to debug |
| Hard to identify root cause | Clear cause-effect relationship |
| Mock issues affect many files | Mock issues caught early |
| Messy git history | Clean, atomic commits possible |
When testing a single component, hook, or utility:
1. Read source code completely
2. Run `pnpm analyze-component <path>` (if available)
3. Check complexity score and features detected
4. Write the test file
5. Run test: `pnpm test <file>.spec.tsx`
6. Fix any failures
7. Verify coverage meets goals (100% function, >95% branch)
When testing a directory or multiple files, follow this strict workflow:
Process files in this recommended order:
1. Utility functions (simplest, no React)
2. Custom hooks (isolated logic)
3. Simple presentational components (few/no props)
4. Medium complexity components (state, effects)
5. Complex components (API, routing, many deps)
6. Container/index components (integration tests - last)
Rationale:
For EACH file in the ordered list:
┌─────────────────────────────────────────────┐
│ 1. Write test file │
│ 2. Run: pnpm test <file>.spec.tsx │
│ 3. If FAIL → Fix immediately, re-run │
│ 4. If PASS → Mark complete in todo list │
│ 5. ONLY THEN proceed to next file │
└─────────────────────────────────────────────┘
DO NOT proceed to the next file until the current one passes.
After all individual tests pass:
# Run all tests in the directory together
pnpm test path/to/directory/
# Check coverage
pnpm test:coverage path/to/directory/
Use pnpm analyze-component <path> to assess complexity before testing.
Consider refactoring BEFORE testing:
If testing as-is:
test.each() for data-driven testingdescribe blocks for organizationdescribe blocksRegardless of complexity score:
When testing multiple files, use a todo list like this:
Testing: path/to/directory/
Ordered by complexity (simple → complex):
☐ utils/helper.ts [utility, simple]
☐ hooks/use-custom-hook.ts [hook, simple]
☐ empty-state.tsx [component, simple]
☐ item-card.tsx [component, medium]
☐ list.tsx [component, complex]
☐ index.tsx [integration]
Progress: 0/6 complete
Update status as you complete each:
Always run tests after:
Signs you should pause:
# BAD: Writing all files then testing
Write component-a.spec.tsx
Write component-b.spec.tsx
Write component-c.spec.tsx
Write component-d.spec.tsx
Run pnpm test ← Multiple failures, hard to debug
# GOOD: Incremental with verification
Write component-a.spec.tsx
Run pnpm test component-a.spec.tsx ✅
Write component-b.spec.tsx
Run pnpm test component-b.spec.tsx ✅
...continue...
Even simple components can have:
Always verify, regardless of perceived simplicity.
Failing tests compound:
Fix failures immediately before proceeding.
When using Claude for multi-file testing:
Example prompt:
Test all components in `path/to/directory/`.
First, analyze the directory and create a todo list ordered by complexity.
Then, process ONE file at a time, waiting for my confirmation that tests pass
before proceeding to the next.
Before starting multi-file testing:
During testing:
After completion: