use simpler reporting approach in e2e test workflow

This commit is contained in:
mahula 2025-10-01 17:42:43 +02:00
parent 1d0badcc56
commit 352780853d
5 changed files with 1082 additions and 291 deletions

View File

@ -138,290 +138,80 @@ jobs:
# Disable individual cypress-split summaries to avoid conflicts
SPLIT_SUMMARY: false
- name: Merge Test Reports
if: always()
run: |
if [ -d "reports" ] && [ "$(find reports/ -name "*.json" 2>/dev/null)" ]; then
npm run report:merge
else
echo "No test reports to merge"
fi
working-directory: ./cypress
- name: Generate HTML Report
if: always()
run: |
if [ -f "reports/merged-report.json" ]; then
npm run report:generate
else
echo "No merged report to generate HTML from"
fi
working-directory: ./cypress
- name: Create Test Summary
if: always()
run: |
echo "# Cypress E2E Test Results" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
# Debug: Show what files exist
echo "## Debug Information" >> $GITHUB_STEP_SUMMARY
echo "**Working Directory:** $(pwd)" >> $GITHUB_STEP_SUMMARY
echo "**Reports Directory Structure:**" >> $GITHUB_STEP_SUMMARY
echo '```' >> $GITHUB_STEP_SUMMARY
ls -la reports/ 2>/dev/null || echo "No reports directory found"
echo ""
ls -la reports/json/ 2>/dev/null || echo "No reports/json directory found"
echo ""
echo "=== JSON files in reports/ ==="
find reports/ -name "*.json" 2>/dev/null || echo "No JSON files found in reports/"
echo ""
echo "=== Count of JSON files ==="
find reports/ -name "*.json" 2>/dev/null | wc -l || echo "0"
echo '```' >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
# Count total specs
TOTAL_SPECS=$(find e2e -name "*.cy.ts" | wc -l)
echo "**Total Specs:** $TOTAL_SPECS" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo ""
find reports/ -name "*.json" 2>/dev/null || echo "No JSON files found"
echo '```' >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
# Count total specs
TOTAL_SPECS=$(find e2e -name "*.cy.ts" | wc -l)
echo "**Total Specs:** $TOTAL_SPECS" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
# Check actual test results from JSON reports
TOTAL_FAILURES=0
if [ -d "reports/json" ] && [ "$(ls -A reports/json 2>/dev/null)" ]; then
# Count total failures across all JSON reports
for json_file in reports/json/*.json; do
if [ -f "$json_file" ]; then
failures=$(grep -o '"failures":[0-9]*' "$json_file" | cut -d':' -f2 || echo "0")
TOTAL_FAILURES=$((TOTAL_FAILURES + failures))
fi
done
fi
# Display status based on actual test results
if [ "$TOTAL_FAILURES" -eq 0 ]; then
echo "## ✅ All Tests Passed" >> $GITHUB_STEP_SUMMARY
else
echo "## ❌ Tests Failed ($TOTAL_FAILURES total failures)" >> $GITHUB_STEP_SUMMARY
fi
echo "" >> $GITHUB_STEP_SUMMARY
# Always show spec details table
echo "## 📊 Test Details" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo "| Spec File | Status |" >> $GITHUB_STEP_SUMMARY
echo "|-----------|--------|" >> $GITHUB_STEP_SUMMARY
# List all spec files and their actual status from JSON reports
if [ -d "reports" ] && [ "$(find reports/ -name "*.json" 2>/dev/null)" ]; then
echo "Found reports directory with JSON files" >> $GITHUB_STEP_SUMMARY
# Create temporary file to store spec results
temp_results=$(mktemp)
# Parse JSON reports to get actual spec results
for json_file in reports/*.json; do
if [ -f "$json_file" ]; then
# Try multiple patterns to extract spec file name from JSON
# Pattern 1: Look for "file" field
spec_file=$(grep -o '"file":"[^"]*"' "$json_file" | cut -d'"' -f4 | head -1)
# Pattern 2: Look for "spec" field if "file" not found
if [ -z "$spec_file" ]; then
spec_file=$(grep -o '"spec":"[^"]*"' "$json_file" | cut -d'"' -f4 | head -1)
fi
# Pattern 3: Look for "title" or other identifying fields
if [ -z "$spec_file" ]; then
# Try to extract from the file name itself (mochawesome pattern)
spec_file=$(basename "$json_file" .json | sed 's/mochawesome_[0-9]*_//')
fi
if [ -n "$spec_file" ]; then
spec_name=$(basename "$spec_file")
# Check if this spec has any failures
failures=$(grep -o '"failures":[0-9]*' "$json_file" | cut -d':' -f2 || echo "0")
passes=$(grep -o '"passes":[0-9]*' "$json_file" | cut -d':' -f2 || echo "0")
if [ "$failures" -gt 0 ]; then
echo "$spec_name:❌ Failed ($failures failures)" >> "$temp_results"
elif [ "$passes" -gt 0 ]; then
echo "$spec_name:✅ Passed ($passes tests)" >> "$temp_results"
else
echo "$spec_name:⚠️ No tests found" >> "$temp_results"
fi
fi
fi
done
# List all spec files with their actual status
find e2e -name "*.cy.ts" | sort | while read spec; do
spec_name=$(basename "$spec")
result=$(grep "^$spec_name:" "$temp_results" | cut -d':' -f2- || echo "⚠️ No report found")
echo "| $spec_name | $result |" >> $GITHUB_STEP_SUMMARY
done
# Clean up temporary file
rm -f "$temp_results"
else
# Fallback if no JSON reports available
find e2e -name "*.cy.ts" | sort | while read spec; do
spec_name=$(basename "$spec")
echo "| $spec_name | ⚠️ No reports available |" >> $GITHUB_STEP_SUMMARY
done
fi
# Add test counts from JSON reports if available
if [ -d "reports/json" ] && [ "$(ls -A reports/json 2>/dev/null)" ]; then
echo "" >> $GITHUB_STEP_SUMMARY
echo "## Test Counts" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
TOTAL_TESTS=0
PASSED_TESTS=0
FAILED_TESTS=0
# Parse JSON reports to get test counts
for json_file in reports/json/*.json; do
if [ -f "$json_file" ]; then
# Extract test counts using basic tools (avoiding jq dependency)
TESTS=$(grep -o '"tests":[0-9]*' "$json_file" | cut -d':' -f2 || echo "0")
PASSES=$(grep -o '"passes":[0-9]*' "$json_file" | cut -d':' -f2 || echo "0")
FAILURES=$(grep -o '"failures":[0-9]*' "$json_file" | cut -d':' -f2 || echo "0")
TOTAL_TESTS=$((TOTAL_TESTS + TESTS))
PASSED_TESTS=$((PASSED_TESTS + PASSES))
FAILED_TESTS=$((FAILED_TESTS + FAILURES))
fi
done
echo "- **Total Tests:** $TOTAL_TESTS" >> $GITHUB_STEP_SUMMARY
echo "- **Passed:** $PASSED_TESTS ✅" >> $GITHUB_STEP_SUMMARY
echo "- **Failed:** $FAILED_TESTS ❌" >> $GITHUB_STEP_SUMMARY
fi
# Add links to artifacts based on actual test results
echo "" >> $GITHUB_STEP_SUMMARY
echo "## Reports" >> $GITHUB_STEP_SUMMARY
if [ "$TOTAL_FAILURES" -gt 0 ]; then
echo "- HTML Report: Will be available in artifacts" >> $GITHUB_STEP_SUMMARY
echo "- Screenshots: Will be available in artifacts" >> $GITHUB_STEP_SUMMARY
echo "- JSON Reports: Available for detailed analysis" >> $GITHUB_STEP_SUMMARY
else
echo "- ✅ All tests passed - no failure artifacts needed" >> $GITHUB_STEP_SUMMARY
echo "- JSON Reports: Available for test verification" >> $GITHUB_STEP_SUMMARY
fi
working-directory: ./cypress
- name: Debug Before Upload
if: always()
run: |
echo "=== Current Working Directory ==="
pwd
echo ""
echo "=== Cypress Directory Structure ==="
ls -la cypress/ || echo "No cypress directory"
echo ""
echo "=== Cypress Reports Directory ==="
ls -la cypress/reports/ || echo "No cypress/reports directory"
echo ""
echo "=== Find all files in cypress/reports ==="
find cypress/reports/ -type f 2>/dev/null || echo "No files in cypress/reports"
echo ""
echo "=== JSON files specifically ==="
find cypress/reports/ -name "*.json" 2>/dev/null || echo "No JSON files found"
- name: Upload Test Artifacts (Temporary)
if: always() && (steps.cypress-tests.outcome == 'failure' || steps.report-results.outputs.test_failed == 'true')
uses: actions/upload-artifact@2848b2cda0e5190984587ec6bb1f36730ca78d50 # v4.6.2
- name: Upload raw test artifacts on failure
if: failure()
uses: actions/upload-artifact@v4
with:
name: e2e-test-reports-temp-${{ github.run_id }}-${{ github.run_attempt }}
name: cypress-test-results-${{ github.run_id }}
path: |
cypress/reports/
retention-days: 1
cypress/cypress/results/
cypress/screenshots/
cypress/videos/
retention-days: 7
if-no-files-found: warn
- name: Report Test Results
id: report-results
if: always()
run: |
echo "Debug: cypress-tests step outcome = '${{ steps.cypress-tests.outcome }}'"
if [ "${{ steps.cypress-tests.outcome }}" = "failure" ]; then
echo "❌ Tests failed - artifacts will be uploaded by dependent job"
echo "test_failed=true" >> $GITHUB_OUTPUT
exit 1
else
echo "✅ All tests passed successfully"
echo "test_failed=false" >> $GITHUB_OUTPUT
fi
upload-artifacts:
name: Upload Test Artifacts
process-test-reports:
name: Process Test Reports
runs-on: ubuntu-latest
needs: cypress-e2e-tests
# Only run if the test job failed (not cancelled or skipped)
if: always() && (needs.cypress-e2e-tests.result == 'failure' || needs.cypress-e2e-tests.outputs.test_failed == 'true')
if: failure() && needs.cypress-e2e-tests.result == 'failure'
steps:
- name: Download Test Reports
uses: actions/download-artifact@4a24838f3d5601fd639834081e118c2995d51e1c #v5.0.0
with:
name: e2e-test-reports-temp-${{ github.run_id }}-${{ github.run_attempt }}
path: ./cypress-reports
- name: Checkout code
uses: actions/checkout@v4
- name: Debug Downloaded Artifacts
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: '20'
cache: 'npm'
cache-dependency-path: cypress/package-lock.json
- name: Install dependencies
run: npm ci
working-directory: ./cypress
- name: Download test artifacts
uses: actions/download-artifact@v4
with:
name: cypress-test-results-${{ github.run_id }}
path: ./downloaded-reports
- name: Copy reports to expected location
run: |
echo "=== Downloaded Artifact Structure ==="
pwd
ls -la .
echo ""
echo "=== cypress-reports directory ==="
ls -la cypress-reports/ || echo "cypress-reports directory not found"
echo ""
echo "=== Find all files ==="
find cypress-reports/ -type f 2>/dev/null || echo "No files found in cypress-reports"
echo ""
echo "=== Find JSON files specifically ==="
find cypress-reports/ -name "*.json" 2>/dev/null || echo "No JSON files found"
mkdir -p cypress/cypress/results
if [ -d "downloaded-reports/cypress/results" ]; then
cp -r downloaded-reports/cypress/results/* cypress/cypress/results/
fi
if [ -d "downloaded-reports/screenshots" ]; then
cp -r downloaded-reports/screenshots cypress/
fi
if [ -d "downloaded-reports/videos" ]; then
cp -r downloaded-reports/videos cypress/
fi
- name: Upload Test Artifacts
uses: actions/upload-artifact@2848b2cda0e5190984587ec6bb1f36730ca78d50 # v4.6.2
- name: Merge test reports
run: |
if [ -d "cypress/results" ] && [ "$(find cypress/results/ -name "*.json" 2>/dev/null)" ]; then
echo "Found JSON reports, merging..."
npm run report:merge
else
echo "No JSON reports found to merge"
fi
- name: Generate HTML report
run: |
if [ -f "cypress/results/merged-report.json" ]; then
echo "Generating HTML report..."
npm run report:generate
else
echo "No merged report found, skipping HTML generation"
fi
- name: Upload processed reports
uses: actions/upload-artifact@v4
with:
name: e2e-test-failures-${{ github.run_id }}-${{ github.run_attempt }}
name: e2e-test-reports-${{ github.run_id }}
path: |
cypress-reports/reports/
cypress/cypress/results/
retention-days: 30
if-no-files-found: warn
- name: Create Failure Summary
run: |
echo "# 🚨 E2E Test Failure Report" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo "The E2E tests failed. Artifacts have been uploaded for analysis." >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo "## 📦 Available Artifacts" >> $GITHUB_STEP_SUMMARY
echo "- **Screenshots**: Visual evidence of failed tests" >> $GITHUB_STEP_SUMMARY
echo "- **HTML Report**: Detailed test results with interactive features" >> $GITHUB_STEP_SUMMARY
echo "- **JSON Reports**: Raw test data for further analysis" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo "## 🔍 Next Steps" >> $GITHUB_STEP_SUMMARY
echo "1. Download the artifacts from this workflow run" >> $GITHUB_STEP_SUMMARY
echo "2. Open the HTML report to see detailed test results" >> $GITHUB_STEP_SUMMARY
echo "3. Review screenshots to understand visual failures" >> $GITHUB_STEP_SUMMARY
echo "4. Check the test logs in the main job for additional context" >> $GITHUB_STEP_SUMMARY
- name: Cleanup Temporary Artifacts
if: always()
continue-on-error: true
run: |
# Note: GitHub Actions will automatically clean up temporary artifacts
# This step is mainly for documentation purposes
echo "Temporary artifacts will be automatically cleaned up by GitHub Actions"

View File

@ -9,21 +9,20 @@ export default defineConfig({
specPattern: 'e2e/**/*.cy.ts',
supportFile: 'support/e2e.ts',
screenshotsFolder: 'reports/screenshots',
videosFolder: 'reports/videos',
screenshotsFolder: 'screenshots',
videosFolder: 'videos',
video: false,
screenshotOnRunFailure: true,
reporter: 'cypress-mochawesome-reporter',
reporter: 'mochawesome',
reporterOptions: {
reportDir: 'reports',
charts: true,
reportPageTitle: 'Utopia Map E2E Test Report',
useInlineDiffs: true,
embeddedScreenshots: true,
inlineAssets: true,
saveAllAttempts: false,
saveJson: true,
saveHtml: false,
reportDir: 'cypress/results',
reportFilename: '[name].html',
overwrite: false,
html: true,
json: true,
},
defaultCommandTimeout: 10000,
@ -47,9 +46,6 @@ export default defineConfig({
},
setupNodeEvents(on, config) {
// Load cypress-mochawesome-reporter plugin
require('cypress-mochawesome-reporter/plugin')(on)
// Load cypress-split plugin
cypressSplit(on, config)

1005
cypress/package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@ -7,6 +7,9 @@
"test": "cypress run --e2e --browser chromium",
"test:open": "cypress open --e2e",
"test:split:auto": "SPEC_COUNT=$(find e2e -name '*.cy.ts' | wc -l) && echo \"Running $SPEC_COUNT chunks in parallel\" && for i in $(seq 0 $((SPEC_COUNT-1))); do SPLIT=$SPEC_COUNT SPLIT_INDEX=$i cypress run --e2e --browser chromium & done; wait",
"report:merge": "mochawesome-merge cypress/results/*.json > cypress/results/merged-report.json",
"report:generate": "marge cypress/results/merged-report.json --reportDir cypress/results/html --reportTitle 'Utopia Map E2E Tests' --reportPageTitle 'Utopia Map E2E Test Report' --inline --charts",
"report:clean": "rm -rf cypress/results cypress/screenshots cypress/videos",
"lint": "eslint .",
"lint:fix": "eslint . --fix"
},
@ -21,9 +24,13 @@
"@eslint/js": "^9.36.0",
"@types/node": "^24.5.2",
"cypress": "^15.3.0",
"cypress-mochawesome-reporter": "^3.8.2",
"cypress-split": "^1.24.23",
"eslint": "^9.36.0",
"eslint-plugin-cypress": "^5.1.1",
"mochawesome": "^7.1.3",
"mochawesome-merge": "^4.3.0",
"mochawesome-report-generator": "^6.2.0",
"typescript": "^5.9.2",
"typescript-eslint": "^8.44.1"
}

View File

@ -1,7 +1,6 @@
/// <reference types="cypress" />
// Import cypress-mochawesome-reporter register
import 'cypress-mochawesome-reporter/register'
// Import commands.ts using ES2015 syntax:
// import './commands'