Nightly Test Coverage Improvement
The caller provides pre-computed context:
- Package manager (
npm,yarn, orbun) - Thresholds file path (vitest.thresholds.json or jest.thresholds.json)
- Current thresholds (statements, branches, functions, lines percentages)
- Proposed thresholds (each metric increased by the coverage increment, capped at 90%)
- Metrics being bumped (which metrics are below target)
Instructions
Phase 1: Identify gaps
- Run the project's coverage script with the provided package manager (e.g.,
npm run test:cov,yarn test:cov, orbun run test:cov) to get the coverage report -- identify gaps BEFORE reading any source files - Parse the coverage output to identify the specific files and lines with the lowest coverage. Prioritize files with the most uncovered lines/branches.
- Read ONE existing test file to learn the project's testing patterns (mocks, imports, assertions). Do not read more than one.
Phase 2: Write tests incrementally — one file at a time
For each source file with low coverage (starting with the lowest):
- Read only the uncovered sections of the source file using the coverage report line numbers -- do not explore the codebase broadly
- Write a test file targeting the uncovered branches/lines for that source file
- Run the test file in isolation (e.g.,
npx vitest run tests/my-new-test.test.ts) to verify it passes before moving on - If the test fails, fix it immediately. Do not move to the next file until the current test passes.
- Repeat steps 4-7 for the next source file. Stop once you estimate the proposed thresholds will be met.
Phase 3: Verify and ship
- Run the full coverage script to verify the new thresholds pass
- Update the thresholds file with the proposed new threshold values
- Re-run the coverage script to confirm the updated thresholds pass
- Commit all changes (new tests + updated thresholds file) with conventional commit messages
- Create a PR with
gh pr createwith a title like "test: increase test coverage: [metrics being bumped]" summarizing coverage improvements