check-code-coverage
Utilities for checking the coverage produced by NYC against extra or missing files
Last updated 4 months ago by bahmutov .
MIT · Repository · Bugs · Original npm · Tarball · package.json
$ cnpm install check-code-coverage 
SYNC missed versions from official npm registry.

check-code-coverage ci status check-code-coverage

Utilities for checking the coverage produced by NYC against extra or missing files

Use

npm i -D check-code-coverage
# check if .nyc_output/out.json has files foo.js and bar.js covered and nothing else
npx only-covered foo.js bar.js

Watch these short videos to see these tools in action:

check-coverage

Checks if the file is present in the output JSON file and has 100% statement coverage

# check if .nyc_output/out.json has 100% code coverage for main.js
npx check-coverage main.js
# read coverage report from particular JSON file
check-coverage --from examples/exclude-files/coverage/coverage-final.json main.js

The file has to end with "main.js". You can specify part of the path, like this

npx check-coverage src/app/main.js

You can pass multiple filenames

npx check-coverage main.js src/person.js

only-covered

Check if the coverage JSON file only the given list of files and nothing else. By default only-covered script reads .nyc_output/out.json file from the current working directory. You can specify a different file using --from parameter.

# check if coverage has info about two files and nothing else
only-covered src/lib/utils.ts src/main.js
# read coverage from another file and check if it only has info on "main.js"
only-covered --from examples/exclude-files/coverage/coverage-final.json main.js

check-total

If you generate coverage report using reporter json-summary, you can check the total statements percentage

check-total
# with default options
check-total --from coverage/coverage-summary.json --min 80

update-badge

If your README.md includes Shields.io badge, like this

![check-code-coverage](https://img.shields.io/badge/code--coverage-80%-brightgreen)

You can update it using statements covered percentage from coverage/coverage-summary.json by running

update-badge

If the coverage summary has 96%, then the above badge would be updated to

![check-code-coverage](https://img.shields.io/badge/code--coverage-96%-brightgreen)
  • The badges will have different colors, depending on the coverage, see bin/update-badge.js
  • If the code coverage badge is not found, a new badge is inserted on the first line.

You can change the JSON summary filename to read coverage from:

update-badge --from path/to/json/summary/file.json

You can also skip reading file and set the coverage number directly

update-badge --set 78
update-badge --set 78%

Related project: dependency-version-badge

set-gh-status

If you run your tests on GitHub Actions, there is an easy way to add commit status with code coverage percentage. From your CI workflow use command:

- name: Set code coverage commit status ????
  run: npx set-gh-status
  env:
    GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

Which should show a commit status message like:

Commit status check

This script reads the code coverage summary from coverage/coverage-summary.json by default (you can specific a different file name using --from option) and posts the commit status, always passing for now.

If there is a coverage badge in the README file, you can add 2nd status check. This check will read the code coverage from the README file (by parsing the badge text), then will set a failing status check if the coverage dropped more than 1 percent. Tip: use this check on pull requests to ensure tests and code are updated together before merging.

- name: Ensure coverage has not dropped ????
  run: npx set-gh-status --check-against-readme
  env:
    GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

Coverage diff

Pull requests

When setting a status on a GitHub pull request, you need to use SHA of the merged commit. You can pass it as GH_SHA environment variable.

- name: Ensure coverage has not dropped ????
  run: npx set-gh-status --check-against-readme
  env:
    GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
    GH_SHA: ${{ github.event.after }}

Debug

To see verbose log messages, run with DEBUG=check-code-coverage environment variable

Current Tags

  • 1.10.0                                ...           latest (4 months ago)

17 Versions

  • 1.10.0                                ...           4 months ago
  • 1.9.3                                ...           6 months ago
  • 1.9.2                                ...           9 months ago
  • 1.9.1                                ...           9 months ago
  • 1.9.0                                ...           9 months ago
  • 1.8.0                                ...           9 months ago
  • 1.7.1                                ...           9 months ago
  • 1.7.0                                ...           9 months ago
  • 1.6.0                                ...           9 months ago
  • 1.5.0                                ...           9 months ago
  • 1.4.1                                ...           9 months ago
  • 1.4.0                                ...           9 months ago
  • 1.3.0                                ...           9 months ago
  • 1.2.0                                ...           9 months ago
  • 1.1.0                                ...           9 months ago
  • 1.0.1                                ...           10 months ago
  • 1.0.0                                ...           10 months ago
Maintainers (1)
Downloads
Today 0
This Week 1
This Month 4
Last Day 1
Last Week 0
Last Month 7
Dependencies (4)
Dev Dependencies (3)
Dependents (0)
None

Copyright 2014 - 2017 © taobao.org |