-
Notifications
You must be signed in to change notification settings - Fork 78
70 lines (60 loc) · 1.86 KB
/
frontend-test.yml
File metadata and controls
70 lines (60 loc) · 1.86 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
name: frontend-tests-and-coverage
on:
push:
branches:
- "main"
pull_request:
branches:
- "main"
- "dev"
jobs:
test-and-coverage:
runs-on: ubuntu-latest
permissions:
# pull-requests: write # to add comments to the PRs
contents: read
steps:
- uses: actions/checkout@v4
- name: Setup Node.js
uses: actions/setup-node@v3
with:
node-version: "20.x"
- name: Install dependencies
run: npm ci
working-directory: frontend
# 1. RUN ONLY TESTS ON PUSH
- name: Run frontend tests
if: github.event_name == 'push'
run: npm test
working-directory: frontend
# 2. RUN COVERAGE ON PRs
- name: Run jest with coverage
if: github.event_name == 'pull_request'
run: npx jest --coverage --coverageReporters=cobertura
working-directory: frontend
# # 3. POST COMMENT ON PR
# - name: Jest Coverage Comment
# if: >
# github.event_name == 'pull_request'
# uses: MishaKav/jest-coverage-comment@main
# with:
# coverage-summary-path: ./frontend/coverage/coverage-summary.json
# title: Frontend Coverage Report
# 3. WRITE COVERAGE SUMMARY TO CHECKS
- name: Write Summary from File
if: github.event_name == 'pull_request'
uses: irongut/CodeCoverageSummary@v1.3.0
with:
filename: frontend/coverage/cobertura-coverage.xml
badge: true
format: markdown
output: both
# 4. PUSH TO SUMMARY PAGE
- name: Write to Job Summary
if: github.event_name == 'pull_request'
run: |
if [ -f "code-coverage-results.md" ]; then
cat code-coverage-results.md >> $GITHUB_STEP_SUMMARY
else
echo "Coverage file not found"
fi