An evolution of library jest-coverage-badges, adding lots of options and improvements
Create a group of coverage badge
Creates a group of code coverage badges like the following:
Currently just reads from Istanbul's JSON summary reporter and downloads a badge from https://shields.io/ for each jest coverage type (statement
, branch
, functions
, lines
). Like this:
*This package is an extension of jest-coverage-badges, but this one creates all the types of coverage and able to use new variations based on shields.io
-
Install
@leandroluk/jest-badges
in your project or globalProject (in your project folder):
npm install --save @leandroluk/jest-badges
Global:
npm install --global @leandroluk/jest-badges
-
Configure Jest (in
package.json
):(optional: "text" and "lcov")
"jest": { "coverageReporters": [ "json-summary", "text", "lcov" ] }
If you installed in your project, you can create a script to run it, for example:
"scripts": { "test:coverage": "npm test -- --coverage", "test:badges": "npm run test:coverage && jest-badges" }
-
Run
npm test -- --coverage
-
Run
jest-badges
(or just run:npm run test:badges
)Resulting in badges:
./coverage/badge-statements.svg
./coverage/badge-lines.svg
./coverage/badge-functions.svg
./coverage/badge-branches.svg
Arg | Alias | Default Value | Info |
---|---|---|---|
--in |
-I |
<rootDir>/coverage/coverage-summary.json |
Refer to coverage-summary.json file, defined as default in jest config file. Example: $ npx jest-badges --in "./cov"
|
--out |
-O |
<rootDir>/coverage |
Refer to coverage directory, defined in jest config file. Example $ npx jest-badges --out "./badges"
|
--prefix |
-P |
jest: |
Refers to prefix before the badge key value. Example $ npm jest-badges --prefix "example:"
|
--style |
-S |
flat |
Refers to available styles in shields.io. Available options: • flat • flat-square • plastic • social Examples: $ npx jest-badges --style "flat"
|
--color-danger |
--colorDanger -CD
|
Refers to the color when the coverage is in danger. Example $ npm jest-badges --color-danger "pink"
|
|
--color-warn |
--colorWarn -CW
|
Refers to the color when the coverage is in warning. Example $ npm jest-badges --color-warn "pink"
|
|
--color-ok |
--colorOk -CO
|
Refers to the color when the coverage are ok. Example $ npm jest-badges --color-ok "pink"
|
|
--threshold-danger |
--thresholdDanger -TD
|
80 |
The value of threshold as danger of coverage. Example $ npm jest-badges --threshold-danger 50
|
--threshold-warn |
--thresholdWarn -TW
|
90 |
The value of threshold as warning of coverage. Example $ npm jest-badges --threshold-warn 50
|
Example:
$ jest-badges --input "./cov" --output "./badges"
After this you can add into Github readme (for example) 😃
We have great companies like coveralls and codecov, but it's paid for private repositories. If this package we can add badges in our readme by creating the badges (this can be run at your build, upload to a store and consume in the readme or the website).
© 2023 [Fork and maintainer] Michael Rodov (rodov.michael@gmail.com)
© 2018 [Main Author of Adaptations] Pamela Peixinho git@pamepeixinho.com (https://pamepeixinho.github.io)