|
38 | 38 | run: npm ci |
39 | 39 |
|
40 | 40 | - name: Run tests with coverage |
41 | | - run: npm run test:coverage |
| 41 | + run: | |
| 42 | + npm run test:coverage 2>&1 | tee test-output.log |
| 43 | + echo "TEST_EXIT_CODE=${PIPESTATUS[0]}" >> $GITHUB_ENV |
| 44 | +
|
| 45 | + - name: Parse test results |
| 46 | + if: always() |
| 47 | + id: test-results |
| 48 | + run: | |
| 49 | + # Extract test results from web-test-runner output |
| 50 | + # Format: "Chrome: |████| 7/7 test files | 182 passed, 0 failed" |
| 51 | + if grep -q "passed" test-output.log; then |
| 52 | + PASSED=$(grep -oP '\d+ passed' test-output.log | tail -1 | grep -oP '\d+' || echo "0") |
| 53 | + FAILED=$(grep -oP '\d+ failed' test-output.log | tail -1 | grep -oP '\d+' || echo "0") |
| 54 | + TOTAL=$((PASSED + FAILED)) |
| 55 | +
|
| 56 | + echo "passed=$PASSED" >> $GITHUB_OUTPUT |
| 57 | + echo "failed=$FAILED" >> $GITHUB_OUTPUT |
| 58 | + echo "total=$TOTAL" >> $GITHUB_OUTPUT |
| 59 | + else |
| 60 | + echo "passed=0" >> $GITHUB_OUTPUT |
| 61 | + echo "failed=0" >> $GITHUB_OUTPUT |
| 62 | + echo "total=0" >> $GITHUB_OUTPUT |
| 63 | + fi |
| 64 | +
|
| 65 | + - name: Generate test summary |
| 66 | + if: always() |
| 67 | + run: | |
| 68 | + echo "### Test Results 📊" >> $GITHUB_STEP_SUMMARY |
| 69 | + echo "" >> $GITHUB_STEP_SUMMARY |
| 70 | +
|
| 71 | + PASSED="${{ steps.test-results.outputs.passed }}" |
| 72 | + FAILED="${{ steps.test-results.outputs.failed }}" |
| 73 | + TOTAL="${{ steps.test-results.outputs.total }}" |
| 74 | +
|
| 75 | + if [ "$FAILED" = "0" ] && [ "$TOTAL" != "0" ]; then |
| 76 | + echo "✅ **All tests passed!**" >> $GITHUB_STEP_SUMMARY |
| 77 | + elif [ "$TOTAL" = "0" ]; then |
| 78 | + echo "⚠️ **Could not parse test results**" >> $GITHUB_STEP_SUMMARY |
| 79 | + else |
| 80 | + echo "❌ **Some tests failed**" >> $GITHUB_STEP_SUMMARY |
| 81 | + fi |
| 82 | +
|
| 83 | + echo "" >> $GITHUB_STEP_SUMMARY |
| 84 | + echo "| Metric | Count |" >> $GITHUB_STEP_SUMMARY |
| 85 | + echo "|--------|-------|" >> $GITHUB_STEP_SUMMARY |
| 86 | + echo "| Total Tests | $TOTAL |" >> $GITHUB_STEP_SUMMARY |
| 87 | + echo "| Passed | $PASSED |" >> $GITHUB_STEP_SUMMARY |
| 88 | + echo "| Failed | $FAILED |" >> $GITHUB_STEP_SUMMARY |
| 89 | +
|
| 90 | + exit $TEST_EXIT_CODE |
| 91 | +
|
| 92 | + - name: Create test results check |
| 93 | + if: always() && github.event_name == 'pull_request' |
| 94 | + uses: actions/github-script@v7 |
| 95 | + with: |
| 96 | + script: | |
| 97 | + const passed = '${{ steps.test-results.outputs.passed }}'; |
| 98 | + const failed = '${{ steps.test-results.outputs.failed }}'; |
| 99 | + const total = '${{ steps.test-results.outputs.total }}'; |
| 100 | +
|
| 101 | + const conclusion = failed === '0' && total !== '0' ? 'success' : (total === '0' ? 'neutral' : 'failure'); |
| 102 | + const summary = `${total} tests run, ${passed} passed, ${failed} failed`; |
| 103 | +
|
| 104 | + await github.rest.checks.create({ |
| 105 | + owner: context.repo.owner, |
| 106 | + repo: context.repo.repo, |
| 107 | + name: 'Test Results', |
| 108 | + head_sha: context.payload.pull_request.head.sha, |
| 109 | + status: 'completed', |
| 110 | + conclusion: conclusion, |
| 111 | + output: { |
| 112 | + title: summary, |
| 113 | + summary: summary, |
| 114 | + text: `**Test Execution Summary**\n\n- Total: ${total}\n- Passed: ${passed} ✅\n- Failed: ${failed} ${failed === '0' ? '✅' : '❌'}` |
| 115 | + } |
| 116 | + }); |
42 | 117 |
|
43 | 118 | - name: Upload coverage to Codecov |
44 | 119 | uses: codecov/codecov-action@v4 |
|
0 commit comments