/** * @fileoverview Tests for jUnit Formatter. * @author Jamund Ferguson */ "use strict"; //------------------------------------------------------------------------------ // Requirements //------------------------------------------------------------------------------ const assert = require("chai").assert, formatter = require("../../../../lib/cli-engine/formatters/junit"), process = require("process"); //------------------------------------------------------------------------------ // Tests //------------------------------------------------------------------------------ const suppliedFilePath = (process.platform === "win32") ? "C:\\path\\to\\foo.js" : "/path/to/foo.js"; const expectedClassName = (process.platform === "win32") ? "C:\\path\\to\\foo" : "/path/to/foo"; describe("formatter:junit", () => { describe("when there are no problems", () => { const code = []; it("should not complain about anything", () => { const result = formatter(code); assert.strictEqual(result.replace(/\n/gu, ""), ""); }); }); describe("when passed a single message", () => { const code = [{ filePath: suppliedFilePath, messages: [{ message: "Unexpected foo.", severity: 2, line: 5, column: 10, ruleId: "foo" }] }]; 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, ""), ``); }); 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, ""), ``); }); }); describe("when passed a fatal error message", () => { const code = [{ filePath: suppliedFilePath, messages: [{ fatal: true, message: "Unexpected foo.", line: 5, column: 10, ruleId: "foo" }] }]; it("should return a single and an ", () => { const result = formatter(code); assert.strictEqual(result.replace(/\n/gu, ""), ``); }); }); describe("when passed a fatal error message with no line or column", () => { const code = [{ filePath: suppliedFilePath, messages: [{ fatal: true, message: "Unexpected foo." }] }]; it("should return a single and an ", () => { const result = formatter(code); assert.strictEqual(result.replace(/\n/gu, ""), ``); }); }); describe("when passed a fatal error message with no line, column, or message text", () => { const code = [{ filePath: suppliedFilePath, messages: [{ fatal: true }] }]; it("should return a single and an ", () => { const result = formatter(code); assert.strictEqual(result.replace(/\n/gu, ""), ``); }); }); describe("when passed multiple messages", () => { const code = [{ filePath: suppliedFilePath, messages: [{ message: "Unexpected foo.", severity: 2, line: 5, column: 10, ruleId: "foo" }, { message: "Unexpected bar.", severity: 1, line: 6, column: 11, ruleId: "bar" }] }]; it("should return a multiple 's", () => { const result = formatter(code); assert.strictEqual(result.replace(/\n/gu, ""), ``); }); }); describe("when passed special characters", () => { const code = [{ filePath: suppliedFilePath, messages: [{ message: "Unexpected \b\t\n\f\r牛逼.", severity: 1, line: 5, column: 10, ruleId: "foo" }] }]; it("should make them go away", () => { const result = formatter(code); assert.strictEqual(result.replace(/\n/gu, ""), ``); }); }); describe("when passed multiple files with 1 message each", () => { const code = [{ filePath: suppliedFilePath, messages: [{ message: "Unexpected foo.", severity: 1, line: 5, column: 10, ruleId: "foo" }] }, { filePath: "bar.js", messages: [{ message: "Unexpected bar.", severity: 2, line: 6, column: 11, ruleId: "bar" }] }]; it("should return 2 's", () => { const result = formatter(code); assert.strictEqual(result.replace(/\n/gu, ""), ``); }); }); describe("when passed multiple files should print even if no errors", () => { const code = [{ filePath: suppliedFilePath, messages: [{ message: "Unexpected foo.", severity: 1, line: 5, column: 10, ruleId: "foo" }] }, { filePath: "bar.js", messages: [] }]; it("should return 2 ", () => { const result = formatter(code); assert.strictEqual(result.replace(/\n/gu, ""), ``); }); }); describe("when passed a file with no errors", () => { const code = [{ filePath: suppliedFilePath, messages: [] }]; it("should print a passing ", () => { const result = formatter(code); assert.strictEqual(result.replace(/\n/gu, ""), ``); }); }); });