Skip to content
This repository has been archived by the owner on Mar 25, 2021. It is now read-only.

Commit

Permalink
Improve JUnit formatter (#4327)
Browse files Browse the repository at this point in the history
Fix documentation
  • Loading branch information
iMarv authored and ericanderson committed Dec 12, 2018
1 parent 0298542 commit cd5d7d0
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 18 deletions.
13 changes: 8 additions & 5 deletions src/formatters/junitFormatter.ts
Expand Up @@ -32,8 +32,8 @@ export class Formatter extends AbstractFormatter {
<?xml version="1.0" encoding="utf-8"?>
<testsuites package="tslint">
<testsuite name="myFile.ts">
<testcase name="Line 1, Column 14: semicolon">
<failure type="warning">Missing semicolon</failure>
<testcase name="semicolon" classname="myFile.ts">
<failure type="warning">Missing semicolon Line 1, Column 14</failure>
</testcase>
</testsuite>
</testsuites>
Expand Down Expand Up @@ -64,9 +64,12 @@ export class Formatter extends AbstractFormatter {
output += `<testsuite name="${this.escapeXml(failure.getFileName())}">`;
}

output += `<testcase name="Line ${lineAndCharacter.line + 1}, `;
output += `Column ${lineAndCharacter.character + 1}: ${rule}">`;
output += `<failure type="${severity}">${message}</failure>`;
output += `<testcase name="${rule}" `;
output += `classname="${this.escapeXml(failure.getFileName())}">`;
output += `<failure type="${severity}">${message} `;
output += `Line ${lineAndCharacter.line + 1}, `;
output += `Column ${lineAndCharacter.character + 1}`;
output += `</failure>`;
output += "</testcase>";
}
if (previousFilename !== null) {
Expand Down
25 changes: 12 additions & 13 deletions test/formatters/junitFormatterTests.ts
Expand Up @@ -79,29 +79,28 @@ describe("JUnit Formatter", () => {
"warning",
),
];

const expectedResult = `<?xml version="1.0" encoding="utf-8"?>
<testsuites package="tslint">
<testsuite name="${TEST_FILE_1}">
<testcase name="Line 1, Column 1: first-name">
<failure type="error">first failure</failure>
<testcase name="first-name" classname="${TEST_FILE_1}">
<failure type="error">first failure Line 1, Column 1</failure>
</testcase>
<testcase name="Line 1, Column 3: escape">
<failure type="error">&amp;&lt;&gt;&#39;&quot; should be escaped</failure>
<testcase name="escape" classname="${TEST_FILE_1}">
<failure type="error">&amp;&lt;&gt;&#39;&quot; should be escaped Line 1, Column 3</failure>
</testcase>
<testcase name="Line 6, Column 3: last-name">
<failure type="error">last failure</failure>
<testcase name="last-name" classname="${TEST_FILE_1}">
<failure type="error">last failure Line 6, Column 3</failure>
</testcase>
</testsuite>
<testsuite name="${TEST_FILE_2}">
<testcase name="Line 1, Column 1: first-name">
<failure type="error">first failure</failure>
<testcase name="first-name" classname="${TEST_FILE_2}">
<failure type="error">first failure Line 1, Column 1</failure>
</testcase>
<testcase name="Line 1, Column 3: escape">
<failure type="warning">&amp;&lt;&gt;&#39;&quot; should be escaped</failure>
<testcase name="escape" classname="${TEST_FILE_2}">
<failure type="warning">&amp;&lt;&gt;&#39;&quot; should be escaped Line 1, Column 3</failure>
</testcase>
<testcase name="Line 6, Column 3: last-name">
<failure type="warning">last failure</failure>
<testcase name="last-name" classname="${TEST_FILE_2}">
<failure type="warning">last failure Line 6, Column 3</failure>
</testcase>
</testsuite>
</testsuites>`.replace(/>\s+/g, ">"); // Remove whitespace between tags;
Expand Down

0 comments on commit cd5d7d0

Please sign in to comment.