@codelenny/1pct
v0.1.0
Published
Summarize Istanbul Coverage
Downloads
7
Readme
1%: Summarize Istanbul Coverage
Running tests through Istanbul produces separate percentages for statements, branches, functions, and lines:
$(npm bin)/nyc (ava|mocha|...)
# ----------------------------|----------|----------|----------|----------|----------------|
# File | % Stmts | % Branch | % Funcs | % Lines |Uncovered Lines |
# ----------------------------|----------|----------|----------|----------|----------------|
# All files | 50.00 | - | - | 90.00 | |
# ...
# ----------------------------|----------|----------|----------|----------|----------------|
Use 1% to merge each coverage metric into a single percentage. For instance, 2/4 statements (50% statement coverage)
and 9/10 lines (90% line coverage) would become 79% total coverage (calculated using (2+9)/(4+10)
).
Installation
npm install --save-dev @codelenny/1pct
Usage
Run your tests normally:
$(npm bin)/nyc (ava|mocha|...)
# ----------------------------|----------|----------|----------|----------|----------------|
# File | % Stmts | % Branch | % Funcs | % Lines |Uncovered Lines |
# ----------------------------|----------|----------|----------|----------|----------------|
# All files | 50.00 | - | - | 90.00 | |
# ...
# ----------------------------|----------|----------|----------|----------|----------------|
Generate a JSON coverage summary for 1%:
$(npm bin)/nyc report --reporter=json-summary
Run 1% to summarize the total coverage:
$(npm bin)/1%
# statements: Covered 2 out of 4 total (50%)
# ...
# lines: Covered 9 out of 10 total (90%)
Total coverage metrics: 11/14
Total coverage: 78.57%
If you're using GitLab CI or another platform that extracts the coverage percentage from the log output, you can use the following regular expression to filter the total coverage:
/Total coverage: ([0-9]{1,3}\.[0-9]{2})\%/