Code Coverage
Track and improve your test coverage with detailed insights
Coverage Metrics
Statement Coverage
Tracks which lines of code have been executed during tests
85% of statements covered
Branch Coverage
Measures if each branch of control structures is executed
75% of branches covered
Function Coverage
Shows which functions have been called during tests
90% of functions covered
Line Coverage
Percentage of executable lines that were run
82% of lines covered
Coverage Reports
HTML Report Example
------------------------|---------|----------|---------|---------|
File | % Stmts | % Branch | % Funcs | % Lines |
------------------------|---------|----------|---------|---------|
All files | 85.71 | 76.92 | 88.89 | 85.71 |
auth/ | 90.91 | 83.33 | 85.71 | 90.91 |
authentication.ts | 90.91 | 83.33 | 85.71 | 90.91 |
utils/ | 81.82 | 71.43 | 91.67 | 81.82 |
validation.ts | 81.82 | 71.43 | 91.67 | 81.82 |
------------------------|---------|----------|---------|---------|
Configuration
Jest Configuration
// jest.config.js
module.exports = {
collectCoverage: true,
coverageDirectory: "coverage",
coverageReporters: ["json", "lcov", "text", "clover"],
coverageThreshold: {
global: {
branches: 80,
functions: 80,
lines: 80,
statements: 80
}
}
}
Best Practices
Set Realistic Goals
- Start with achievable targets
- Gradually increase thresholds
- Focus on critical paths first
Regular Monitoring
- Track coverage trends
- Review uncovered code
- Update tests accordingly
CI/CD Integration
- Enforce coverage gates
- Generate reports automatically
- Block merges if below threshold
Coverage Badges
Add coverage badges to your README:
[](https://coveralls.io/github/username/repo?branch=main)