]> git.proxmox.com Git - pve-eslint.git/blob - eslint/tests/lib/cli-engine/formatters/unix.js
first commit
[pve-eslint.git] / eslint / tests / lib / cli-engine / formatters / unix.js
1 /**
2 * @fileoverview Tests for unix-style formatter.
3 * @author oshi-shinobu
4 */
5
6 "use strict";
7
8 //------------------------------------------------------------------------------
9 // Requirements
10 //------------------------------------------------------------------------------
11
12 const assert = require("chai").assert,
13 formatter = require("../../../../lib/cli-engine/formatters/unix");
14
15 //------------------------------------------------------------------------------
16 // Tests
17 //------------------------------------------------------------------------------
18
19 describe("formatter:compact", () => {
20 describe("when passed no messages", () => {
21 const code = [{
22 filePath: "foo.js",
23 messages: []
24 }];
25
26 it("should return nothing", () => {
27 const result = formatter(code);
28
29 assert.strictEqual(result, "");
30 });
31 });
32
33 describe("when passed a single message", () => {
34 const code = [{
35 filePath: "foo.js",
36 messages: [{
37 message: "Unexpected foo.",
38 severity: 2,
39 line: 5,
40 column: 10,
41 ruleId: "foo"
42 }]
43 }];
44
45 it("should return a string in the format filename:line:column: error [Error/rule_id]", () => {
46 const result = formatter(code);
47
48 assert.strictEqual(result, "foo.js:5:10: Unexpected foo. [Error/foo]\n\n1 problem");
49 });
50
51 it("should return a string in the format filename:line:column: warning [Warning/rule_id]", () => {
52 code[0].messages[0].severity = 1;
53 const result = formatter(code);
54
55 assert.strictEqual(result, "foo.js:5:10: Unexpected foo. [Warning/foo]\n\n1 problem");
56 });
57 });
58
59 describe("when passed a fatal error message", () => {
60 const code = [{
61 filePath: "foo.js",
62 messages: [{
63 fatal: true,
64 message: "Unexpected foo.",
65 line: 5,
66 column: 10,
67 ruleId: "foo"
68 }]
69 }];
70
71 it("should return a string in the format filename:line:column: error [Error/rule_id]", () => {
72 const result = formatter(code);
73
74 assert.strictEqual(result, "foo.js:5:10: Unexpected foo. [Error/foo]\n\n1 problem");
75 });
76 });
77
78 describe("when passed multiple messages", () => {
79 const code = [{
80 filePath: "foo.js",
81 messages: [{
82 message: "Unexpected foo.",
83 severity: 2,
84 line: 5,
85 column: 10,
86 ruleId: "foo"
87 }, {
88 message: "Unexpected bar.",
89 severity: 1,
90 line: 6,
91 column: 11,
92 ruleId: "bar"
93 }]
94 }];
95
96 it("should return a string with multiple entries", () => {
97 const result = formatter(code);
98
99 assert.strictEqual(result, "foo.js:5:10: Unexpected foo. [Error/foo]\nfoo.js:6:11: Unexpected bar. [Warning/bar]\n\n2 problems");
100 });
101 });
102
103 describe("when passed multiple files with 1 message each", () => {
104 const code = [{
105 filePath: "foo.js",
106 messages: [{
107 message: "Unexpected foo.",
108 severity: 2,
109 line: 5,
110 column: 10,
111 ruleId: "foo"
112 }]
113 }, {
114 filePath: "bar.js",
115 messages: [{
116 message: "Unexpected bar.",
117 severity: 1,
118 line: 6,
119 column: 11,
120 ruleId: "bar"
121 }]
122 }];
123
124 it("should return a string with multiple entries", () => {
125 const result = formatter(code);
126
127 assert.strictEqual(result, "foo.js:5:10: Unexpected foo. [Error/foo]\nbar.js:6:11: Unexpected bar. [Warning/bar]\n\n2 problems");
128 });
129 });
130
131 describe("when passed one file not found message", () => {
132 const code = [{
133 filePath: "foo.js",
134 messages: [{
135 fatal: true,
136 message: "Couldn't find foo.js."
137 }]
138 }];
139
140 it("should return a string without line and column", () => {
141 const result = formatter(code);
142
143 assert.strictEqual(result, "foo.js:0:0: Couldn't find foo.js. [Error]\n\n1 problem");
144 });
145 });
146 });