Skip to content

Commit e3a64d2

Browse files
committedDec 27, 2024
fix(jest-junit-reporter): report when entire suite fails
1 parent 30c1281 commit e3a64d2

File tree

3 files changed

+50
-12
lines changed

3 files changed

+50
-12
lines changed
 

‎projects/npm-tools/packages/jest-junit-reporter/src/index.js

Lines changed: 19 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -37,18 +37,25 @@ module.exports = (report) => {
3737
};
3838

3939
const testResults = report.testResults
40-
.reduce(
41-
(results, suite) =>
42-
suite.testResults.length
43-
? results.concat(
44-
suite.testResults.map((test) => ({
45-
...test,
46-
testFilePath: suite.testFilePath,
47-
}))
48-
)
49-
: results,
50-
[]
51-
)
40+
.reduce((acc, suite) => {
41+
if (suite.testResults.length) {
42+
acc.push(
43+
...suite.testResults.map((test) => ({
44+
...test,
45+
testFilePath: suite.testFilePath,
46+
}))
47+
);
48+
} else if (suite.failureMessage) {
49+
acc.push({
50+
duration: 0,
51+
failureMessages: [suite.failureMessage],
52+
fullName: suite.testFilePath,
53+
testFilePath: suite.testFilePath,
54+
});
55+
}
56+
57+
return acc;
58+
}, [])
5259
.map((testCase) => {
5360
const results = [
5461
{

‎projects/npm-tools/packages/jest-junit-reporter/test/__snapshots__/index.js.snap

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,15 @@ Received: true
2020
</testsuite>"
2121
`;
2222
23+
exports[`@liferay/jest-junit-reporter writes a file for a failing test suite 1`] = `
24+
"<?xml version=\\"1.0\\" encoding=\\"UTF-8\\"?>
25+
<testsuite errors=\\"0\\" failures=\\"0\\" hostname=\\"\\" id=\\"0\\" name=\\"Jest\\" package=\\"reporter-tests\\" skipped=\\"0\\" tests=\\"1\\" time=\\"0\\" timestamp=\\"1000\\">
26+
<testcase classname=\\"test-module.bar\\" name=\\"/foo/bar/liferay-portal/modules/apps/test-module/bar/Baz.js\\" time=\\"0\\">
27+
<failure message=\\"Test Suite Failed to run\\">Test Suite Failed to run</failure>
28+
</testcase>
29+
</testsuite>"
30+
`;
31+
2332
exports[`@liferay/jest-junit-reporter writes a file for a passing test 1`] = `
2433
"<?xml version=\\"1.0\\" encoding=\\"UTF-8\\"?>
2534
<testsuite errors=\\"0\\" failures=\\"0\\" hostname=\\"\\" id=\\"0\\" name=\\"Jest\\" package=\\"reporter-tests\\" skipped=\\"0\\" tests=\\"1\\" time=\\"0\\" timestamp=\\"1000\\">

‎projects/npm-tools/packages/jest-junit-reporter/test/index.js

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,20 @@ const failedTestReport = {
3434
],
3535
};
3636

37+
const failedTestSuite = {
38+
numFailedTests: 0,
39+
numTotalTests: 1,
40+
startTime: 1000,
41+
testResults: [
42+
{
43+
failureMessage: 'Test Suite Failed to run',
44+
testFilePath:
45+
'/foo/bar/liferay-portal/modules/apps/test-module/bar/Baz.js',
46+
testResults: [],
47+
},
48+
],
49+
};
50+
3751
const passedTestReport = {
3852
numFailedTests: 0,
3953
numTotalTests: 1,
@@ -82,4 +96,12 @@ describe('@liferay/jest-junit-reporter', () => {
8296

8397
expect(xmlWritten).toMatchSnapshot();
8498
});
99+
100+
it('writes a file for a failing test suite', () => {
101+
reporter(failedTestSuite);
102+
103+
const xmlWritten = fs.writeFileSync.mock.calls[0][1];
104+
105+
expect(xmlWritten).toMatchSnapshot();
106+
});
85107
});

0 commit comments

Comments
 (0)