Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions src/cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ const { getCoverageReport } = require('./parse');
const {
getSummaryReport,
getParsedXml,
getNotSuccessTest,
} = require('./junitXml');
const { getMultipleReport } = require('./multiFiles');
const { getCoverageXmlReport } = require('./parseXml');
Expand Down Expand Up @@ -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));

Expand Down
52 changes: 43 additions & 9 deletions src/junitXml.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@ const getSummary = (data) => {
summary.tests += +tests;
summary.time += +time;
}
summary.notSuccessTestInfo = getNotSuccessTest(data);

return summary;
};

Expand All @@ -70,19 +72,23 @@ 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 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(content);
const testcases = getTestCases(data);

const failures = testcases.filter((t) => t.failure).map(testCaseToOutput);
const errors = testcases.filter((t) => t.error).map(testCaseToOutput);
Expand All @@ -109,17 +115,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 = `
<details>
<summary>:warning: Detailed Non-Success Tests (${allNonSuccessTests.length})</summary>

${detailedTestsList}
</details>
`;
}

// 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 };