npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

check-code-coverage

v1.10.5

Published

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

Downloads

27,425

Readme

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

The command exits with 0 if the total is above or equal to the minimum number. If the code coverage is below the minimum, the command exits with code 1. On most CIs any command exiting with non-zero code fails the build.

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 -p check-code-coverage 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 -p check-code-coverage 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 -p check-code-coverage 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