fix-tests-ensure-coverage
Automatically fix all test failures and ensure coverage targets are met. Runs tests, fixes issues iteratively until 100% pass with 0 skips, runs coverage, and adds tests until targets (85% lines, 80% branches) are achieved. Use when user says "fix tests", "ensure coverage", "make tests pass", or similar.
SKILL.md
| Name | fix-tests-ensure-coverage |
| Description | Automatically fix all test failures and ensure coverage targets are met. Runs tests, fixes issues iteratively until 100% pass with 0 skips, runs coverage, and adds tests until targets (85% lines, 80% branches) are achieved. Use when user says "fix tests", "ensure coverage", "make tests pass", or similar. |
name: fix-tests-ensure-coverage description: Automatically fix all test failures and ensure coverage targets are met. Runs tests, fixes issues iteratively until 100% pass with 0 skips, runs coverage, and adds tests until targets (85% lines, 80% branches) are achieved. Use when user says "fix tests", "ensure coverage", "make tests pass", or similar. allowed-tools: Bash, Read, Edit, Write, Grep, Glob, TodoWrite
Test Fixer & Coverage Enforcer
Automatically fixes all test failures and ensures coverage targets are met for the CI-fixer project.
When to Use
Use this skill when the user asks to:
- "Fix all tests"
- "Ensure coverage targets"
- "Make tests pass with no skips"
- "Get coverage to 100%"
- "Run tests and fix failures"
- Similar variations
Overview
This skill automates the test fixing and coverage process by:
- Running all tests (unit + integration + e2e)
- Analyzing failures and fixing them iteratively until 100% pass with 0 skips
- Running test coverage
- Identifying uncovered files and branches
- Adding tests to meet coverage targets (85% lines, 80% branches)
Coverage Targets
- Lines: 85%
- Branches: 80%
- Functions: 80%
- Statements: 85%
These thresholds are enforced in vitest.config.ts.
Instructions
Phase 1: Fix Test Failures
-
Run all tests:
npm test -
Parse test results to identify:
- Failed tests
- Skipped tests
- Error messages
-
For each failure:
- Read the test file and source file
- Analyze the error
- Determine if it's a test bug or implementation bug
- Fix the issue (either fix the test or fix the implementation)
- Re-run tests to verify the fix
-
Iterate until:
- 100% of tests pass
- 0 tests are skipped
- Or maximum iterations (10) reached
-
For skipped tests:
- Investigate why they are skipped
- Fix the underlying issue preventing them from running
- Remove
.skipmodifiers
Phase 2: Ensure Coverage Targets
-
Run coverage report:
npm run test:coverage -
Parse coverage results to identify:
- Files below line coverage threshold
- Files below branch coverage threshold
- Uncovered functions and statements
-
For each uncovered file:
- Read the source file
- Identify uncovered code paths
- Read existing tests (if any)
- Add comprehensive tests covering:
- Edge cases
- Error conditions
- Different branch conditions
- Boundary values
-
Iterate until:
- All coverage targets met
- Or maximum iterations (5) reached
Test Location Patterns
Tests are located in __tests__/ with the following structure:
- Unit tests:
__tests__/unit/**/*.test.ts - Integration tests:
__tests__/integration/**/*.test.ts - E2E tests:
__tests__/e2e/**/*.spec.ts
Fix Strategy
For Test Failures:
- Understand the error: Read the error message carefully
- Read the source: Understand what the code is supposed to do
- Read the test: Understand what the test is checking
- Determine the fix:
- If test is wrong → fix the test
- If implementation is wrong → fix the implementation
- If test is outdated → update the test
- If API changed → update test and implementation
For Coverage Gaps:
- Analyze uncovered code: Use coverage report to see what's not tested
- Prioritize:
- Critical business logic first
- Error handling paths
- Edge cases and boundary conditions
- Write meaningful tests: Don't just add lines to hit coverage - tests should verify actual behavior
- Follow existing patterns: Match the style and structure of existing tests in the file
Running Tests
All tests:
npm test
Specific test suites:
npm run test:unit
npm run test:integration
npm run test:e2e
Coverage:
npm run test:coverage
Single test file:
npx vitest run path/to/test.test.ts
Example Usage
User: "Fix all my tests and make sure coverage is good"
Claude will:
- Run
npm testto see current state - Identify failures and skipped tests
- Fix each failure iteratively
- Run
npm run test:coverage - Identify coverage gaps
- Add tests to meet targets
- Report final results
Important Notes
- TDD approach: Write tests before implementation when possible
- Don't skip tests: Ensure all tests can run (remove
.skipmodifiers) - Meaningful tests: Coverage for the sake of coverage is not useful - tests should verify actual behavior
- Fix the root cause: Don't just make tests pass by making them less specific
- Consider performance: Unit tests should be <100ms, integration tests <5s
- Non-interactive: Use
CI=truefor any watch-mode tools
Troubleshooting
Tests keep failing:
- Check if dependencies are installed
- Verify database is initialized (
npx prisma db push) - Check environment variables (
.env.local) - Look for circular dependencies or import issues
Coverage not improving:
- Ensure new tests actually execute the uncovered code
- Check for conditional code paths (if statements, switch cases)
- Look for error handling that's not triggered
- Verify async/await code paths are tested
Skipped tests:
- Find
.skipmodifiers and remove them - Check if tests are skipped with
it.skipordescribe.skip - Ensure prerequisites are met (e.g., test data, services)