/jest-badges-readme

Creates a group of coverage badges from Jest into your README

Primary LanguageTypeScriptMIT LicenseMIT

Jest Badges Readme

Creates Jest Coverage badges for your README.md file.

Statements Branches Functions Lines Build Status Built By We Love
Statements Branches Functions Lines BuildStatus BuiltBy ForTheBadge

TL;DR

  • To be short, all it does is: Creates your README.md dinamically with your Jest Coverage Badges on top of 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

Requirements (it's taken for granted that you'll meet those). Also please be working with any project running Jest.

  • Minor adendum: you must have your Jest configured with the property coverageReporters properly setup. e.g.:
      "coverageReporters": [
        "json-summary",
        "text",
        "lcov"
      ]
  • Have a README-template.md file created.

Let's all get back to what Jest covers for us.

  • % Stmts (which states for Statements).
  • % Branch (pretty self explanatory).
  • % Functions (won't repeat myself).
  • % Lines (last but not least).

This tool will create badge URLs for these former 4 items into your README-template.md if you follow the next steps:

  • Open up your README-template.md and add 4 markers inside it respectively for each Jest coverage items. These markers would be as follows:
    1. '#statements#'
    2. '#branches#'
    3. '#functions#'
    4. '#lines#'

Are you in need of a local building badge? Add these NPM scripts in order to manage your local building badges as well:

  "prebuild": "echo false > .buildstatus",
  "postbuild": "echo true > .buildstatus"
  • Add one more marker like this:
    1. '#buildstatus#'
  • This is going to create a file called .buildstatus in your root project telling this tool if your build is successful or not with either true or false. Simply put.

Example of README-template.md:

| Statements | Branches | Functions | Lines | Build Status | Built By | We Love |
| -----------|----------|-----------|-------| ------------ | -------- | ------- |
| ![Statements](#statements# "Make me better!") | ![Branches](#branches# "Make me better!") | ![Functions](#functions# "Make me better!") | ![Lines](#lines# "Make me better!") | ![BuildStatus](#buildstatus# "Building Status") | ![BuiltBy](https://img.shields.io/badge/TypeScript-Lovers-black.svg "img.shields.io") | ![ForTheBadge](https://img.shields.io/badge/Using-Badges-red.svg "ForTheBadge")

Which results in in the report above!

Summarizing it all

Create a NPM Script as the example:

  • For locally installed library:

      "make-badges": "node_modules/.bin/jest-badges-readme || true",
      "make-readme": "npm run test:coverage && npm run make-badges"
  • For globally installed library:

      "make-readme": "npm run test:coverage && jest-badges-readme"