Skip to content

Github action generating coverage badges using jest and pushing them to the repo

Notifications You must be signed in to change notification settings

ishmelev-sp/jest-badges-action

 
 

Repository files navigation

jest-badges-action

Open in Visual Studio Code Github workflow Quality Gate Status Maintainability Rating Security Rating Reliability Rating Coverage Total coverage Lines of Code Technical Debt Code Smells Bugs Vulnerabilities Duplicated Lines (%) Last commit

⚡ Description

This github action generates testing coverage badges using jest and pushes them back to the repo.

⚡ Requirements

You will need to add json-summary to coverage reporters in jest config:

module.exports = {
   coverageReporters: ["json-summary"];
};

You also need to run jest before calling this action in your ci workflow. See usage for an example.

⚡ Inputs

🔶 branches

Branches on which the badges should be generated, separated by commas.

Default value: master

🔶 coverage-summary-path

Jest coverage summary path (json-summary). Defining this may be useful if you need to run this action on a monorepo.

Default value: ./coverage/coverage-summary.json

⚡ Usage

Let's first define an npm script to run jest in package.json, specifying the coverage option to generate a coverage report:

{
  "scripts": {
    "test:ci": "jest --ci --coverage"
  }
}

Let's then define our workflow:

name: My ci things
on: [push]
jobs:
  bump:
    runs-on: ubuntu-latest
    steps:
    # Necessary to push the generated badges to the repo
    - name: Check out repository code
      uses: actions/checkout@v2
    # Necessary to generate the coverage report.
    # Make sure to add 'json-summary' to the coverageReporters in jest options
    - name: Tests
      run: yarn test:ci
    [...]
    - name: Generating coverage badges
      uses: jpb06/jest-badges-action@latest
        with:
          branches: master,preprod,staging

The badges will be generated when the action runs on the master, preprod or staging branch.

🔶 Using a custom jest coverage summary file path

In case you need to define a custom path for the coverage summary file, you can use the coverage-summary-path input like so:

    [...]
    - name: Generating coverage badges
      uses: jpb06/jest-badges-action@latest
        with:
          coverage-summary-path: ./my-module/coverage/coverage-summary.json

About

Github action generating coverage badges using jest and pushing them to the repo

Resources

Stars

Watchers

Forks

Packages

No packages published

Languages

  • TypeScript 96.1%
  • JavaScript 3.9%