Skip to content

Commit b34e2e0

Browse files
enhance Jest configuration and add GitHub Actions workflow for coverage checks
1 parent 5bf6f3d commit b34e2e0

2 files changed

Lines changed: 83 additions & 3 deletions

File tree

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
name: 'Coverage Check'
2+
3+
on:
4+
pull_request:
5+
branches:
6+
- development
7+
- staging
8+
- main
9+
push:
10+
branches:
11+
- development
12+
- staging
13+
- main
14+
15+
jobs:
16+
coverage:
17+
runs-on: ubuntu-latest
18+
permissions:
19+
contents: read
20+
pull-requests: write
21+
checks: write
22+
23+
steps:
24+
- name: Checkout code
25+
uses: actions/checkout@v4
26+
27+
- name: Setup Node.js
28+
uses: actions/setup-node@v4
29+
with:
30+
node-version: '18'
31+
cache: 'npm'
32+
33+
- name: Install dependencies
34+
run: npm ci
35+
36+
- name: Jest Coverage Report
37+
if: github.event_name == 'pull_request'
38+
uses: artiomtr/jest-coverage-report-action@v2
39+
with:
40+
github-token: ${{ secrets.GITHUB_TOKEN }}
41+
test-script: npm test -- --coverage --testMatch="**/test/unit/**/*.spec.ts"
42+
threshold: 95
43+
working-directory: ./
44+
package-manager: npm
45+
annotations: failed-tests
46+
coverage-file: ./coverage/coverage-summary.json
47+
base-coverage-file: ./coverage/coverage-summary.json
48+
skip-step: install
49+
50+
- name: Run unit tests with coverage (for push events)
51+
if: github.event_name == 'push'
52+
run: npm test -- --coverage --testMatch="**/test/unit/**/*.spec.ts" --coverageReporters=json-summary --coverageReporters=text
53+
54+
- name: Verify coverage threshold
55+
run: |
56+
COVERAGE=$(node -pe "
57+
const c = JSON.parse(require('fs').readFileSync('coverage/coverage-summary.json')).total;
58+
const threshold = 95;
59+
const metrics = ['statements', 'branches', 'functions', 'lines'];
60+
const failed = metrics.filter(m => c[m].pct < threshold);
61+
if (failed.length) {
62+
console.log('❌ Coverage below 95%: ' + failed.join(', '));
63+
process.exit(1);
64+
}
65+
console.log('✅ All coverage metrics meet the 95% threshold');
66+
")
67+
68+
- name: Upload coverage reports
69+
if: always()
70+
uses: actions/upload-artifact@v3
71+
with:
72+
name: coverage-report
73+
path: |
74+
coverage/
75+
reports/
76+
retention-days: 30
77+

jest.config.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,12 @@ export default {
1515
coverageDirectory: "./reports/contentstack-delivery/coverage/",
1616
collectCoverageFrom: ["src/**", "!src/index.ts"],
1717
coverageThreshold: {
18-
// global: {
19-
// branches: 95,
20-
// }
18+
global: {
19+
statements: 95,
20+
branches: 95,
21+
functions: 95,
22+
lines: 95,
23+
}
2124
},
2225
reporters: [
2326
"default",

0 commit comments

Comments
 (0)