Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Track your code coverage in every pull request.

License

NotificationsYou must be signed in to change notification settings

ArtiomTr/jest-coverage-report-action

Use this GitHub action with your project
Add this Action to an existing workflow or create a new one
View on Marketplace

Repository files navigation

PR Comment example

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

MIT LicenseIssues

This action usesJest to extract code coverage, and comments it on pull request. Inspired bySize-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 allnew covered files. 🆕
  • Showing spoiler in the comment for all files, in whichcoverage was reduced. 🔻
  • Failed tests & uncovered lineannotations 📢

PR Comment example

Usage

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

Minimal configuration

name:'coverage'on:pull_request:branches:            -master            -mainjobs:coverage:runs-on:ubuntu-lateststeps:            -uses:actions/checkout@v3            -uses:ArtiomTr/jest-coverage-report-action@v2
  1. Pay attention to the action parameters. You can specify customthreshold ortest script
  2. That's it!

Forks with no write permission

If you're seeing this error in your action's console:

HttpError: Resource not accessible by integration    at /home/runner/work/_actions/ArtiomTr/jest-coverage-report-action/v2/dist/index.js:8:323774    at processTicsAndRejections (node:internal/process/task_queues:96:5)    at async /home/runner/work/_actions/ArtiomTr/jest-coverage-report-action/v2/dist/index.js:64:2535    at async Ie (/home/runner/work/_actions/ArtiomTr/jest-coverage-report-action/v2/dist/index.js:63:156)    at async S_ (/home/runner/work/_actions/ArtiomTr/jest-coverage-report-action/v2/dist/index.js:64:2294)

It means that action is running with low privileges. By default,pull_request event doesn't have any write permissions, when PR is coming from fork. To fix that, change trigger action topull_request_target:

name:'coverage'on:pull_request_target:branches:            -master            -mainjobs:coverage:runs-on:ubuntu-lateststeps:            -uses:actions/checkout@v3            -uses:ArtiomTr/jest-coverage-report-action@v2

Warning

This brings worse DX - you can test action only when it is merged into your main branch.Any changes to the workflow file will be taken only after merging them to the main branch

Custom token

By default, this action takesgithub.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'scoverageThreshold property.Just add into yourjest.config.js file:

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

Custom working directory

If you want to run this action in custom directory, specifyworking-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 themautomatically. 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 yourpackage.json:

with:test-script:npm test

Usage withyarnpnpm, orbun

By default, this action will install your dependencies usingnpm. If you are usingyarn,pnpm, orbun, you can specify it in thepackage-manager option:

with:package-manager:yarn

or

with:package-manager:pnpm

or

with:package-manager:bun

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.jsonbase-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 toreport.json file. Then, specify these options for the action:

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

Skipping steps

Note: this option affects only coverage for the "head" branch. For skipping steps of "base" branch, seebase-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 theskip-step option.

with:skip-step:all

Accepted values are:

  • none (default) - all steps will be run
  • install - skip installing dependencies
  • all - skip installing dependenciesand 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

Outputs

By default, action attaches comment to a pull request or commit. However, if you want to use other action for publishing report, you can specifyoutput: report-markdown:

-uses:ArtiomTr/jest-coverage-report-action@v2# give the id for the step, to access outputs in another step.id:coveragewith:# tell to the action to not attach comment.output:report-markdown-uses:marocchino/sticky-pull-request-comment@v2with:# pass output from the previous step by id.message:${{ steps.coverage.outputs.report }}

Also, you can use this data on other platforms. For instance, you can send report to yourSlack orJira.

Note: Working examples of integrations with different platforms are much appreciated! Feel free to open aPR.

Available options are:

  • comment - Attach comment to PR or commit, depending on event type, which triggered an action.
  • report-markdown - Generate output "report", with report contents in markdown format.

Also, you can combine these options:

with:# This will attach comment to a PR and generate markdown output.output:comment, report-markdown

Pull Request Number

If you are using thepush 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 theprnumber 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, thejwalton/gh-find-current-pr action makes it easy:

name:'coverage'on:push:branches:            -master            -mainjobs:coverage:permissions:checks:writepull-requests:writecontents:writeruns-on:ubuntu-lateststeps:            -uses:actions/checkout@v1            -uses:jwalton/gh-find-current-pr@v1id:findPr            -uses:ArtiomTr/jest-coverage-report-action@v2with:prnumber:${{ steps.findPr.outputs.number }}

Customizing report title

If you're running this action multiple times (for instance, when dealing with monorepos), you'll need to distinguish reports from different runs. To do so, you can use thecustom-title property:

with:custom-title:Coverage report for backend

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
Artiom Tretjakovas

💻📖👀🚧🖋
Guilherme Taschetto
Guilherme Taschetto

💻📖
Adam Tuttle
Adam Tuttle

💻
dadayama
dadayama

💻
bluelovers
bluelovers

📖
gdelahodde-masteos
gdelahodde-masteos

💻📖
jlim9333
jlim9333

💻
Jeremy Gillick
Jeremy Gillick

💻📖
Matej Zajo Kralik
Matej Zajo Kralik

💻
Sidharth Vinod
Sidharth Vinod

💻
Jaylen Wimbish
Jaylen Wimbish

📖
princeIta
princeIta

📖
Brian Whitton
Brian Whitton

💻🐛
Bohdan Petryshyn
Bohdan Petryshyn

💻
Herbert Treis Neto
Herbert Treis Neto

💻
Thomas Patrick Levy
Thomas Patrick Levy

💻
Lauris Mikāls
Lauris Mikāls

💻
Rena Hamada
Rena Hamada

📖
JacobLinCool
JacobLinCool

💻📖
Tommaso Ferrari
Tommaso Ferrari

💻
Florian
Florian

💻
Hirotaka Miyagi
Hirotaka Miyagi

💻
Armando Faz
Armando Faz

💻
Maciej Tutak
Maciej Tutak

💻
Niko Oshinov
Niko Oshinov

📖
Dale Fenton
Dale Fenton

📖💻
Florent Jaby
Florent Jaby

💻
vikasperi
vikasperi

💻
Chow Loong Jin
Chow Loong Jin

🐛💻
Anton Joy
Anton Joy

💻
Danny Lan
Danny Lan

💻
Brian Cooper
Brian Cooper

💻
syossan27
syossan27

💻

License

MIT ©Artiom Tretjakovas

Sponsor this project

 

Contributors46

Languages


[8]ページ先頭

©2009-2025 Movatter.jp