This document explains the code coverage configuration for QuorumProof.
Main coverage configuration:
test: {
coverage: {
provider: "v8", // Coverage provider
reporter: ["text", "json", "html", "lcov"], // Report formats
exclude: [ // Files to exclude
"node_modules/",
"dist/",
"**/*.test.ts",
"**/*.test.tsx",
"**/index.ts",
"src/main.tsx",
"src/setupTests.ts",
],
lines: 70, // Line coverage threshold
functions: 70, // Function coverage threshold
branches: 65, // Branch coverage threshold
statements: 70, // Statement coverage threshold
},
}GitHub Actions workflow for automated coverage:
- Runs on push to main/develop
- Runs on pull requests
- Uploads to Codecov
- Comments on PRs with coverage metrics
- Archives reports for 30 days
Local coverage reporting script:
./scripts/coverage.shGenerates and displays coverage reports locally.
Percentage of executable lines covered by tests.
- Target: 70%
- Why: Ensures most code paths are tested
Percentage of functions called during tests.
- Target: 70%
- Why: Ensures functions are actually used in tests
Percentage of conditional branches executed.
- Target: 65% (lower than others)
- Why: Some branches are harder to test (error cases, edge cases)
Percentage of statements executed.
- Target: 70%
- Why: Similar to lines, ensures code is exercised
The following are excluded from coverage:
node_modules/- Dependenciesdist/- Build output**/*.test.ts- Test files themselves**/*.test.tsx- Test files themselves**/index.ts- Re-export filessrc/main.tsx- Entry pointsrc/setupTests.ts- Test setup
To require higher coverage:
- Edit
frontend/vite.config.ts - Increase threshold values
- Add tests to meet new thresholds
- Verify with
npm run test:coverage
Example:
coverage: {
lines: 80, // Increased from 70
functions: 80, // Increased from 70
branches: 75, // Increased from 65
statements: 80, // Increased from 70
}To lower requirements (not recommended):
- Edit
frontend/vite.config.ts - Decrease threshold values
- Document why in commit message
To exclude additional files:
- Edit
frontend/vite.config.ts - Add pattern to
excludearray - Use glob patterns (e.g.,
**/mock/**)
Example:
exclude: [
"node_modules/",
"dist/",
"**/*.test.ts",
"**/*.test.tsx",
"**/mocks/**", // New exclusion
"**/fixtures/**", // New exclusion
]- Location:
frontend/coverage/lcov-report/index.html - Use: Visual inspection, drill-down analysis
- Features:
- File-by-file breakdown
- Line-by-line highlighting
- Coverage trends
- Location:
frontend/coverage/coverage-final.json - Use: Programmatic access, CI/CD integration
- Format: Structured coverage data
- Location:
frontend/coverage/lcov.info - Use: Third-party tools, Codecov upload
- Format: Standard coverage format
- Display: Terminal output
- Use: Quick overview, CI/CD logs
- Format: Human-readable summary
Coverage workflow runs:
- On push to main/develop
- On pull requests
- Uploads to Codecov
- Comments on PRs
- Tracks coverage over time
- Generates badges
- Provides trend analysis
- Integrates with GitHub
- Run
npm run test:coverage - Open
frontend/coverage/lcov-report/index.html - Identify uncovered files
- Add tests for uncovered code
- Re-run coverage
- Click file in HTML report
- See uncovered lines highlighted
- Add tests for those lines
- Verify coverage improved
- Check GitHub Actions logs
- Verify dependencies installed
- Check Node.js version
- Verify test files exist
- Aim for high coverage: 80%+ is ideal
- Test critical paths: Focus on business logic
- Test error cases: Don't just test happy path
- Keep thresholds reasonable: Don't over-engineer
- Review coverage regularly: Track trends