Skip to the content.

Istanbul Badges Readme

Creates README badges from istanbul coverage report

Statements Branches Functions Lines
Statements Branches Functions Lines

Table of Contents

Running example

Example


Requirements

  "coverageReporters": ["json-summary"]

Installation

  npm i -D istanbul-badges-readme
| Statements                  | Branches                | Functions                 | Lines             |
| --------------------------- | ----------------------- | ------------------------- | ----------------- |
| ![Statements](#statements#) | ![Branches](#branches#) | ![Functions](#functions#) | ![Lines](#lines#) |

Simple Usage

  npx istanbul-badges-readme
"scripts": {
  "make-badges": "istanbul-badges-readme",
}

Advanced Usage Arguments

Coverage Directory

  npm run istanbul-badges-readme --coverageDir="./my-custom-coverage-directory"

Readme Directory

  npm run istanbul-badges-readme --readmeDir="./my-custom-readme-directory"

Silent

  npm run istanbul-badges-readme --silent

Functions and Branches Labels

  npm run istanbul-badges-readme --functionsLabel='Mis funciones!' --branchesLabel='Branches are troublesome!'

Badge Style

  npm run istanbul-badges-readme --style="for-the-badges"
  npm run istanbul-badges-readme --logo="jest"

Configure Badge Color

Exit code

  npm run istanbul-badges-readme --exitCode=1

Usage as a part of your githooks

  1. Install Husky.
  npm install -D husky
  1. Add your pre-commit script:
  "husky": {
    "hooks": {
      "pre-commit": "npm run test && istanbul-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!

Usage as a part of your CI

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.

Custom Badge Styles

See running examples

Examples folder

✔️ Tip

We use this in our pull request GitHub Action, check out a recent pull request to see it in action!


Contributors

Thanks goes to these wonderful people (emoji key):

Olavo Parno
Olavo Parno

🤔 💻 ⚠️
nothingismagick
nothingismagick

🤔 🐛 🖋
Dave Fisher
Dave Fisher

🐛
Martin Zagora
Martin Zagora

🤔 🐛
Victor Miti
Victor Miti

🐛
Stefan Huber
Stefan Huber

💬 📖
Guilherme Ventura
Guilherme Ventura

🤔 💻 🐛
Matt Hodges
Matt Hodges

🐛
Antoine Vendeville
Antoine Vendeville

🐛
Oleg Dutchenko
Oleg Dutchenko

🐛
Thomas
Thomas

🤔
Troy Poulter
Troy Poulter

💻 🤔 ⚠️
LiaoLiao
LiaoLiao

🤔
David Mimnagh
David Mimnagh

🤔
Micael Levi L. Cavalcante
Micael Levi L. Cavalcante

🤔 💻 🐛
Richard Michael Coo
Richard Michael Coo

🐛
Letícia Vidal
Letícia Vidal

🐛
Yusuf
Yusuf

📖
Supun Tharinda Edirisuriya
Supun Tharinda Edirisuriya

📖
Nico Meyer
Nico Meyer

💻 🤔

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


License

Istanbul Badges Readme is MIT licensed.