]>
git.proxmox.com Git - pve-eslint.git/blob - eslint/tests/lib/cli-engine/formatters/table.js
2 * @fileoverview Tests for "table" reporter.
3 * @author Gajus Kuizinas <gajus@gajus.com>
7 //------------------------------------------------------------------------------
9 //------------------------------------------------------------------------------
11 const assert
= require("chai").assert
;
12 const chalk
= require("chalk");
13 const formatter
= require("../../../../lib/cli-engine/formatters/table");
15 //------------------------------------------------------------------------------
17 //------------------------------------------------------------------------------
19 describe("formatter:table", () => {
20 const originalColorLevel
= chalk
.level
;
27 chalk
.level
= originalColorLevel
;
30 describe("when passed no messages", () => {
40 it("should return a table of error and warning count with no messages", () => {
41 const expectedOutput
= [
43 "╔════════════════════════════════════════════════════════════════════════════════════════════════════════════════╗",
45 "╟────────────────────────────────────────────────────────────────────────────────────────────────────────────────╢",
47 "╚════════════════════════════════════════════════════════════════════════════════════════════════════════════════╝",
51 const result
= formatter(code
);
53 assert
.strictEqual(result
, expectedOutput
);
57 describe("when passed a single message", () => {
58 it("should return a string in the correct format for errors", () => {
64 message
: "Unexpected foo.",
76 const expectedOutput
= [
80 "║ Line │ Column │ Type │ Message │ Rule ID ║",
81 "╟──────────┼──────────┼──────────┼────────────────────────────────────────────────────────┼──────────────────────╢",
82 "║ 5 │ 10 │ error │ Unexpected foo. │ foo ║",
84 "╔════════════════════════════════════════════════════════════════════════════════════════════════════════════════╗",
86 "╟────────────────────────────────────────────────────────────────────────────────────────────────────────────────╢",
88 "╚════════════════════════════════════════════════════════════════════════════════════════════════════════════════╝",
92 const result
= formatter(code
);
94 assert
.strictEqual(result
, expectedOutput
);
97 it("should return a string in the correct format for warnings", () => {
103 message
: "Unexpected foo.",
115 const expectedOutput
= [
119 "║ Line │ Column │ Type │ Message │ Rule ID ║",
120 "╟──────────┼──────────┼──────────┼────────────────────────────────────────────────────────┼──────────────────────╢",
121 "║ 5 │ 10 │ warning │ Unexpected foo. │ foo ║",
123 "╔════════════════════════════════════════════════════════════════════════════════════════════════════════════════╗",
125 "╟────────────────────────────────────────────────────────────────────────────────────────────────────────────────╢",
127 "╚════════════════════════════════════════════════════════════════════════════════════════════════════════════════╝",
131 const result
= formatter(code
);
133 assert
.strictEqual(result
, expectedOutput
);
137 describe("when passed a fatal error message", () => {
138 it("should return a string in the correct format", () => {
145 message
: "Unexpected foo.",
156 const expectedOutput
= [
160 "║ Line │ Column │ Type │ Message │ Rule ID ║",
161 "╟──────────┼──────────┼──────────┼────────────────────────────────────────────────────────┼──────────────────────╢",
162 "║ 5 │ 10 │ error │ Unexpected foo. │ foo ║",
164 "╔════════════════════════════════════════════════════════════════════════════════════════════════════════════════╗",
166 "╟────────────────────────────────────────────────────────────────────────────────────────────────────────────────╢",
168 "╚════════════════════════════════════════════════════════════════════════════════════════════════════════════════╝",
172 const result
= formatter(code
);
174 assert
.strictEqual(result
, expectedOutput
);
178 describe("when passed multiple messages", () => {
179 it("should return a string with multiple entries", () => {
185 message
: "Unexpected foo.",
192 message
: "Unexpected bar.",
204 const expectedOutput
= [
208 "║ Line │ Column │ Type │ Message │ Rule ID ║",
209 "╟──────────┼──────────┼──────────┼────────────────────────────────────────────────────────┼──────────────────────╢",
210 "║ 5 │ 10 │ error │ Unexpected foo. │ foo ║",
211 "║ 6 │ 11 │ warning │ Unexpected bar. │ bar ║",
213 "╔════════════════════════════════════════════════════════════════════════════════════════════════════════════════╗",
215 "╟────────────────────────────────────────────────────────────────────────────────────────────────────────────────╢",
217 "╚════════════════════════════════════════════════════════════════════════════════════════════════════════════════╝",
221 const result
= formatter(code
);
223 assert
.strictEqual(result
, expectedOutput
);
227 describe("when passed multiple files with 1 message each", () => {
228 it("should return a string with multiple entries", () => {
234 message
: "Unexpected foo.",
247 message
: "Unexpected bar.",
259 const expectedOutput
= [
263 "║ Line │ Column │ Type │ Message │ Rule ID ║",
264 "╟──────────┼──────────┼──────────┼────────────────────────────────────────────────────────┼──────────────────────╢",
265 "║ 5 │ 10 │ error │ Unexpected foo. │ foo ║",
269 "║ Line │ Column │ Type │ Message │ Rule ID ║",
270 "╟──────────┼──────────┼──────────┼────────────────────────────────────────────────────────┼──────────────────────╢",
271 "║ 6 │ 11 │ warning │ Unexpected bar. │ bar ║",
273 "╔════════════════════════════════════════════════════════════════════════════════════════════════════════════════╗",
275 "╟────────────────────────────────────────────────────────────────────────────────────────────────────────────────╢",
277 "╚════════════════════════════════════════════════════════════════════════════════════════════════════════════════╝",
281 const result
= formatter(code
);
283 assert
.strictEqual(result
, expectedOutput
);
287 describe("when passed one file not found message", () => {
288 it("should return a string without line and column (0, 0)", () => {
295 message
: "Couldn't find foo.js."
303 const expectedOutput
= [
307 "║ Line │ Column │ Type │ Message │ Rule ID ║",
308 "╟──────────┼──────────┼──────────┼────────────────────────────────────────────────────────┼──────────────────────╢",
309 "║ 0 │ 0 │ error │ Couldn't find foo.js. │ ║",
311 "╔════════════════════════════════════════════════════════════════════════════════════════════════════════════════╗",
313 "╟────────────────────────────────────────────────────────────────────────────────────────────────────────────────╢",
315 "╚════════════════════════════════════════════════════════════════════════════════════════════════════════════════╝",
319 const result
= formatter(code
);
321 assert
.strictEqual(result
, expectedOutput
);