Skip to content
Snippets Groups Projects
Unverified Commit 1b2dcb71 authored by Uladzimir Havenchyk's avatar Uladzimir Havenchyk Committed by GitHub
Browse files

ci: put failing tests into e2e job summary (#47134)

* ci: put failing tests into e2e job summary

* cleanup
parent 0e514b45
No related branches found
No related tags found
No related merge requests found
const fs = require("fs");
const logger = { debug: console.debug, error: console.error };
const collectTestsByType = ({ type, suite, path, cache = [] }) => {
logger.debug(`Collecting tests of type ${type}`);
const localCache = cache;
const { [type]: typeList, suites, tests } = suite;
for (const uuid of typeList) {
const foundTestByUuid = tests.find(test => test.uuid === uuid);
if (!foundTestByUuid) {
logger.error(`Test with uuid ${uuid} not found`);
throw new Error(`Test with uuid ${uuid} not found`);
}
logger.debug(`Found test with uuid ${uuid}`);
foundTestByUuid.path = path;
localCache.push({ path, ...foundTestByUuid });
}
for (const subSuite of suites) {
collectTestsByType({
type,
suite: subSuite,
path: subSuite.file || path,
cache: localCache,
});
}
return localCache;
};
const extractTestResultsInfo = ({ results, stats }) => {
logger.debug("Extracting test results information");
const testType = "failures";
const failedTests = results.flatMap(result =>
collectTestsByType({
type: testType,
suite: result,
path: result.file,
}),
);
logger.debug("Finished extracting test results information");
return {
failedTests,
};
};
function parseReport() {
const content = fs.readFileSync(
"./cypress/reports/cypress-test-report.json",
"utf-8",
);
const data = JSON.parse(content);
return extractTestResultsInfo(data).failedTests.map(test => ({
title: test.fullTitle,
error: test.err?.message,
path: test.path,
}));
}
exports.parseReport = parseReport;
const groupTestsByPath = report => {
return report.reduce((acc, item) => {
if (!acc[item.path]) {
acc[item.path] = [];
}
acc[item.path].push(item);
return acc;
}, {});
};
function formatSummary(report) {
const failedTestsByPath = groupTestsByPath(report);
let summary = "### Failed Tests Summary\n\n";
for (const [path, tests] of Object.entries(failedTestsByPath)) {
summary += `| ${path} |\n`;
summary += "| :--- |\n";
tests.forEach(test => {
summary += `| ${test.title}`;
summary += "<p></p>"; // adds extra space after title
summary += `<details>`;
summary += "<summary>❌ ";
summary += `<code>${truncateError(test.error)}</code>`;
summary += "</summary>";
summary += `<pre>${test.error}</pre>`.replaceAll("\n", "<br>");
summary += `</details> |\n`;
});
}
return summary;
}
function truncateError(error, maxLength = 100) {
if (error.length <= maxLength) return error;
return error.replaceAll("\n", "").substring(0, maxLength) + "...";
}
exports.formatSummary = formatSummary;
......@@ -252,6 +252,21 @@ jobs:
./logs/test.log
if-no-files-found: ignore
- name: Publish Summary
if: failure()
uses: actions/github-script@v7
with:
script: | #js
const {
parseReport,
formatSummary
} = require("./.github/scripts/handle-mochawesome-report.js");
const report = parseReport();
const summary = formatSummary(report);
await core.summary.addRaw(summary).write();
e2e-tests-skipped-stub:
needs: [e2e-tests, e2e-matrix-builder]
if: |
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment