Skip to content

Commit

Permalink
add summary report merger
Browse files Browse the repository at this point in the history
  • Loading branch information
shashwatahalder01 committed Dec 19, 2024
1 parent ae2b960 commit 55a49e9
Show file tree
Hide file tree
Showing 3 changed files with 98 additions and 2 deletions.
8 changes: 7 additions & 1 deletion .github/workflows/all-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -582,7 +582,13 @@ jobs:
npx playwright merge-reports --reporter html ./all-reports/all-blob-reports
mv playwright-report ./all-reports/html-report
- name: Upload HTML report
- name: Generate summary report
working-directory: tests/pw
run: |
node ./mergeTestSummary.js
- name: Upload final test artifact
uses: actions/upload-artifact@v4
with:
name: final-test-artifact
Expand Down
2 changes: 1 addition & 1 deletion tests/pw/e2e.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ export default defineConfig({
{
name: 'e2e_tests',
testMatch: /.*\.spec\.ts/,
grep: [/@lite/],
grep: [/@admin/],
/* whether not to run setup tests before running actual tests */
dependencies: NO_SETUP ? [] : ['e2e_setup'],
/* whether not to run teardown tests after running actual tests */
Expand Down
90 changes: 90 additions & 0 deletions tests/pw/utils/mergeSummaryReport.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
const fs = require('fs');
const path = require('path');

// Helper function to format duration
const getFormattedDuration = milliseconds => {
const hours = Math.floor(milliseconds / (1000 * 60 * 60));
const min = Math.floor((milliseconds / (1000 * 60)) % 60);
const sec = Math.floor((milliseconds / 1000) % 60);
return `${hours < 1 ? '' : hours + 'h '}${min < 1 ? '' : min + 'm '}${sec < 1 ? '' : sec + 's'}`;
};

const mergeReports = reportPaths => {
const mergedReport = {
suite_name: '',
total_tests: 0,
passed: 0,
failed: 0,
flaky: 0,
skipped: 0,
suite_duration: 0,
suite_duration_formatted: '',
tests: [],
passed_tests: [],
failed_tests: [],
flaky_tests: [],
skipped_tests: [],
};

reportPaths.forEach(reportPath => {
const report = JSON.parse(fs.readFileSync(reportPath, 'utf8'));
mergedReport.total_tests += report.total_tests;
mergedReport.passed += report.passed;
mergedReport.failed += report.failed;
mergedReport.flaky += report.flaky;
mergedReport.skipped += report.skipped;
mergedReport.suite_duration += report.suite_duration;

// Append and de-duplicate test arrays
mergedReport.tests.push(...report.tests);
mergedReport.passed_tests.push(...report.passed_tests);
mergedReport.failed_tests.push(...report.failed_tests);
mergedReport.flaky_tests.push(...report.flaky_tests);
mergedReport.skipped_tests.push(...report.skipped_tests);
});

// Remove duplicates and sort arrays
mergedReport.tests = [...new Set(mergedReport.tests)].sort();
mergedReport.passed_tests = [...new Set(mergedReport.passed_tests)].sort();
mergedReport.failed_tests = [...new Set(mergedReport.failed_tests)].sort();
mergedReport.flaky_tests = [...new Set(mergedReport.flaky_tests)].sort();
mergedReport.skipped_tests = [...new Set(mergedReport.skipped_tests)].sort();

// Format the suite duration
mergedReport.suite_duration_formatted = getFormattedDuration(mergedReport.suite_duration);

return mergedReport;
};

// Main script execution
const reportsFolder = './all-reports'; // Change to your artifacts location
const reportPaths = [];

// Collect all result.json files
const findReports = dir => {
const files = fs.readdirSync(dir);
files.forEach(file => {
const fullPath = path.join(dir, file);
if (fs.statSync(fullPath).isDirectory()) {
findReports(fullPath); // Recurse into subdirectories
} else if (file === 'results.json') {
reportPaths.push(fullPath);
}
});
};

findReports(reportsFolder);

if (reportPaths.length === 0) {
console.error('No results.json files found in artifacts.');
process.exit(1);
}

// Merge reports
const mergedReport = mergeReports(reportPaths);

// Save the merged report
const outputPath = './all-reports/merged-summary.json';
fs.writeFileSync(outputPath, JSON.stringify(mergedReport, null, 2), 'utf8');

console.log(`Merged summary report saved to ${outputPath}`);

0 comments on commit 55a49e9

Please sign in to comment.