Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(jest-junit-reporter): report when entire suite fails #1241

Merged
merged 1 commit into from
Dec 30, 2024
Merged
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
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();
});
});
Loading