1
+ name : Playwright/Vitest Tests
2
+ on :
3
+ workflow_call :
4
+ inputs :
5
+ working-directory :
6
+ type : string
7
+ description : " The working directory for the job, e.g. apps/dolly-frontend (without leading/trailing slash)."
8
+ required : true
9
+ secrets :
10
+ READER_TOKEN :
11
+ required : true
12
+
13
+ jobs :
14
+ playwright-tests :
15
+ timeout-minutes : 15
16
+ runs-on : ubuntu-latest
17
+ strategy :
18
+ fail-fast : false
19
+ matrix :
20
+ shardIndex : [ 1, 2, 3, 4 ]
21
+ shardTotal : [ 4 ]
22
+ env :
23
+ NODE_AUTH_TOKEN : ${{ secrets.READER_TOKEN }}
24
+ steps :
25
+ - uses : actions/checkout@v4
26
+ - uses : actions/setup-node@v4
27
+ with :
28
+ node-version : lts/*
29
+ registry-url : https://npm.pkg.github.com/
30
+ scope : " @navikt"
31
+ - name : Install dependencies
32
+ working-directory : ${{ inputs.working-directory }}/src/main/js
33
+ run : npm ci
34
+ - name : Install Playwright Browsers
35
+ working-directory : ${{ inputs.working-directory }}/src/main/js
36
+ run : npx playwright install --with-deps
37
+ - name : Run Playwright tests
38
+ working-directory : ${{ inputs.working-directory }}/src/main/js
39
+ run : npx playwright test --shard=${{ matrix.shardIndex }}/${{ matrix.shardTotal }}
40
+ - name : Upload blob report to GitHub Actions Artifacts
41
+ if : ${{ !cancelled() }}
42
+ uses : actions/upload-artifact@v4
43
+ with :
44
+ name : blob-report-${{ matrix.shardIndex }}
45
+ path : ${{ inputs.working-directory }}/src/main/js/blob-report
46
+ retention-days : 1
47
+
48
+ - name : Run Vitest/RTL tests
49
+ if : ${{ matrix.shardIndex == 1 }}
50
+ working-directory : ${{ inputs.working-directory }}/src/main/js
51
+ run : npm run test:vitest-run
52
+
53
+ merge-reports :
54
+ if : ${{ !cancelled() }}
55
+ needs : [ playwright-tests ]
56
+ runs-on : ubuntu-latest
57
+ steps :
58
+ - uses : actions/checkout@v4
59
+ - uses : actions/setup-node@v4
60
+ with :
61
+ node-version : 22.x
62
+
63
+ - name : Download blob reports from GitHub Actions Artifacts
64
+ uses : actions/download-artifact@v4
65
+ with :
66
+ path : ${{ inputs.working-directory }}/src/main/js/all-blob-reports
67
+ pattern : blob-report-*
68
+ merge-multiple : true
69
+
70
+ - name : Merge into HTML Report
71
+ working-directory : ${{ inputs.working-directory }}/src/main/js
72
+ run : npx playwright merge-reports --reporter html ./all-blob-reports
73
+
74
+ - name : Upload HTML report
75
+ uses : actions/upload-artifact@v4
76
+ with :
77
+ name : html-report--attempt-${{ github.run_attempt }}
78
+ path : ${{ inputs.working-directory }}/src/main/js/playwright-report
79
+ retention-days : 14
80
+
81
+ - name : Upload HTML report to CDN
82
+ uses : nais/deploy/actions/cdn-upload/v2@master
83
+ with :
84
+ team : dolly
85
+ source : ${{ inputs.working-directory }}/src/main/js/playwright-report
86
+ destination : /${{ github.repository }}/${{ github.run_number }}
87
+ identity_provider : ${{ secrets.NAIS_WORKLOAD_IDENTITY_PROVIDER }}
88
+ # project_id: ${{ vars.NAIS_MANAGEMENT_PROJECT_ID }}
89
+
90
+ - name : Merge to json report
91
+ working-directory : ${{ inputs.working-directory }}/src/main/js
92
+ run : npx playwright merge-reports --reporter json ./all-blob-reports > playwright-report/report.json
93
+
94
+ - name : Make fancy GHA Summary
95
+ working-directory : ${{ inputs.working-directory }}/src/main/js
96
+ run : |
97
+ total_tests=$(jq '.stats.expected + .stats.unexpected' playwright-report/report.json)
98
+ passed_tests=$(jq '.stats.expected' playwright-report/report.json)
99
+ failed_tests=$(jq '.stats.unexpected' playwright-report/report.json)
100
+ failed_test_info=$(jq -r '.suites[].specs[] | select(.ok == false) | "\(.title) (\(.file), \(.tests[].projectName))"' playwright-report/report.json)
101
+ echo "## Playwright Test Report Summary" >> $GITHUB_STEP_SUMMARY
102
+ echo "Total tests: $total_tests ✅" >> $GITHUB_STEP_SUMMARY
103
+ echo "Passed tests: $passed_tests ✅" >> $GITHUB_STEP_SUMMARY
104
+ if [ "$failed_tests" -gt 0 ]; then
105
+ echo "Failed tests: $failed_tests ❌" >> $GITHUB_STEP_SUMMARY
106
+ echo "### Failed Tests:" >> $GITHUB_STEP_SUMMARY
107
+ while IFS= read -r test; do
108
+ echo "- $test ❌" >> $GITHUB_STEP_SUMMARY
109
+ done <<< "$failed_test_info"
110
+ else
111
+ echo "Failed tests: $failed_tests 🔹" >> $GITHUB_STEP_SUMMARY
112
+ fi
113
+ echo "Se hele rapporten [her](https://cdn.nav.no/dolly/${{ github.repository }}/${{ github.run_number }}/playwright-report/index.html)." >> $GITHUB_STEP_SUMMARY
0 commit comments