-
Notifications
You must be signed in to change notification settings - Fork 24
/
formatter.test.js
112 lines (110 loc) · 2.65 KB
/
formatter.test.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
const formatter = require('./formatter');
const stripAnsi = require('strip-ansi');
const strippedFormatter = (...args) => stripAnsi(formatter(...args));
describe('formatter', () => {
it('returns an empty string when there aren\'t any warnings or errors across all files', () => {
expect(strippedFormatter([
{
filePath: 'some/file',
messages: [],
warningCount: 0,
errorCount: 0
}
])).toMatchSnapshot();
});
it('will not display any message for an individual file which does not have any warnings or errors', () => {
const output = strippedFormatter([
{
filePath: 'bad/file',
messages: [{
ruleId: 'some-rule',
severity: 2,
message: 'file is bad'
}],
errorCount: 1,
warningCount: 0
},
{
filePath: 'good/file',
messages: [],
warningCount: 0,
errorCount: 0
}
]);
expect(output).toMatchSnapshot();
});
it('will display errors before warnings', () => {
const output = strippedFormatter([
{
filePath: 'bad/file',
messages: [
{
ruleId: 'some-rule',
severity: 1,
message: 'file has first warning'
},
{
ruleId: 'some-rule',
severity: 1,
message: 'file has second warning'
},
{
ruleId: 'some-rule',
severity: 2,
message: 'file is bad'
},
{
ruleId: 'some-rule',
severity: 2,
message: 'file is pretty bad'
}
],
errorCount: 2,
warningCount: 2
}
]);
expect(output).toMatchSnapshot();
});
it('will display issues across many files', () => {
const output = strippedFormatter([
{
filePath: 'bad/file',
messages: [{
ruleId: 'some-rule',
severity: 2,
message: 'file is bad'
}],
errorCount: 1,
warningCount: 0
},
{
filePath: 'bad/file2',
messages: [{
ruleId: 'some-rule',
severity: 1,
message: 'file has a warning'
}],
errorCount: 0,
warningCount: 1
},
{
filePath: 'bad/file3',
messages: [
{
ruleId: 'some-rule',
severity: 2,
message: 'file is bad'
},
{
ruleId: 'some-rule',
severity: 1,
message: 'file has a warning'
}
],
errorCount: 1,
warningCount: 1
}
]);
expect(output).toMatchSnapshot();
});
});