Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/ArtiomTr/jest-coverage-report-action
Track your code coverage in every pull request.
https://github.com/ArtiomTr/jest-coverage-report-action
action actions annotations coverage-reporters github-action github-actions github-actions-ci jest threshold
Last synced: 29 days ago
JSON representation
Track your code coverage in every pull request.
- Host: GitHub
- URL: https://github.com/ArtiomTr/jest-coverage-report-action
- Owner: ArtiomTr
- License: mit
- Created: 2021-01-10T10:41:26.000Z (almost 4 years ago)
- Default Branch: main
- Last Pushed: 2024-09-09T19:15:44.000Z (3 months ago)
- Last Synced: 2024-11-08T02:32:48.940Z (about 1 month ago)
- Topics: action, actions, annotations, coverage-reporters, github-action, github-actions, github-actions-ci, jest, threshold
- Language: TypeScript
- Homepage: https://www.covbot.dev
- Size: 14.7 MB
- Stars: 494
- Watchers: 3
- Forks: 143
- Open Issues: 41
-
Metadata Files:
- Readme: README.md
- Funding: .github/FUNDING.yml
- License: LICENSE
- Code of conduct: CODE_OF_CONDUCT.md
- Security: SECURITY.md
Awesome Lists containing this project
- awesome - ArtiomTr/jest-coverage-report-action - Track your code coverage in every pull request. (TypeScript)
README
# jest coverage report ๐งช
A GitHub action that reports about your code coverage in every pull request.This action uses [Jest](https://github.com/facebook/jest) to extract code coverage, and comments it on pull request. Inspired by [Size-limit action](https://github.com/andresz1/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** ๐ข
## Usage
1. Install and configure [Jest](https://github.com/facebook/jest).
2. Create new action inside `.github/workflows`:**Minimal configuration**
```yml
name: 'coverage'
on:
pull_request:
branches:
- master
- main
jobs:
coverage:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: ArtiomTr/jest-coverage-report-action@v2
```3. Pay attention to the action parameters. You can specify custom [threshold](#specify-threshold) or [test script](#customizing-test-script)
4. 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 to `pull_request_target`:
```yml
name: 'coverage'
on:
pull_request_target:
branches:
- master
- main
jobs:
coverage:
runs-on: ubuntu-latest
steps:
- 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 takes `github.token` variable to publish reports on your PR. You can overwrite this property by specifying:
```yml
with:
github-token: ${{ secrets.SECRET_TOKEN }}
```## Specify threshold
This action automatically suports jest's [`coverageThreshold`](https://jestjs.io/docs/configuration#coveragethreshold-object) property.
Just add into your `jest.config.js` file:```js
module.exports = {
coverageThreshold: {
global: {
lines: 80,
},
},
};
```## Custom working directory
If you want to run this action in custom directory, specify `working-directory`:
```yml
with:
working-directory:
```## 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:
```yml
with:
test-script: yarn jest
```Or, if you would like to run a script from your `package.json`:
```yml
with:
test-script: npm test
```## Usage with `yarn` `pnpm`, or `bun`
By default, this action will install your dependencies using `npm`. If you are using `yarn`, `pnpm`, or `bun`, you can specify it in the `package-manager` option:
```yml
with:
package-manager: yarn
```or
```yml
with:
package-manager: pnpm
```or
```yml
with:
package-manager: bun
```## Use existing test report(s)
To bypass running unit tests, you can pass the filepath to the current report.json
```yml
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:
```yml
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`](#use-existing-test-reports) 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.
```yml
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:
```yml
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 specify `output: report-markdown`:
```yaml
- uses: ArtiomTr/jest-coverage-report-action@v2
# give the id for the step, to access outputs in another step.
id: coverage
with:
# tell to the action to not attach comment.
output: report-markdown
- uses: marocchino/sticky-pull-request-comment@v2
with:
# 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 your [Slack](https://github.com/slackapi/slack-github-action) or [Jira](https://github.com/atlassian/gajira-comment).
> **Note**: Working examples of integrations with different platforms are much appreciated! Feel free to open a [PR](https://github.com/ArtiomTr/jest-coverage-report-action/pulls).
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:
```yml
with:
# This will attach comment to a PR and generate markdown output.
output: comment, report-markdown
```## 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](https://github.com/jwalton/gh-find-current-pr) action makes it easy:
```yml
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 }}
```## 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 the `custom-title` property:
```yaml
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 โจ](https://allcontributors.org/docs/en/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
๐ ๐ป
Florent Jaby
๐ป
vikasperi
๐ป
Chow Loong Jin
๐ ๐ป
Anton Joy
๐ป
Danny Lan
๐ป
Brian Cooper
๐ป
syossan27
๐ป
## License
MIT ยฉ [Artiom Tretjakovas](https://github.com/ArtiomTr)