From 7acb1b85b1320cc8fb99fd4db29e0c02f746ab2a Mon Sep 17 00:00:00 2001 From: Fabio Pitino Date: Tue, 7 May 2019 16:46:39 +0100 Subject: [PATCH 1/3] New: Add classname attribute to JUnit testcase (refs #11068) --- lib/cli-engine/formatters/junit.js | 16 ++++++++++++++-- tests/lib/cli-engine/formatters/junit.js | 22 +++++++++++----------- 2 files changed, 25 insertions(+), 13 deletions(-) diff --git a/lib/cli-engine/formatters/junit.js b/lib/cli-engine/formatters/junit.js index c12736751d3..a994b4b1980 100644 --- a/lib/cli-engine/formatters/junit.js +++ b/lib/cli-engine/formatters/junit.js @@ -5,6 +5,7 @@ "use strict"; const xmlEscape = require("../xml-escape"); +const path = require("path"); //------------------------------------------------------------------------------ // Helper Functions @@ -24,6 +25,16 @@ function getMessageType(message) { } +/** + * Returns a full file path without extension + * @param {string} filePath input file path + * @returns {string} file path without extension + * @private + */ +function pathWithoutExt(filePath) { + return path.join(path.dirname(filePath), path.basename(filePath, path.extname(filePath))); +} + //------------------------------------------------------------------------------ // Public Interface //------------------------------------------------------------------------------ @@ -38,13 +49,14 @@ module.exports = function(results) { results.forEach(result => { const messages = result.messages; + const classname = pathWithoutExt(result.filePath); if (messages.length > 0) { output += `\n`; messages.forEach(message => { const type = message.fatal ? "error" : "failure"; - output += ``; + output += ``; output += `<${type} message="${xmlEscape(message.message || "")}">`; output += "\n"; } else { output += `\n`; - output += `\n`; + output += `\n`; output += "\n"; } diff --git a/tests/lib/cli-engine/formatters/junit.js b/tests/lib/cli-engine/formatters/junit.js index 7ba0bf441a8..e52b63a42a0 100644 --- a/tests/lib/cli-engine/formatters/junit.js +++ b/tests/lib/cli-engine/formatters/junit.js @@ -31,7 +31,7 @@ describe("formatter:junit", () => { describe("when passed a single message", () => { const code = [{ - filePath: "foo.js", + filePath: "/path/to/foo.js", messages: [{ message: "Unexpected foo.", severity: 2, @@ -44,14 +44,14 @@ describe("formatter:junit", () => { it("should return a single with a message and the line and col number in the body (error)", () => { const result = formatter(code); - assert.strictEqual(result.replace(/\n/gu, ""), ""); + assert.strictEqual(result.replace(/\n/gu, ""), ""); }); it("should return a single with a message and the line and col number in the body (warning)", () => { code[0].messages[0].severity = 1; const result = formatter(code); - assert.strictEqual(result.replace(/\n/gu, ""), ""); + assert.strictEqual(result.replace(/\n/gu, ""), ""); }); }); @@ -70,7 +70,7 @@ describe("formatter:junit", () => { it("should return a single and an ", () => { const result = formatter(code); - assert.strictEqual(result.replace(/\n/gu, ""), ""); + assert.strictEqual(result.replace(/\n/gu, ""), ""); }); }); @@ -86,7 +86,7 @@ describe("formatter:junit", () => { it("should return a single and an ", () => { const result = formatter(code); - assert.strictEqual(result.replace(/\n/gu, ""), ""); + assert.strictEqual(result.replace(/\n/gu, ""), ""); }); }); @@ -101,7 +101,7 @@ describe("formatter:junit", () => { it("should return a single and an ", () => { const result = formatter(code); - assert.strictEqual(result.replace(/\n/gu, ""), ""); + assert.strictEqual(result.replace(/\n/gu, ""), ""); }); }); @@ -126,7 +126,7 @@ describe("formatter:junit", () => { it("should return a multiple 's", () => { const result = formatter(code); - assert.strictEqual(result.replace(/\n/gu, ""), ""); + assert.strictEqual(result.replace(/\n/gu, ""), ""); }); }); @@ -145,7 +145,7 @@ describe("formatter:junit", () => { it("should make them go away", () => { const result = formatter(code); - assert.strictEqual(result.replace(/\n/gu, ""), ""); + assert.strictEqual(result.replace(/\n/gu, ""), ""); }); }); @@ -173,7 +173,7 @@ describe("formatter:junit", () => { it("should return 2 's", () => { const result = formatter(code); - assert.strictEqual(result.replace(/\n/gu, ""), ""); + assert.strictEqual(result.replace(/\n/gu, ""), ""); }); }); @@ -195,7 +195,7 @@ describe("formatter:junit", () => { it("should return 2 ", () => { const result = formatter(code); - assert.strictEqual(result.replace(/\n/gu, ""), ""); + assert.strictEqual(result.replace(/\n/gu, ""), ""); }); }); @@ -208,7 +208,7 @@ describe("formatter:junit", () => { it("should print a passing ", () => { const result = formatter(code); - assert.strictEqual(result.replace(/\n/gu, ""), ""); + assert.strictEqual(result.replace(/\n/gu, ""), ""); }); }); }); From bc9152aff6da36c3e0a4337739f5feddd98b19d4 Mon Sep 17 00:00:00 2001 From: Fabio Pitino Date: Tue, 7 May 2019 17:45:19 +0100 Subject: [PATCH 2/3] Enforce POSIX paths for more test consistency --- lib/cli-engine/formatters/junit.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/cli-engine/formatters/junit.js b/lib/cli-engine/formatters/junit.js index a994b4b1980..f1b04b8feaa 100644 --- a/lib/cli-engine/formatters/junit.js +++ b/lib/cli-engine/formatters/junit.js @@ -32,7 +32,7 @@ function getMessageType(message) { * @private */ function pathWithoutExt(filePath) { - return path.join(path.dirname(filePath), path.basename(filePath, path.extname(filePath))); + return path.join(path.posix.dirname(filePath), path.basename(filePath, path.extname(filePath))); } //------------------------------------------------------------------------------ From a7449e955216a46e57cc1dcb35ef54c2a5298e75 Mon Sep 17 00:00:00 2001 From: Fabio Pitino Date: Thu, 16 May 2019 09:19:33 +0100 Subject: [PATCH 3/3] Enforce path.posix.join for classname attribute --- lib/cli-engine/formatters/junit.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/cli-engine/formatters/junit.js b/lib/cli-engine/formatters/junit.js index f1b04b8feaa..c32425883f7 100644 --- a/lib/cli-engine/formatters/junit.js +++ b/lib/cli-engine/formatters/junit.js @@ -32,7 +32,7 @@ function getMessageType(message) { * @private */ function pathWithoutExt(filePath) { - return path.join(path.posix.dirname(filePath), path.basename(filePath, path.extname(filePath))); + return path.posix.join(path.posix.dirname(filePath), path.basename(filePath, path.extname(filePath))); } //------------------------------------------------------------------------------