Creates and updates README testing coverage badges with your json-summary
Creates README badges from istanbul coverage report
Statements | Branches | Functions | Lines |
---|---|---|---|
package.json
or inside your jest config file i.e. jest.config.js
or jestconfig.json
as written below: "coverageReporters": ["json-summary"]
npm i -D istanbul-badges-readme
Add at least one of the below coverage hashes in your README file:
![Statements](#statements#)
![Branches](#branches#)
![Functions](#functions#)
![Lines](#lines#)
A simple example of all hashes being used in a table fashion markup:
| Statements | Branches | Functions | Lines |
| --------------------------- | ----------------------- | ------------------------- | ----------------- |
| ![Statements](#statements#) | ![Branches](#branches#) | ![Functions](#functions#) | ![Lines](#lines#) |
npx istanbul-badges-readme
"scripts": {
"make-badges": "istanbul-badges-readme",
}
npm run istanbul-badges-readme --coverageDir="./my-custom-coverage-directory"
npm run istanbul-badges-readme --readmeDir="./my-custom-readme-directory"
npm run istanbul-badges-readme --silent
npm run istanbul-badges-readme --functionsLabel='Mis funciones!' --branchesLabel='Branches are troublesome!'
npm run istanbul-badges-readme --style="for-the-badges"
npm run istanbul-badges-readme --logo="jest"
--colors
argument. If you want red badges for a code coverage below 50% and yellow badges for a coverage below 60%, you'd do this: npm run istanbul-badges-readme --colors=red:50,yellow:60
npm run istanbul-badges-readme --exitCode=1
pre-commit
script to your package.json. npm install -D husky
"husky": {
"hooks": {
"pre-commit": "npm run test && istanbul-badges-readme && git add 'README.md'"
}
}
You may want to have peace of mind that contributors have run istanbul-badges-readme
locally by performing a simple check in your CI.
The --ci
argument will throw an error, code 0 by default unless exitCode is specified, thus not updating anything regarding coverage, if the badges generated do not match what is already in the README.md
.
You can add this to your package.json as follows for exitCode 0:
"scripts": {
"make-badges": "istanbul-badges-readme",
"make-badges:ci": "npm run make-badges -- --ci",
}
Also if you wish a different exitCode:
"scripts": {
"make-badges": "istanbul-badges-readme",
"make-badges:ci": "npm run make-badges -- --ci --exitCode=1",
}
This is a useful addition/alternative to the githooks approach for some use cases such as larger codebases, slow computers etc, where it isn't always feasible to run all the tests and produce coverage on each commit.
DEFAULT STYLE Square style='square'
:
Square flat style='square-flat'
:
Plastic style='plastic'
:
For the badge style='for-the-badge'
:
βοΈ Tip
We use this in our pull request GitHub Action, check out a recent pull request to see it in action!
Thanks goes to these wonderful people (emoji key):
This project follows the all-contributors specification. Contributions of any kind welcome!
Istanbul Badges Readme is MIT licensed.