Skip to content

Commit

Permalink
Fix: Include files with no messages in junit results (#9093) (#9094)
Browse files Browse the repository at this point in the history
  • Loading branch information
Sean-Der authored and not-an-aardvark committed Aug 14, 2017
1 parent 1d6a9c0 commit a4f53ba
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 11 deletions.
10 changes: 2 additions & 8 deletions lib/formatters/junit.js
Expand Up @@ -39,10 +39,7 @@ module.exports = function(results) {

const messages = result.messages;

if (messages.length) {
output += `<testsuite package="org.eslint" time="0" tests="${messages.length}" errors="${messages.length}" name="${result.filePath}">\n`;
}

output += `<testsuite package="org.eslint" time="0" tests="${messages.length}" errors="${messages.length}" name="${result.filePath}">\n`;
messages.forEach(message => {
const type = message.fatal ? "error" : "failure";

Expand All @@ -57,10 +54,7 @@ module.exports = function(results) {
output += `</${type}>`;
output += "</testcase>\n";
});

if (messages.length) {
output += "</testsuite>\n";
}
output += "</testsuite>\n";

});

Expand Down
6 changes: 3 additions & 3 deletions tests/lib/formatters/junit.js
Expand Up @@ -177,7 +177,7 @@ describe("formatter:junit", () => {
});
});

describe("when passed multiple files with total 1 failure", () => {
describe("when passed multiple files should print even if no errors", () => {
const code = [{
filePath: "foo.js",
messages: [{
Expand All @@ -192,10 +192,10 @@ describe("formatter:junit", () => {
messages: []
}];

it("should return 1 <testsuite>", () => {
it("should return 2 <testsuite>", () => {
const result = formatter(code);

assert.equal(result.replace(/\n/g, ""), "<?xml version=\"1.0\" encoding=\"utf-8\"?><testsuites><testsuite package=\"org.eslint\" time=\"0\" tests=\"1\" errors=\"1\" name=\"foo.js\"><testcase time=\"0\" name=\"org.eslint.foo\"><failure message=\"Unexpected foo.\"><![CDATA[line 5, col 10, Warning - Unexpected foo. (foo)]]></failure></testcase></testsuite></testsuites>");
assert.equal(result.replace(/\n/g, ""), "<?xml version=\"1.0\" encoding=\"utf-8\"?><testsuites><testsuite package=\"org.eslint\" time=\"0\" tests=\"1\" errors=\"1\" name=\"foo.js\"><testcase time=\"0\" name=\"org.eslint.foo\"><failure message=\"Unexpected foo.\"><![CDATA[line 5, col 10, Warning - Unexpected foo. (foo)]]></failure></testcase></testsuite><testsuite package=\"org.eslint\" time=\"0\" tests=\"0\" errors=\"0\" name=\"bar.js\"></testsuite></testsuites>");
});
});
});

0 comments on commit a4f53ba

Please sign in to comment.