Skip to content

Commit

Permalink
fix(htmlReportCreator): check if plainFailureMessage exists (#6)
Browse files Browse the repository at this point in the history
  • Loading branch information
sklawren authored Feb 19, 2020
1 parent 0458730 commit 879d959
Show file tree
Hide file tree
Showing 4 changed files with 7,780 additions and 5 deletions.
77 changes: 77 additions & 0 deletions __tests__/__snapshots__/html-report-creator.spec.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,83 @@ exports[`html-report-creator should correctly render passing tests 1`] = `
</html>"
`;
exports[`html-report-creator should ignore null plainFailureMessages 1`] = `
"<?xml version=\\"1.0\\"?>
<html>
<head>
<meta charset=\\"utf-8\\"/>
<title>Jest test results</title>
<style type=\\"text/css\\">
html, body {
font-family: sans-serif;
font-size: 1rem;
}
body {
padding: 1rem 1rem;
}
.summary {
color: #999;
margin-bottom: 1em;
}
.suite-info {
padding-bottom: 1em;
font-weight: bold;
font-size: 0.9rem;
color: black;
}
.suite-table {
width: 100%;
margin-bottom: 1em;
}
.suite-table tr.passed {
background-color: mintcream;
color: green;
}
.suite-table tr.failed {
background-color: LavenderBlush;
color: red;
}
.suite-table td {
font-size: 0.85rem;
border-bottom: 1px solid #aaa;
vertical-align: top;
padding: 0.5rem;
}
.suite-table span.result {
float: right;
}
</style>
</head>
<div class=\\"summary\\">
<div>
Test Suites: 0 passed,
1 failed,
0 skipped,
1 total
</div>
<div>
Tests: 0 passed,
1 failed,
0 skipped,
1 total
</div>
</div>
<div class=\\"suite-info\\">
/path/to/__tests__/test.spec.js
(0.297s)
</div>
<table class=\\"suite-table\\">
<tr class=\\"failed\\">
<td>
test should work
<span class=\\"result\\">failed in 0.004s</span>
<div/>
</td>
</tr>
</table>
</html>"
`;
exports[`html-report-creator should not display pending tests 1`] = `
"<?xml version=\\"1.0\\"?>
<html>
Expand Down
22 changes: 22 additions & 0 deletions __tests__/html-report-creator.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,28 @@ describe('html-report-creator', () => {
).toMatchSnapshot();
});

it('should ignore null plainFailureMessages', () => {
const createHtmlReport = setupTest();
const mockResult = buildMockResult(
{
numPassedTestSuites: 0,
numFailedTestSuites: 1,
numPassedTests: 0,
numFailedTests: 1,
testResults: [
{
testResults: [{ status: 'failed', failureMessages: [null] }],
},
],
}
);

createHtmlReport(mockResult);
expect(
prettyPrintHtml(fs.writeFileSync.mock.calls[0][1])
).toMatchSnapshot();
});

it('should render failure message as a link if test is for an image snapshot', () => {
const createHtmlReport = setupTest();
const mockResult = buildMockResult(
Expand Down
13 changes: 8 additions & 5 deletions html-report-creator.js
Original file line number Diff line number Diff line change
Expand Up @@ -78,12 +78,14 @@ module.exports = (result) => {
const failureMsgDiv = testTd.ele('div');
test.failureMessages.forEach((failureMsg) => {
const plainFailureMessage = stripAnsi(failureMsg);
// TODO: need to find better way to when it is an image snapshot
if (plainFailureMessage.includes('__image_snapshots__/')) {
const imageDiffUrl = `${plainFailureMessage.match(':(.*).png')[1]}.png`;
failureMsgDiv.ele('a', { href: imageDiffUrl });
if (plainFailureMessage) {
// TODO: need to find better way to when it is an image snapshot
if (plainFailureMessage.includes('__image_snapshots__/')) {
const imageDiffUrl = `${plainFailureMessage.match(':(.*).png')[1]}.png`;
failureMsgDiv.ele('a', { href: imageDiffUrl });
}
failureMsgDiv.ele('pre', plainFailureMessage);
}
failureMsgDiv.ele('pre', plainFailureMessage);
});
}
}
Expand All @@ -94,3 +96,4 @@ module.exports = (result) => {

return result;
};

Loading

0 comments on commit 879d959

Please sign in to comment.