Create a coverage badge - but better
Creates a code coverage badge like the following:
Currently just reads from Istanbul's JSON summary reporter and downloads a badge from https://shields.io/. Don't expect too much! Send a PR if you need configuration etc.
npm install --save-dev @joshjohanning/make-coverage-badge-betterOr install globally:
npm install -g @joshjohanning/make-coverage-badge-better(For Create React Apps)
- Configure Jest (in
package.json):
"jest": {
"coverageReporters": [
"json-summary"
]
}- Run
npm test -- --coverage - Run
make-coverage-badge-better
Resulting badge will be in ./coverage/badge.svg.
Create a badge with a GitHub logo and blue label:
make-coverage-badge-better --logo github --label-color blueCreate a badge with a custom style and logo color:
make-coverage-badge-better --style flat-square --logo javascript --logo-color yellowCreate a badge with all customizations:
make-coverage-badge-better \
--label-color "#0969da" \
--logo github \
--logo-color white \
--style for-the-badge \
--link "https://github.com/yourorg/yourrepo"Writes the coverage badge to the given path (relative to project root). Defaults to ./coverage/badge.svg.
Path to a coverage report file. Defaults to ./coverage/coverage-summary.json.
The following options allow you to customize the appearance of the badge using shields.io parameters:
Background color of the label (left side of the badge). Supports hex colors, named colors, etc.
Example: --label-color blue or --label-color "#0969da"
Add a logo from simple-icons to the badge.
Example: --logo github or --logo javascript
Color of the logo. Supports hex colors, named colors, etc.
Example: --logo-color white
Width of the logo in pixels.
Example: --logo-width 20
Badge style. Available options:
flat(default)flat-squareplasticfor-the-badgesocial
Example: --style flat-square
Text to prefix the coverage percentage.
Example: --prefix "v"
Text to suffix the coverage percentage.
Example: --suffix " coverage"
HTTP cache duration in seconds.
Example: --cache-seconds 3600
URL to link to when the badge is clicked. Can be used twice for separate left and right links.
Example: --link "https://github.com/yourorg/yourrepo"
- Coveralls: paid for private repos
- coverage-badger: same approach, but using an XML report and therefore requires XML dependencies
© 2019 Tom Vincent git@tlvince.com (https://tlvince.com)
Released under the MIT license.