@@ -54,7 +54,9 @@ describe("formatter:codeframe", () => {
54
54
describe ( "when passed no messages" , ( ) => {
55
55
const code = [ {
56
56
filePath : "foo.js" ,
57
- messages : [ ]
57
+ messages : [ ] ,
58
+ errorCount : 0 ,
59
+ warningCount : 0
58
60
} ] ;
59
61
60
62
it ( "should return nothing" , ( ) => {
@@ -64,70 +66,84 @@ describe("formatter:codeframe", () => {
64
66
} ) ;
65
67
} ) ;
66
68
67
- describe ( "when passed a single message" , ( ) => {
69
+ describe ( "when passed a single warning message" , ( ) => {
68
70
const code = [ {
69
71
filePath : path . join ( process . cwd ( ) , "lib" , "foo.js" ) ,
70
72
source : "var foo = 1;\n var bar = 2;\n" ,
71
73
messages : [ {
72
74
message : "Unexpected foo." ,
73
- severity : 2 ,
75
+ severity : 1 ,
74
76
line : 1 ,
75
77
column : 5 ,
76
78
ruleId : "foo"
77
- } ]
79
+ } ] ,
80
+ errorCount : 0 ,
81
+ warningCount : 1
78
82
} ] ;
79
83
80
- it ( "should return a string in the correct format for errors " , ( ) => {
84
+ it ( "should return a string in the correct format for warnings " , ( ) => {
81
85
const result = formatter ( code ) ;
82
86
83
87
assert . equal ( chalk . stripColor ( result ) , [
84
- `error : Unexpected foo (foo) at ${ path . join ( "lib" , "foo.js" ) } :1:5:` ,
88
+ `warning : Unexpected foo (foo) at ${ path . join ( "lib" , "foo.js" ) } :1:5:` ,
85
89
"> 1 | var foo = 1;" ,
86
90
" | ^" ,
87
91
" 2 | var bar = 2;" ,
88
92
" 3 | " ,
89
93
"\n" ,
90
- "1 error found."
94
+ "1 warning found."
91
95
] . join ( "\n" ) ) ;
92
96
} ) ;
93
97
94
- it ( "should return a string in the correct format for warnings" , ( ) => {
95
- code [ 0 ] . messages [ 0 ] . severity = 1 ;
98
+ it ( "should return bold yellow summary when there are only warnings" , ( ) => {
99
+ sandbox . spy ( chalkStub . yellow , "bold" ) ;
100
+ sandbox . spy ( chalkStub . red , "bold" ) ;
101
+
102
+ formatter ( code ) ;
103
+
104
+ assert . equal ( chalkStub . yellow . bold . callCount , 1 ) ;
105
+ assert . equal ( chalkStub . red . bold . callCount , 0 ) ;
106
+ } ) ;
107
+ } ) ;
108
+
109
+ describe ( "when passed a single error message" , ( ) => {
110
+ const code = [ {
111
+ filePath : path . join ( process . cwd ( ) , "lib" , "foo.js" ) ,
112
+ source : "var foo = 1;\n var bar = 2;\n" ,
113
+ messages : [ {
114
+ message : "Unexpected foo." ,
115
+ severity : 2 ,
116
+ line : 1 ,
117
+ column : 5 ,
118
+ ruleId : "foo"
119
+ } ] ,
120
+ errorCount : 1 ,
121
+ warningCount : 0
122
+ } ] ;
96
123
124
+ it ( "should return a string in the correct format for errors" , ( ) => {
97
125
const result = formatter ( code ) ;
98
126
99
127
assert . equal ( chalk . stripColor ( result ) , [
100
- `warning : Unexpected foo (foo) at ${ path . join ( "lib" , "foo.js" ) } :1:5:` ,
128
+ `error : Unexpected foo (foo) at ${ path . join ( "lib" , "foo.js" ) } :1:5:` ,
101
129
"> 1 | var foo = 1;" ,
102
130
" | ^" ,
103
131
" 2 | var bar = 2;" ,
104
132
" 3 | " ,
105
133
"\n" ,
106
- "1 warning found."
134
+ "1 error found."
107
135
] . join ( "\n" ) ) ;
108
136
} ) ;
109
137
110
138
it ( "should return bold red summary when there are errors" , ( ) => {
111
139
sandbox . spy ( chalkStub . yellow , "bold" ) ;
112
140
sandbox . spy ( chalkStub . red , "bold" ) ;
113
- code [ 0 ] . messages [ 0 ] . severity = 2 ;
114
141
115
142
formatter ( code ) ;
116
143
117
144
assert . equal ( chalkStub . yellow . bold . callCount , 0 ) ;
118
145
assert . equal ( chalkStub . red . bold . callCount , 1 ) ;
119
146
} ) ;
120
-
121
- it ( "should return bold yellow summary when there are only warnings" , ( ) => {
122
- sandbox . spy ( chalkStub . yellow , "bold" ) ;
123
- sandbox . spy ( chalkStub . red , "bold" ) ;
124
- code [ 0 ] . messages [ 0 ] . severity = 1 ;
125
-
126
- formatter ( code ) ;
127
-
128
- assert . equal ( chalkStub . yellow . bold . callCount , 1 ) ;
129
- assert . equal ( chalkStub . red . bold . callCount , 0 ) ;
130
- } ) ;
131
147
} ) ;
132
148
133
149
describe ( "when passed multiple messages" , ( ) => {
@@ -146,7 +162,9 @@ describe("formatter:codeframe", () => {
146
162
line : 1 ,
147
163
column : 7 ,
148
164
ruleId : "no-unused-vars"
149
- } ]
165
+ } ] ,
166
+ errorCount : 2 ,
167
+ warningCount : 0
150
168
} ] ;
151
169
152
170
it ( "should return a string with multiple entries" , ( ) => {
@@ -171,6 +189,8 @@ describe("formatter:codeframe", () => {
171
189
sandbox . spy ( chalkStub . yellow , "bold" ) ;
172
190
sandbox . spy ( chalkStub . red , "bold" ) ;
173
191
code [ 0 ] . messages [ 0 ] . severity = 1 ;
192
+ code [ 0 ] . warningCount = 1 ;
193
+ code [ 0 ] . errorCount = 1 ;
174
194
175
195
formatter ( code ) ;
176
196
@@ -190,6 +210,8 @@ describe("formatter:codeframe", () => {
190
210
column : 11 ,
191
211
source : " const foo = 1;"
192
212
} ] ,
213
+ errorCount : 1 ,
214
+ warningCount : 0 ,
193
215
output : "function foo() {\n\n // a comment\n const foo = 1;\n}\n\n"
194
216
} ] ;
195
217
@@ -221,7 +243,9 @@ describe("formatter:codeframe", () => {
221
243
line : 1 ,
222
244
column : 14 ,
223
245
ruleId : "semi"
224
- } ]
246
+ } ] ,
247
+ errorCount : 1 ,
248
+ warningCount : 0
225
249
} , {
226
250
filePath : "bar.js" ,
227
251
source : "const bar = 2\n" ,
@@ -231,7 +255,9 @@ describe("formatter:codeframe", () => {
231
255
line : 1 ,
232
256
column : 14 ,
233
257
ruleId : "semi"
234
- } ]
258
+ } ] ,
259
+ errorCount : 1 ,
260
+ warningCount : 0
235
261
} ] ;
236
262
237
263
it ( "should return a string with multiple entries" , ( ) => {
@@ -265,7 +291,9 @@ describe("formatter:codeframe", () => {
265
291
message : "Parsing error: Unexpected token {" ,
266
292
line : 1 ,
267
293
column : 2
268
- } ]
294
+ } ] ,
295
+ errorCount : 1 ,
296
+ warningCount : 0
269
297
} ] ;
270
298
271
299
it ( "should return a string in the correct format" , ( ) => {
@@ -288,7 +316,9 @@ describe("formatter:codeframe", () => {
288
316
messages : [ {
289
317
fatal : true ,
290
318
message : "Couldn't find foo.js."
291
- } ]
319
+ } ] ,
320
+ errorCount : 1 ,
321
+ warningCount : 0
292
322
} ] ;
293
323
294
324
it ( "should return a string without code preview (codeframe)" , ( ) => {
@@ -306,7 +336,9 @@ describe("formatter:codeframe", () => {
306
336
message : "Unexpected foo." ,
307
337
severity : 2 ,
308
338
source : "foo"
309
- } ]
339
+ } ] ,
340
+ errorCount : 1 ,
341
+ warningCount : 0
310
342
} ] ;
311
343
312
344
it ( "should return a string without code preview (codeframe)" , ( ) => {
0 commit comments