Skip to content

Commit 3d6c27b

Browse files
author
Dias, Diego
committed
Use MishaKav/jest-coverage-comment for proper coverage reporting
- Replace custom parsing with maintained jest-coverage-comment action - Displays coverage badge, summary table, and file-by-file coverage - Shows in both PR comments and GitHub Actions summary - More reliable than manual JSON parsing
1 parent b456bfa commit 3d6c27b

File tree

1 file changed

+7
-31
lines changed

1 file changed

+7
-31
lines changed

β€Ž.github/workflows/test-coverage.ymlβ€Ž

Lines changed: 7 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -38,35 +38,11 @@ jobs:
3838
name: coverage-report
3939
path: coverage/jest-tests/
4040

41-
- name: Coverage Summary
41+
- name: Jest Coverage Comment
42+
uses: MishaKav/jest-coverage-comment@main
4243
if: always()
43-
run: |
44-
echo "## πŸ“Š Jest Coverage Summary" >> $GITHUB_STEP_SUMMARY
45-
echo "" >> $GITHUB_STEP_SUMMARY
46-
47-
if [ -f coverage/jest-tests/coverage-summary.json ]; then
48-
# Parse and display coverage metrics
49-
echo "| Metric | Coverage | Threshold | Status |" >> $GITHUB_STEP_SUMMARY
50-
echo "|--------|----------|-----------|--------|" >> $GITHUB_STEP_SUMMARY
51-
52-
# Extract coverage percentages using grep and basic parsing
53-
total_lines=$(cat coverage/jest-tests/coverage-summary.json | grep -o '"lines":{"total":[0-9]*,"covered":[0-9]*,"skipped":[0-9]*,"pct":[0-9.]*' | grep -o 'pct":[0-9.]*' | cut -d':' -f2)
54-
total_statements=$(cat coverage/jest-tests/coverage-summary.json | grep -o '"statements":{"total":[0-9]*,"covered":[0-9]*,"skipped":[0-9]*,"pct":[0-9.]*' | grep -o 'pct":[0-9.]*' | cut -d':' -f2)
55-
total_functions=$(cat coverage/jest-tests/coverage-summary.json | grep -o '"functions":{"total":[0-9]*,"covered":[0-9]*,"skipped":[0-9]*,"pct":[0-9.]*' | grep -o 'pct":[0-9.]*' | cut -d':' -f2)
56-
total_branches=$(cat coverage/jest-tests/coverage-summary.json | grep -o '"branches":{"total":[0-9]*,"covered":[0-9]*,"skipped":[0-9]*,"pct":[0-9.]*' | grep -o 'pct":[0-9.]*' | cut -d':' -f2)
57-
58-
# Check thresholds and add status
59-
[ $(echo "$total_lines >= 40" | bc -l) -eq 1 ] && lines_status="βœ…" || lines_status="❌"
60-
[ $(echo "$total_statements >= 40" | bc -l) -eq 1 ] && stmt_status="βœ…" || stmt_status="❌"
61-
[ $(echo "$total_functions >= 100" | bc -l) -eq 1 ] && func_status="βœ…" || func_status="❌"
62-
[ $(echo "$total_branches >= 40" | bc -l) -eq 1 ] && branch_status="βœ…" || branch_status="❌"
63-
64-
echo "| Lines | ${total_lines}% | 40% | $lines_status |" >> $GITHUB_STEP_SUMMARY
65-
echo "| Statements | ${total_statements}% | 40% | $stmt_status |" >> $GITHUB_STEP_SUMMARY
66-
echo "| Functions | ${total_functions}% | 100% | $func_status |" >> $GITHUB_STEP_SUMMARY
67-
echo "| Branches | ${total_branches}% | 40% | $branch_status |" >> $GITHUB_STEP_SUMMARY
68-
echo "" >> $GITHUB_STEP_SUMMARY
69-
echo "πŸ“ Download the **coverage-report** artifact to view the detailed HTML coverage report." >> $GITHUB_STEP_SUMMARY
70-
else
71-
echo "⚠️ Coverage summary file not found." >> $GITHUB_STEP_SUMMARY
72-
fi
44+
with:
45+
coverage-summary-path: coverage/jest-tests/coverage-summary.json
46+
title: Jest Coverage Report
47+
badge-title: Coverage
48+
create-new-comment: false

0 commit comments

Comments
Β (0)