From 164437d994290fc3c5612ae351960cdf29099bf0 Mon Sep 17 00:00:00 2001 From: Marie-Alice Blete <10806774+malywut@users.noreply.github.com> Date: Mon, 10 Feb 2025 15:13:35 +0100 Subject: [PATCH 1/2] Add test failure/errors details as collapsible --- src/cli.js | 3 +-- src/junitXml.js | 45 +++++++++++++++++++++++++++++++++++++-------- 2 files changed, 38 insertions(+), 10 deletions(-) diff --git a/src/cli.js b/src/cli.js index f1f7051..9e2c1dd 100644 --- a/src/cli.js +++ b/src/cli.js @@ -4,7 +4,6 @@ const { getCoverageReport } = require('./parse'); const { getSummaryReport, getParsedXml, - getNotSuccessTest, } = require('./junitXml'); const { getMultipleReport } = require('./multiFiles'); const { getCoverageXmlReport } = require('./parseXml'); @@ -90,7 +89,7 @@ const main = async () => { const parsedXml = getParsedXml(options); const { errors, failures, skipped, tests, time } = parsedXml; const valuesToExport = { errors, failures, skipped, tests, time }; - const notSuccessTestInfo = getNotSuccessTest(options); + const notSuccessTestInfo = parsedXml.notSuccessTestInfo; console.log('notSuccessTestInfo', JSON.stringify(notSuccessTestInfo)); diff --git a/src/junitXml.js b/src/junitXml.js index 8500de7..3d7c124 100644 --- a/src/junitXml.js +++ b/src/junitXml.js @@ -51,6 +51,8 @@ const getSummary = (data) => { summary.tests += +tests; summary.time += +time; } + summary.notSuccessTestInfo = getNotSuccessTest(data); + return summary; }; @@ -70,19 +72,18 @@ const getTestCases = (data) => { return parser.resultObject.testsuites.testsuite.map((t) => t.testcase).flat(); }; -const getNotSuccessTest = (options) => { +const getNotSuccessTest = (data) => { const initData = { count: 0, failures: [], errors: [], skipped: [] }; try { - const content = getContent(options.xmlFile); - if (content) { + if (data) { const testCaseToOutput = (testcase) => { const { classname, name } = testcase['$']; return { classname, name }; }; - const testcases = getTestCases(content); + const testcases = getTestCases(data); const failures = testcases.filter((t) => t.failure).map(testCaseToOutput); const errors = testcases.filter((t) => t.error).map(testCaseToOutput); @@ -109,17 +110,45 @@ const toMarkdown = (summary, options) => { const { errors, failures, skipped, tests, time } = summary; const displayTime = time > 60 ? `${(time / 60) | 0}m ${time % 60 | 0}s` : `${time.toFixed(3)}s`; + + // Summary table const table = `| Tests | Skipped | Failures | Errors | Time | | ----- | ------- | -------- | -------- | ------------------ | | ${tests} | ${skipped} :zzz: | ${failures} :x: | ${errors} :fire: | ${displayTime} :stopwatch: | `; + // Combine and sort all non-success tests + const allNonSuccessTests = [ + ...summary.notSuccessTestInfo.failures.map(f => ({ ...f, type: ':x: Failure' })), + ...summary.notSuccessTestInfo.errors.map(e => ({ ...e, type: ':fire: Error' })), + ...summary.notSuccessTestInfo.skipped.map(s => ({ ...s, type: ':zzz: Skipped' })) + ]; + + // Detailed non-success tests section + let nonSuccessDetails = ''; + if (allNonSuccessTests.length > 0) { + const detailedTestsList = allNonSuccessTests.map(test => + `- ${test.type} **${test.name}** (${test.classname}) + \`${test.message ? test.message.replace(/\n/g, ' ').replace(/\|/g, '\\|') : 'No message'}\`` + ).join('\n'); + + nonSuccessDetails = ` +
+:warning: Detailed Non-Success Tests (${allNonSuccessTests.length}) + +${detailedTestsList} +
+`; + } + + // Combine sections + let output = table + nonSuccessDetails; + if (options.xmlTitle) { - return `## ${options.xmlTitle} -${table}`; + output = `## ${options.xmlTitle}\n${output}`; } - return table; + return output; }; -module.exports = { getSummaryReport, getParsedXml, getNotSuccessTest }; +module.exports = { getSummaryReport, getParsedXml }; From b24f62309817d5564ba73a89241e7cc123fd2e47 Mon Sep 17 00:00:00 2001 From: Marie-Alice Blete <10806774+malywut@users.noreply.github.com> Date: Mon, 10 Feb 2025 16:43:17 +0100 Subject: [PATCH 2/2] Add missing information from test cases --- src/junitXml.js | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/junitXml.js b/src/junitXml.js index 3d7c124..85cbcdc 100644 --- a/src/junitXml.js +++ b/src/junitXml.js @@ -80,7 +80,12 @@ const getNotSuccessTest = (data) => { if (data) { const testCaseToOutput = (testcase) => { const { classname, name } = testcase['$']; - return { classname, name }; + const failure = testcase.failure ? testcase.failure[0] : null; + const error = testcase.error ? testcase.error[0] : null; + const skipped = testcase.skipped ? testcase.skipped[0] : null; + const message = failure ? failure['_'] : error ? error['_'] : skipped ? skipped['_'] : null; + + return { classname, name, failure, error, skipped, message }; }; const testcases = getTestCases(data);