Coverage reporter for pull requests with support for Monorepos.
Run this CLI in CI, to compare current coverage against the base branch, and report the results in the Github PR.
-cp --coverage-path <path> path to coverage json file
-mp --monorepo-path <path> Only for monorepos. Path from the repo root (default: "")
-gt --github-token <value> personal access token for github (default: GITHUB_TOKEN)
-o --owner <value> owner or org for the repo (default: DRONE_REPO_OWNER) (default: "@getyourguide")
-r --repo <value> name of the github repo (default: DRONE_REPO_NAME)
-b --branch <value> current branch (default: DRONE_BRANCH)
-c --commit <value> sha of the current commit (default: DRONE_COMMIT_SHA)
-bb --base-branch <value> base branches from where coverage should be upload (default: ["master","main"])
-bp --base-path <value> absolute path to look for files
-h, --help display help for command
In order to use it, you need to setup your test runner to report coverage and produce a json-summary
.
Please check the docs of your test runner.
// jest.config.js
{
collectCoverage: true,
collectCoverageFrom: ["**/*.{ts,vue}"],
coverageReporters: ["json-summary"],
}
To verify, run the tests, and it should generate: ./coverage/coverage-summary.json
To simplify the usage, we created a CoverageGuard GithubAction.
Example PR monorepo
- name: Coverage Guard
uses: getyourguide/actions/coverage-guard@main
env:
CODEARTIFACT_AUTH_TOKEN: ${{ secrets.CODEARTIFACT_AUTH_TOKEN }}
GITHUB_TOKEN: ${{ secrets.COVERAGE_GUARD_GITHUB_ACCESS_TOKEN }}
DD_API_KEY: ${{ secrets.DATADOG_API_KEY }}
with:
options: "-cp ./apps/my-app/coverage/coverage-summary.json -mp apps/my-app"
To simplify the usage, we created a CoverageGuard Drone plugin.
coverage-guard:
image: 130607246975.dkr.ecr.eu-central-1.amazonaws.com/drone-plugins/coverage-guard:latest
secrets: [codeartifact_auth_token, github_token, dd_site, dd_api_key]
# Pass any parameter valid for the npm package
# Check options from above
options: -cp ./coverage/coverage-summary.json -mp apps/my-app
when:
event: push
- Install dependency:
pnpm add @getyourguide/coverage-guard --save-dev
- Create a script in your
package.json
with the path to the coverage summary
{
"scripts": {
"test:ci": "jest --coverage --coverageReporters=json-summary",
"coverage": "coverage-guard -cp ./coverage/coverage-summary.json -mp apps/my-app"
}
}
- Add a step to run the command in CI. This step should run after
test:ci
coverage-guard:
- pnpm coverage
Happy testing! ❤️