Skip to content

Commit

Permalink
Add test coverage report to README.md and Github actions (#152)
Browse files Browse the repository at this point in the history
* Add coverage report to GitHub workflows.
* docs: Update README.md to describe generating and using coverage report.
* Configure initial coverage threshold
  • Loading branch information
marinojoey authored Aug 31, 2023
1 parent 4816bd0 commit 492d026
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 2 deletions.
11 changes: 11 additions & 0 deletions .github/workflows/code-coverage.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
name: "coverage"
on:
pull_request_target:
branches:
- develop
jobs:
coverage:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: ArtiomTr/jest-coverage-report-action@v2
2 changes: 1 addition & 1 deletion .husky/pre-commit
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#!/bin/sh
. "$(dirname "$0")/_/husky.sh"
yarn lint
yarn test
yarn test --coverage
yarn build
14 changes: 14 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,20 @@ yarn install
yarn test
```

#### Generating Test Coverage Report

To generate a test coverage report using Jest run the following command in your terminal:

```sh
npx jest --coverage
```

If you're using macOS, you can directly access the coverage report in your browser by opening the following URL:

```
file:///Users/<userName>/sandbag/coverage/lcov-report/index.html
```

#### How to publish a new release to NPM
Submit a PR with commit message `[npm publish]`

Expand Down
10 changes: 9 additions & 1 deletion jest.config.cjs
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
/** @type {import('ts-jest/dist/types').InitialOptionsTsJest} */
module.exports = {
preset: 'ts-jest',
testEnvironment: 'node'
testEnvironment: 'node',
coverageThreshold: {
global: {
branches: 20,
functions: 20,
lines: 20,
statements: -999999 // Exceptionally high allowance for uncovered statements to start
}
}
}

0 comments on commit 492d026

Please sign in to comment.