Skip to content

Commit

Permalink
Merge pull request #1241 from bryceosterhaus/LPD-44094
Browse files Browse the repository at this point in the history
fix(jest-junit-reporter): report when entire suite fails
  • Loading branch information
bryceosterhaus authored Dec 30, 2024
2 parents 30c1281 + dd984f2 commit 41e38ab
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 12 deletions.
32 changes: 20 additions & 12 deletions projects/npm-tools/packages/jest-junit-reporter/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,18 +37,26 @@ module.exports = (report) => {
};

const testResults = report.testResults
.reduce(
(results, suite) =>
suite.testResults.length
? results.concat(
suite.testResults.map((test) => ({
...test,
testFilePath: suite.testFilePath,
}))
)
: results,
[]
)
.reduce((acc, suite) => {
if (suite.testResults.length) {
acc.push(
...suite.testResults.map((test) => ({
...test,
testFilePath: suite.testFilePath,
}))
);
}
else if (suite.failureMessage) {
acc.push({
duration: 0,
failureMessages: [suite.failureMessage],
fullName: suite.testFilePath,
testFilePath: suite.testFilePath,
});
}

return acc;
}, [])
.map((testCase) => {
const results = [
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,15 @@ Received: true
</testsuite>"
`;
exports[`@liferay/jest-junit-reporter writes a file for a failing test suite 1`] = `
"<?xml version=\\"1.0\\" encoding=\\"UTF-8\\"?>
<testsuite errors=\\"0\\" failures=\\"0\\" hostname=\\"\\" id=\\"0\\" name=\\"Jest\\" package=\\"reporter-tests\\" skipped=\\"0\\" tests=\\"1\\" time=\\"0\\" timestamp=\\"1000\\">
<testcase classname=\\"test-module.bar\\" name=\\"/foo/bar/liferay-portal/modules/apps/test-module/bar/Baz.js\\" time=\\"0\\">
<failure message=\\"Test Suite Failed to run\\">Test Suite Failed to run</failure>
</testcase>
</testsuite>"
`;
exports[`@liferay/jest-junit-reporter writes a file for a passing test 1`] = `
"<?xml version=\\"1.0\\" encoding=\\"UTF-8\\"?>
<testsuite errors=\\"0\\" failures=\\"0\\" hostname=\\"\\" id=\\"0\\" name=\\"Jest\\" package=\\"reporter-tests\\" skipped=\\"0\\" tests=\\"1\\" time=\\"0\\" timestamp=\\"1000\\">
Expand Down
22 changes: 22 additions & 0 deletions projects/npm-tools/packages/jest-junit-reporter/test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,20 @@ const failedTestReport = {
],
};

const failedTestSuite = {
numFailedTests: 0,
numTotalTests: 1,
startTime: 1000,
testResults: [
{
failureMessage: 'Test Suite Failed to run',
testFilePath:
'/foo/bar/liferay-portal/modules/apps/test-module/bar/Baz.js',
testResults: [],
},
],
};

const passedTestReport = {
numFailedTests: 0,
numTotalTests: 1,
Expand Down Expand Up @@ -82,4 +96,12 @@ describe('@liferay/jest-junit-reporter', () => {

expect(xmlWritten).toMatchSnapshot();
});

it('writes a file for a failing test suite', () => {
reporter(failedTestSuite);

const xmlWritten = fs.writeFileSync.mock.calls[0][1];

expect(xmlWritten).toMatchSnapshot();
});
});

0 comments on commit 41e38ab

Please sign in to comment.