https://github.com/jgillick/test-coverage-annotations
A github action that add test coverage annotations to your files.
https://github.com/jgillick/test-coverage-annotations
annotations istanbul jest test-coverage unit-testing
Last synced: 3 months ago
JSON representation
A github action that add test coverage annotations to your files.
- Host: GitHub
- URL: https://github.com/jgillick/test-coverage-annotations
- Owner: jgillick
- License: mit
- Created: 2022-11-18T23:15:26.000Z (over 3 years ago)
- Default Branch: main
- Last Pushed: 2022-12-05T22:23:46.000Z (over 3 years ago)
- Last Synced: 2025-09-13T01:19:43.605Z (7 months ago)
- Topics: annotations, istanbul, jest, test-coverage, unit-testing
- Language: TypeScript
- Homepage:
- Size: 306 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Test Coverage Annotations - Github Action
[](https://github.com/search?q=jgillick%2Ftest-coverage-annotations+path%3A.github%2Fworkflows+language%3AYAML&type=code)
A github action that add test coverage annotations to your files using an [istanbul-style coverage JSON file](https://github.com/gotwarlost/istanbul/blob/master/coverage.json.md) (jest compatible).

Requires the following permission:
- `checks: write`
```yaml
- name: Coverage annotations
uses: jgillick/test-coverage-annotations@v1
with:
access-token: ${{ secrets.GITHUB_TOKEN }}
coverage: ./coverage/coverage-final.json
only-changed-files: true
```
## Input parameters
- `access-token`: Your github access token. Needed to add annotations.
- `coverage`: Path to the test coverage JSON file.
- `coverage-working-directory`: The path of the directory that the coverage was generated in. Defaults to pwd of the run. (see below for more details)
- `only-changed-files`: Only annotate changed files in the PR.
## Full Example
Assuming you use jest, here's how you can use this action:
```yaml
jobs:
test:
runs-on: ubuntu-latest
permissions:
checks: write
steps:
# First generate coverage
- name: Get coverage
run: yarn jest --coverage
# Generate annotations
- name: Coverage annotations
uses: jgillick/test-coverage-annotations@v1
with:
access-token: ${{ secrets.GITHUB_TOKEN }}
coverage: coverage/coverage-final.json
only-changed-files: true
```
## Coverage Working Directory
**This is important.** The coverage JSON file will contain the _full path_ to each file in the report. This includes a path before your repository. For example: `/home/app/my_repo/file/test.ts`.
In order to apply annotations to files correctly, we only need the path starting at the repo directory and need to strip the prefix `/home/app/my_repo/`.
By default, this action will use the current working directory of the run.