Skip to content

Commit

Permalink
More tests
Browse files Browse the repository at this point in the history
  • Loading branch information
vpetersson committed Dec 7, 2024
1 parent 18e82be commit b040f48
Showing 1 changed file with 24 additions and 38 deletions.
62 changes: 24 additions & 38 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,27 +22,30 @@ jobs:
- name: Install dependencies
run: |
sudo apt-get update
sudo apt-get install -y libgbm-dev
sudo apt-get install -y libgbm-dev jq
npm ci
- name: Run tests with coverage
run: |
npm test
# Run tests and capture JSON output
npm test -- --json > test-results.json || true
# Extract coverage from JSON and format for summary
echo "# Test Results (Node ${{ matrix.node-version }})" >> $GITHUB_STEP_SUMMARY
echo "## Coverage" >> $GITHUB_STEP_SUMMARY
echo "| Type | Coverage | Details |" >> $GITHUB_STEP_SUMMARY
echo "|------|----------|----------|" >> $GITHUB_STEP_SUMMARY
statements_pct=$(cat coverage/lcov-report/index.html | grep -A 1 "statements" | tail -n 1 | sed -E 's/.*>([0-9.]+)%.*/\1/')
statements_frac=$(cat coverage/lcov-report/index.html | grep -A 1 "statements" | tail -n 1 | sed -E 's/.*\(([0-9]+\/[0-9]+)\).*/\1/')
branches_pct=$(cat coverage/lcov-report/index.html | grep -A 1 "branches" | tail -n 1 | sed -E 's/.*>([0-9.]+)%.*/\1/')
branches_frac=$(cat coverage/lcov-report/index.html | grep -A 1 "branches" | tail -n 1 | sed -E 's/.*\(([0-9]+\/[0-9]+)\).*/\1/')
functions_pct=$(cat coverage/lcov-report/index.html | grep -A 1 "functions" | tail -n 1 | sed -E 's/.*>([0-9.]+)%.*/\1/')
functions_frac=$(cat coverage/lcov-report/index.html | grep -A 1 "functions" | tail -n 1 | sed -E 's/.*\(([0-9]+\/[0-9]+)\).*/\1/')
lines_pct=$(cat coverage/lcov-report/index.html | grep -A 1 "lines" | tail -n 1 | sed -E 's/.*>([0-9.]+)%.*/\1/')
lines_frac=$(cat coverage/lcov-report/index.html | grep -A 1 "lines" | tail -n 1 | sed -E 's/.*\(([0-9]+\/[0-9]+)\).*/\1/')
echo "| Statements | ${statements_pct}% | ${statements_frac} |" >> $GITHUB_STEP_SUMMARY
echo "| Branches | ${branches_pct}% | ${branches_frac} |" >> $GITHUB_STEP_SUMMARY
echo "| Functions | ${functions_pct}% | ${functions_frac} |" >> $GITHUB_STEP_SUMMARY
echo "| Lines | ${lines_pct}% | ${lines_frac} |" >> $GITHUB_STEP_SUMMARY
# Use jq to parse the JSON and format the table
if jq -e '.coverageMap' test-results.json > /dev/null 2>&1; then
jq -r '.coverageMap |
to_entries[] |
select(.key == "total") |
.value |
"| Statements | \(.statements.pct | floor)% | \(.statements.covered)/\(.statements.total) |\n| Branches | \(.branches.pct | floor)% | \(.branches.covered)/\(.branches.total) |\n| Functions | \(.functions.pct | floor)% | \(.functions.covered)/\(.functions.total) |\n| Lines | \(.lines.pct | floor)% | \(.lines.covered)/\(.lines.total) |"' test-results.json >> $GITHUB_STEP_SUMMARY
else
echo "⚠️ Could not parse coverage data from test results" >> $GITHUB_STEP_SUMMARY
cat test-results.json >> $GITHUB_STEP_SUMMARY
fi
- name: Upload coverage report
uses: actions/upload-artifact@v4
with:
Expand All @@ -52,6 +55,7 @@ jobs:
run: xvfb-run --auto-servernum --server-args="-screen 0 1280x800x24" npm run test:visual:ci -- -u
- name: Upload visual test artifacts
if: always()
id: upload-artifacts
uses: actions/upload-artifact@v4
with:
name: visual-test-artifacts
Expand All @@ -60,46 +64,28 @@ jobs:
__image_snapshots__/__diff_output__
- name: Generate visual test summary
if: always()
env:
ARTIFACT_URL: ${{ steps.upload-artifacts.outputs.artifact-url }}
run: |
echo "## Visual Test Results" >> $GITHUB_STEP_SUMMARY
echo "### Upload Asset Form" >> $GITHUB_STEP_SUMMARY
echo '<details><summary>View Screenshot</summary>' >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo "\`\`\`html" >> $GITHUB_STEP_SUMMARY
echo "<img src='data:image/png;base64,$(base64 -w 0 __image_snapshots__/ci-Upload-Asset-Form-1-snap.png)'>" >> $GITHUB_STEP_SUMMARY
echo "\`\`\`" >> $GITHUB_STEP_SUMMARY
echo "</details>" >> $GITHUB_STEP_SUMMARY
echo "[![Upload Asset Form]($ARTIFACT_URL/__image_snapshots__/ci-Upload-Asset-Form-1-snap.png)]($ARTIFACT_URL/__image_snapshots__/ci-Upload-Asset-Form-1-snap.png)" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo "### Complete Workflow Form" >> $GITHUB_STEP_SUMMARY
echo '<details><summary>View Screenshot</summary>' >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo "\`\`\`html" >> $GITHUB_STEP_SUMMARY
echo "<img src='data:image/png;base64,$(base64 -w 0 __image_snapshots__/ci-Complete-Workflow-Form-1-snap.png)'>" >> $GITHUB_STEP_SUMMARY
echo "\`\`\`" >> $GITHUB_STEP_SUMMARY
echo "</details>" >> $GITHUB_STEP_SUMMARY
echo "[![Complete Workflow Form]($ARTIFACT_URL/__image_snapshots__/ci-Complete-Workflow-Form-1-snap.png)]($ARTIFACT_URL/__image_snapshots__/ci-Complete-Workflow-Form-1-snap.png)" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo "### Cleanup Confirmation Form" >> $GITHUB_STEP_SUMMARY
echo '<details><summary>View Screenshot</summary>' >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo "\`\`\`html" >> $GITHUB_STEP_SUMMARY
echo "<img src='data:image/png;base64,$(base64 -w 0 __image_snapshots__/ci-Cleanup-Confirmation-Form-1-snap.png)'>" >> $GITHUB_STEP_SUMMARY
echo "\`\`\`" >> $GITHUB_STEP_SUMMARY
echo "</details>" >> $GITHUB_STEP_SUMMARY
echo "[![Cleanup Confirmation Form]($ARTIFACT_URL/__image_snapshots__/ci-Cleanup-Confirmation-Form-1-snap.png)]($ARTIFACT_URL/__image_snapshots__/ci-Cleanup-Confirmation-Form-1-snap.png)" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
if [ -d "__image_snapshots__/__diff_output__" ]; then
echo "### ⚠️ Visual Differences Detected" >> $GITHUB_STEP_SUMMARY
for diff in __image_snapshots__/__diff_output__/*.png; do
filename=$(basename "$diff" .png)
echo "#### $filename" >> $GITHUB_STEP_SUMMARY
echo '<details><summary>View Diff</summary>' >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo "\`\`\`html" >> $GITHUB_STEP_SUMMARY
echo "<img src='data:image/png;base64,$(base64 -w 0 "$diff")'>" >> $GITHUB_STEP_SUMMARY
echo "\`\`\`" >> $GITHUB_STEP_SUMMARY
echo "</details>" >> $GITHUB_STEP_SUMMARY
echo "[![Diff]($ARTIFACT_URL/__image_snapshots__/__diff_output__/$filename.png)]($ARTIFACT_URL/__image_snapshots__/__diff_output__/$filename.png)" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
done
fi

0 comments on commit b040f48

Please sign in to comment.