/jest-badges-readme

Creates a group of coverage badges from Jest into your README

Primary LanguageTypeScriptMIT LicenseMIT

Deprecated

Please use istanbul-badges-readme instead.

The usage has not changed at all, it has only been made simpler and hopefully bug free.

CodeClimate DevDeps GitHub license npm version PRs Welcome BuiltBy ForTheBadge

Creates Jest Coverage badges for your README.md file

Statements Branches Functions Lines Build Status
Statements Branches Functions Lines BuildStatus

TL;DR

  • To be short, all it does is: Creates your README.md dynamically with your Jest Coverage Badges based on your README-template.md file

Installation

  • Global Installation

      npm i -g @olavoparno/jest-badges-readme
  • Local Installation

      npm i @olavoparno/jest-badges-readme --save-dev

Configuration and requirements

  1. Have Jest installed and with its Coverage Reporting configuration as below
  • It may be set inside your Jest config within package.json or inside your jest config file i.e. jest.config.js or jestconfig.json

      "coverageReporters": [
        "json-summary",
        "lcov"
      ]
  1. 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!") |
  1. 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 terminal

      jest-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:

    1. '#statements#'
    2. '#branches#'
    3. '#functions#'
    4. '#lines#'

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
    1. '#buildstatus#'

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 precommit script to your package.json
  1. Install Husky
  npm install --save-dev husky 
  1. Add your precommit script
  "husky": {
    "hooks": {
      "pre-commit": "jest && node_modules/.bin/jest-badges-readme && git add 'README.md'"
    }
  }
  1. 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!

Contributing

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

Contributors

Thanks goes to these wonderful people (emoji key):


Olavo Parno

🤔 💻 ⚠️

nothingismagick

🤔 🐛 🖋

Dave Fisher

🐛

Martin Zagora

🤔 🐛

This project follows the all-contributors specification. Contributions of any kind welcome!

License

Jest Badges Readme is MIT licensed.