runofthemillgeek / jest-coverage-report-action

Track your code coverage in each pull request.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

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
jobs:
    coverage:
        runs-on: ubuntu-latest
        env:
            CI_JOB_NUMBER: 1
        steps:
            - uses: actions/checkout@v1
            - uses: artiomtr/jest-coverage-report-action@v1.2
              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

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.

License

MIT Β© Artiom Tretjakovas

About

Track your code coverage in each pull request.

License:MIT License


Languages

Language:TypeScript 96.2%Language:JavaScript 3.5%Language:Dockerfile 0.3%