Coverage Until Threshold
FeaturedOn demandAbout Coverage Until Threshold
This loop raises test coverage to a target threshold, 80% by default. Each round runs the tests with coverage, finds under-covered code, writes tests for it and measures again. It stops after at most 12 rounds.
Key features
- 01Default coverage threshold of 80%
- 02Requires every test to pass as well
- 03Capped at 12 rounds to avoid endless runs
- 04Started manually in Claude Code
Use cases
- 01Filling coverage gaps in modules that lack tests
- 02Meeting a coverage requirement before merging
- 03Building a test safety net ahead of a refactor
- Goal
- Coverage reaches the target threshold (default 80%) and all tests pass.
- Exit when
- Stop when coverage meets the threshold and npm test -- --coverage exits with code 0.
- Between iterations run
- npm test -- --coverage
Launch prompt
Paste into Claude Code. The agent repeats the steps below until the exit condition is met.
Start the "Coverage Until Threshold" loop. Goal: Coverage reaches the target threshold (default 80%) and all tests pass. Max iterations: 12. Step 1: Measure coverage — Run the tests with coverage, read the report and identify files and branches that fall below the threshold. `npm test -- --coverage` Step 2: Write missing tests — Add or improve tests for the under-covered code, starting with the largest gaps, without breaking existing tests. Step 3: Re-measure — Run the tests with coverage again and compare the result with the threshold. If coverage is still short or a test fails, begin another round. `npm test -- --coverage` Between iterations run: `npm test -- --coverage` Exit when: Stop when coverage meets the threshold and npm test -- --coverage exits with code 0.
Steps
Each round runs in order; if the exit condition isn’t met, another round starts, up to 12.
Run the tests with coverage, read the report and identify files and branches that fall below the threshold.
npm test -- --coverageAdd or improve tests for the under-covered code, starting with the largest gaps, without breaking existing tests.
Run the tests with coverage again and compare the result with the threshold. If coverage is still short or a test fails, begin another round.
npm test -- --coverageSupported agents
Coding agents that can run this loop directly.