Skip to content

kiron/jest-coverage-report-action

Β 
Β 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

jest coverage report πŸ§ͺ

PR Comment example

A GitHub action that reports about your code coverage in every pull request.

MIT License Issues

This action uses Jest to extract code coverage, and comments it on pull request. Inspired by Size-limit action. Features:

  • Reporting code coverage on each pull request. πŸ“ƒ
  • Rejecting pull request, if coverage is under threshold. ❌
  • Comparing coverage with base branch. πŸ”
  • Showing spoiler in the comment for all new covered files. πŸ†•
  • Showing spoiler in the comment for all files, in which coverage was reduced. πŸ”»

PR Comment example

Usage

  1. Install and configure Jest.
  2. Create new action inside .github/workflows:

Minimal configuration

name: 'coverage'
on:
    pull_request:
        branches:
            - master
            - main
jobs:
    coverage:
        runs-on: ubuntu-latest
        if: "!contains(github.event.head_commit.message, '[skip ci]')"
        steps:
            - uses: actions/checkout@v1
            - uses: artiomtr/[email protected]
              with:
                  github-token: ${{ secrets.GITHUB_TOKEN }}
                  #   threshold: 80 # optional parameter
  1. Pay attention to the action parameters. You can specify custom threshold or test script
  2. That's it!

Specify threshold

If you want to set minimal accepted coverage for the PR, you can pass and optional parameter threshold.

For example, if you want to reject every pull request, with total line coverage less than 80%:

with:
    github-token: ${{ secrets.GITHUB_TOKEN }}
    threshold: 80 # value in percents

Custom working directory

If you want to run this action in custom directory, specify working-directory:

with:
    github-token: ${{ secrets.GITHUB_TOKEN }}
    working-directory: <dir>

Customizing test script

By default, this action will run this command, to extract coverage:

npx jest --silent --ci --coverage --coverageReporters="text" --coverageReporters="text-summary"

If you're not satisfied with default behaviour, you can specify your own command, by passing custom option test-script.

⚠ IMPORTANT ⚠: Please, note that this is not simple npx jest --coverage script call. If you're specify your custom script, YOU SHOULD PASS SAME COVERAGE REPORTERS as it does default script (text and text-summary reporters). Without those options, your action will not work.

For instance, if you want to run test:coverage npm script:

with:
    github-token: ${{ secrets.GITHUB_TOKEN }}
    test-script: npm run test:coverage

Usage with yarn

By default, this action will install your dependencies using npm. If you are using yarn, you can specify it in the package-manager option:

with:
    github-token: ${{ secrets.GITHUB_TOKEN }}
    package-manager: yarn

Use existing test report(s)

To bypass running unit tests, you can pass the filepath to the current report.json

with:
    coverage-file: ./coverage/report.json
    base-coverage-file: ./coverage/master/report.json
  • coverage-file is the filepath to the JSON coverage report for the current pull request.
  • base-coverage-file is the filepath to the JSON coverage report from the branch your pull request is merging into.

For example, you can save every test run to an artifact and then download and reference them here.

Skipping steps

By default, this action will install dependencies and run the tests for you, generating the coverage report. Alternatively, you can skip these steps using the skip-step option.

with:
    github-token: ${{ secrets.GITHUB_TOKEN }}
    skip-step: all

Accepted values are:

  • none (default) - all steps will be run
  • install - skip installing dependencies
  • all - skip installing dependencies and running the test script

Change annotaions

To change annotaions, you have to set the annotaions option as shown below:

with:
    github-token: ${{ secrets.GITHUB_TOKEN }}
    annotations: none

Accepted values are:

  • all (default) - Will annotate sections of your code that failed tests or test did not cover
  • none - Turns off annotaions
  • coverage - Will annotate those sections of your code that test did not cover
  • failed-tests - Will annotate those sections of your code that failed test

Contributing

Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.

Please make sure to update tests as appropriate.

Jest Coverage Report action is made with <3 thanks to these wonderful people (emoji key ✨):


Artiom Tretjakovas

πŸ’» πŸ“– πŸ‘€ 🚧 πŸ–‹

Guilherme Taschetto

πŸ’» πŸ“–

Adam Tuttle

πŸ’»

dadayama

πŸ’»

bluelovers

πŸ“–

gdelahodde-masteos

πŸ’» πŸ“–

jlim9333

πŸ’»

Jeremy Gillick

πŸ’» πŸ“–

Matej Zajo Kralik

πŸ’»

Sidharth Vinod

πŸ’»

Jaylen Wimbish

πŸ“–

princeIta

πŸ“–

Brian Whitton

πŸ’» πŸ›

Bohdan Petryshyn

πŸ’»

Herbert Treis Neto

πŸ’»

Thomas Patrick Levy

πŸ’»

Lauris Mikāls

πŸ’»

License

MIT Β© Artiom Tretjakovas

About

Track your code coverage in every pull request.

Resources

License

Code of conduct

Security policy

Stars

Watchers

Forks

Packages

No packages published

Languages

  • TypeScript 99.3%
  • Other 0.7%