Add test coverage reporting and CI integration
Overview
Currently there's no visibility into test coverage percentage or which code paths are tested.
Goals
- Generate test coverage reports
- Track coverage over time
- Enforce minimum coverage thresholds
- Display coverage in CI/CD pipeline
Implementation Tasks
1. Add Coverage Tool
Choose and integrate a Lua coverage tool:
-
Option A: luacov (most popular)
- Install luacov
- Configure .luacov file
- Generate coverage reports
-
Option B: luacov-coveralls
- For GitLab CI integration
- Upload coverage to external service
2. Update Test Runner
Modify run-ci-locally.sh:
- Enable coverage collection
- Generate coverage report after tests
- Display coverage summary
- Save coverage data
3. GitLab CI Integration
Update .gitlab-ci.yml:
- Add coverage job
- Parse coverage output
- Report coverage percentage
- Fail if coverage drops below threshold
- Generate coverage badge
4. Coverage Reporting
- Generate HTML coverage reports
- Highlight uncovered lines
- Show coverage by file
- Track coverage trends
5. Coverage Thresholds
Set minimum coverage targets:
- Overall: 80% (aspirational)
- Per module: 70% minimum
- Critical modules (utils, template, remove): 90%
6. Documentation
Update docs with:
- How to run coverage locally
- How to interpret coverage reports
- Coverage goals and current status
- How to add tests to improve coverage
Files to Update
-
run-ci-locally.sh- Add coverage options -
.gitlab-ci.yml- Add coverage job -
.luacov- Coverage configuration -
README.md- Add coverage badge -
docs/- Add testing documentation
Example Configuration
-- .luacov
return {
statsfile = "luacov.stats.out",
reportfile = "luacov.report.out",
include = {
"^lua/zk%-extras"
},
exclude = {
"tests/",
},
}
Coverage Goals (Progressive)
- Phase 1 (Current): 15% (only init tests)
- Phase 2: 40% (add utils, template tests)
- Phase 3: 60% (add command tests)
- Phase 4: 80% (comprehensive coverage)
Priority
Medium - Infrastructure improvement that enables better testing
Dependencies
- Issue #8 (closed): utils.lua tests
- Issue #9 (closed): template.lua tests
- Issue #10 (closed): snippet.lua tests
- Issue #11 (closed): remove.lua tests
- Issue #12 (closed): command tests
- Issue #13 (closed): misc.lua tests
- Issue #14 (closed): integration tests
Notes
- Start with basic coverage reporting
- Improve incrementally as tests are added
- Don't block development on coverage requirements initially
- Use coverage to identify gaps