@cryptexlabs/coverage-diff
v1.7.2
Published
Reports differences between two istanbul JSON code coverage summaries.
Readme
coverage-diff
What it does
- Accepts base-summary.json and head-summary.json
- Diffs the two jsons and outputs info about
- Percentage of changed coverage (in changed/added files)
- Formatted as markdown table
- Fail if coverage decreases on a file (check on percentage) for any of the lines/func/statements/branches. Can be configured to only check some criteria.
- Written in Typescript
Usage
const fs = require('fs');
const coverageDiff = require('coverage-diff');
const base = JSON.parse(fs.readFileSync('./base-summary.json'));
const head = JSON.parse(fs.readFileSync('./head-summary.json'));
const diff = coverageDiff.diff(base, head);
console.log(diff.diff);
console.log(diff.results);
console.log(diff.regression);Out:
| Ok | File | Lines | Branches | Functions | Statements | | --- | ----- | ------------- | ------------- | ------------ | ------------- | | 🔴 | file1 | 80%(+10%) | 14%(-30%) | 3%(+20%) | 20%(-10%) | | ✅ | file2 | 20%(+10%) | 8%(-30%) | 2%(-20%) | 5%(-10%) |
API at https://flaviusone.github.io/coverage-diff/globals.html#diff
CLI Usage
Example:
coverage-diff \
--base example/base-summary.json \
--head example/head-summary.json \
--minimum 0 \
--decreaseThreshold 3 \
--criteria branches \
--criteria statements \
--output results \
--totals| Option | Alias | Description | Required | Default | | ----------------- | ----- | -------------------------------------------------------------------------------- | -------- | ------------------------------------------------- | | base | b | The path to the older json-summary file | True | n/a | | head | h | The path to the newer json-summary file | True | n/a | | minimum | m | The minimum required code coverage | False | 0 | | decreaseThreshold | d | The amount that the coverage can be decreased by without failing regression test | False | 100 | | criteria | c | The coverage metrics to check for regression test. Pass multiple | False | ['lines', 'branches', 'functions', 'statements'] | | totals | t | Whether or not to only consider the totals for the regression test | False | false | | output | o | Outputs to print: diff, results, regression | False | false |
Auto-generated docs
https://flaviusone.github.io/coverage-diff/
