Giter Club home page Giter Club logo

jest-coverage-report-action's Introduction

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. ๐Ÿ”ป
  • Failed tests & uncovered line annotations ๐Ÿ“ข

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:
        permissions:
            checks: write
            pull-requests: write
            contents: write
        runs-on: ubuntu-latest
        steps:
            - uses: actions/checkout@v1
            - uses: ArtiomTr/jest-coverage-report-action@v2
  1. Pay attention to the action parameters. You can specify custom threshold or test script
  2. That's it!

Custom token

By default, this action takes github.token variable to publish reports on your PR. You can overwrite this property by specifying:

with:
    github-token: ${{ secrets.SECRET_TOKEN }}

Specify threshold

This action automatically suports jest's coverageThreshold property. Just add into your jest.config.js file:

module.exports = {
    coverageThreshold: {
        global: {
            lines: 80,
        },
    },
};

Custom working directory

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

with:
    working-directory: <dir>

Customizing test script

This action automatically adds necessary flags to your test script. The default script is:

npx jest

So you don't need to specify additional flags - action will handle them automatically. So, after adding necessary flags, action will run this command:

npx jest --ci --json --coverage --testLocationInResults --outputFile=report.json

But you do not need to specify these flags manually. Also, you can use different package manager, yarn for example:

with:
    test-script: yarn jest

Or, if you would like to run a script from your package.json:

with:
    test-script: npm test

Usage with yarn or pnpm

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

with:
    package-manager: yarn

or

with:
    package-manager: pnpm

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.

Opt-out coverage comparison features

You can opt-out coverage comparison features to speed-up action. To achieve this, firstly, manually collect coverage to report.json file. Then, specify these options for the action:

with:
    coverage-file: report.json
    base-coverage-file: report.json

Skipping steps

Note: this option affects only coverage for the "head" branch. For skipping steps of "base" branch, see base-coverage-file option.

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:
    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 annotations

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

with:
    annotations: none

Accepted values are:

  • all (default) - Will annotate sections of your code that failed tests or test did not cover
  • none - Turns off annotations
  • coverage - Will annotate those sections of your code that test did not cover. Limited to changed lines when used on a Pull Request
  • failed-tests - Will annotate those sections of your code that failed test

Pull Request Number

If you are using the push event to trigger this action, by default it does not know which PR to comment on or the base branch of the PR to compare code coverage with.

You can pass the prnumber to the action so that coverage change can be run and comments will be updated on each push, instead of creating a new comment with each run of the action.

You can find the PR number with a number of methods, the jwalton/gh-find-current-pr action makes it easy:

name: 'coverage'
on:
    push:
        branches:
            - master
            - main
jobs:
    coverage:
        permissions:
            checks: write
            pull-requests: write
            contents: write
        runs-on: ubuntu-latest
        steps:
            - uses: actions/checkout@v1
            - uses: jwalton/gh-find-current-pr@v1
                id: findPr
            - uses: ArtiomTr/jest-coverage-report-action@v2
                with:
                   prnumber: ${{ steps.findPr.outputs.number }}

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

๐Ÿ’ป

Rena Hamada

๐Ÿ“–

JacobLinCool

๐Ÿ’ป ๐Ÿ“–

Tommaso Ferrari

๐Ÿ’ป

Florian

๐Ÿ’ป

Hirotaka Miyagi

๐Ÿ’ป

Armando Faz

๐Ÿ’ป

Maciej Tutak

๐Ÿ’ป

Niko Oshinov

๐Ÿ“–

Dale Fenton

๐Ÿ“– ๐Ÿ’ป

License

MIT ยฉ Artiom Tretjakovas

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.