How can I fail a GitHub job if jest code coverage is not met?
I can see that my GitHub action goes into the success block, even though the code coverage is not met. How can I fail it?
I tried these SO answers, but did not have any luck
jest.ts:
module.exports = {
projects: [
{
displayName: 'unit',
testEnvironment: 'node',
testPathIgnorePatterns: ['.d.ts', '.js'],
roots: ['<rootDir>'],
testMatch: ['<rootDir>/test/unit/**/*.test.ts'],
transform: {
'^.+\\.tsx?$': 'ts-jest',
},
clearMocks: true,
collectCoverageFrom: [
'**/*.ts',
'!test/**/*',
],
coverageThreshold: {
global: {
branches: 95,
functions: 95,
lines: 95,
statements: 95,
},
},
},
...
};
YAML:
jobs:
unit-tests:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v1
- name: Notify job starting...
uses: ...
if: success()
id: slack
with:
channel: git
status: STARTING_UNIT_TESTS
color: warning
- name: Use Node.js 16.x
uses: actions/setup-node@v1
with:
node-version: 16.x
- name: Install & test
run: |
npm ci
npm run test-coverage
- name: Send passing unit test metrics
uses: ...
if: success()
with:
api-key: ...
- name: Send failing unit test metrics
uses: ...
if: failure()
with:
api-key: ...
Output:
...
PASS unit test/unit/xyz.test.ts
----------------------------------------|---------|----------|---------|---------|--------------------------------------
File | % Stmts | % Branch | % Funcs | % Lines | Uncovered Line #s
----------------------------------------|---------|----------|---------|---------|--------------------------------------
All files | 48.7 | 14.03 | 38.68 | 50.08 |
The jest coverage report plugin looks promising, but doesn't seem to support jest projects