Creates Jest Coverage badges for your README.md file
- To be short, all it does is: Creates your README.md dynamically with your Jest Coverage Badges based on your README-template.md file
Global Installationnpm i -g @olavoparno/jest-badges-readme
Local Installationnpm i @olavoparno/jest-badges-readme --save-dev
Configuration and requirements
- Have Jest installed and with its Coverage Reporting configuration as below
It may be set inside your Jest config within
package.jsonor inside your jest config file i.e.
- Have a README-template.md file created with the following template (please do feel free to change its presentation structure, e.g. in a table or not)
| Statements | Branches | Functions | Lines || -----------|----------|-----------|-------|| ![Statements](#statements# "Make me better!") | ![Branches](#branches# "Make me better!") | ![Functions](#functions# "Make me better!") | ![Lines](#lines# "Make me better!") |
- Call if from your terminal or from your NPM/YARN Scripts
For locally installed library"make-badges": "node_modules/.bin/jest-badges-readme"
For globally installed library"make-badges": "npm run jest-badges-readme"
You may also provide a different coverage folder path passed as arguments"make-badges": "npm run jest-badges-readme --coverageDir='./my-custom-coverage-folder'"
And finally via the very terminaljest-badges-readme --coverageDir='./my-custom-coverage-folder'
Short summary onto what Jest and Jest Badges Readme covers for us
- % Stmts (which states for Statements)
- % Branch (pretty self explanatory)
- % Functions (won't repeat myself)
- % Lines (last but not least)
This library will create badges URLs for these former 4 items into your README-template.md if you followed the previous steps
Open up your README-template.md and add 4 markers inside it for each Jest coverage item respectively. These markers must be as follows:
If you feel you might need a local building badge indicator, add these NPM scripts in order to manage your local building badge as well
"prebuild": "echo nok > .buildstatus","postbuild": "echo ok > .buildstatus"
- Add one more marker like the example below. This is going to create a file called .buildstatus in your project's root telling this library if your build is either successful or a failure
Example of README-template.md with building status too
| Statements | Branches | Functions | Lines | Build Status || -----------|----------|-----------|-------| ------------ || ![Statements](#statements# "Make me better!") | ![Branches](#branches# "Make me better!") | ![Functions](#functions# "Make me better!") | ![Lines](#lines# "Make me better!") | ![BuildStatus](#buildstatus# "Building Status") |
Using as a part of your githooks
- If you want to have this run on the precommit hook and update the commit in place, just install husky and add the
precommitscript to your package.json
- Install Husky
npm install --save-dev husky
- Add your precommit script
- Git Commit and Push. Just use your workflow as usual. If your tests fail, no commit. If they pass, update the README.md and add the file to the commit. Nice!
The purpose of this library is to motivate developers to constantly write a solid documentation and testing. A complete and nice looking documentation is key to a successful development and code maintainability. Please feel free to open any issues you might come up with and to submit your own PRs. There is not a contributing guide yet
Thanks goes to these wonderful people (emoji key):
🤔 💻 ⚠️
🤔 🐛 🖋
This project follows the all-contributors specification. Contributions of any kind welcome!
Jest Badges Readme is MIT licensed.