@leandroluk/jest-badges

1.0.1 • Public • Published

jest-badges

An evolution of library jest-coverage-badges, adding lots of options and improvements

Create a group of coverage badge

License npm

Creates a group of code coverage badges like the following:

Coverage badge gree Coverage badge gree Coverage badge gree

Currently just reads from Istanbul's JSON summary reporter and downloads a badge from https://shields.io/ for each jest coverage type (statement, branch, functions, lines). Like this:

Coverage lines Coverage functions Coverage branches Coverage statements

*This package is an extension of jest-coverage-badges, but this one creates all the types of coverage and able to use new variations based on shields.io

Usage

  1. Install jest-badges in your project or global

    Project (in your project folder):

    npm install --save jest-badges

    Global:

    npm install --global jest-badges

  2. Configure Jest (in package.json):

    (optional: "text" and "lcov")

    "jest": {
      "coverageReporters": [
        "json-summary", 
        "text",
        "lcov"
      ]
    }

    If you installed in your project, you can create a script to run it, for example:

    "scripts": {
      "test:coverage": "npm test -- --coverage",
      "test:badges": "npm run test:coverage  && jest-badges"
    }
  3. Run npm test -- --coverage

  4. Run jest-badges (or just run: npm run test:badges)

    Resulting in badges:

    • ./coverage/badge-statements.svg
    • ./coverage/badge-lines.svg
    • ./coverage/badge-functions.svg
    • ./coverage/badge-branches.svg

CLI Options

Arg Alias Default Value Info
--in -I /coverage/coverage-summary.json Refer to coverage-summary.json file, defined as default in jest config file. Example:

$ npx jest-badges --in "./cov"
--out -O <rootDir>/coverage Refer to coverage directory, defined in jest config file. Example

$ npx jest-badges --out "./badges"
--prefix -P jest: Refers to prefix before the badge key value. Example

$ npm jest-badges --prefix "example:"
--style -S flat Refers to available styles in shields.io.

Available options:
  • flat
  • flat-square
  • plastic
  • social

Examples:

$ npx jest-badges --style "flat"
--color-danger --colorDanger
-CD
Refers to the color when the coverage is in danger. Example

$ npm jest-badges --color-danger "pink"
--color-warn --colorWarn
-CW
Refers to the color when the coverage is in warning. Example

$ npm jest-badges --color-warn "pink"
--color-ok --colorOk
-CO
Refers to the color when the coverage are ok. Example

$ npm jest-badges --color-ok "pink"
--threshold-danger --thresholdDanger
-TD
80 The value of threshold as danger of coverage. Example

$ npm jest-badges --threshold-danger 50
--threshold-warn --thresholdWarn
-TW
90 The value of threshold as warning of coverage. Example

$ npm jest-badges --threshold-warn 50

Example:
$ jest-coverage-badges --input "./cov" --output "./badges"

After this you can add into Github readme (for example) 😃

Why use this package?

We have great companies like coveralls and codecov, but it's paid for private repositories. If this package we can add badges in our readme by creating the badges (this can be run at your build, upload to a store and consume in the readme or the website).

Author of adaptation of (jest-coverage-badges)

© 2023 [Fork and maintainer] Michael Rodov (rodov.michael@gmail.com)

© 2018 [Main Author of Adaptations] Pamela Peixinho git@pamepeixinho.com (https://pamepeixinho.github.io)

Package Sidebar

Install

npm i @leandroluk/jest-badges

Weekly Downloads

5

Version

1.0.1

License

ISC

Unpacked Size

244 kB

Total Files

18

Last publish

Collaborators

  • leandroluk