-
Notifications
You must be signed in to change notification settings - Fork 2
/
test.js
215 lines (203 loc) · 4.85 KB
/
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
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
const test = require('ava');
const formatter = require('./');
const fixtureWarnings = {
filePath: 'C:\\js\\warnings.js',
messages: [
{
ruleId: 'prefer-const',
severity: 1,
message:
"'initialNavHeight' is never reassigned. Use 'const' instead.",
line: 22,
column: 9,
nodeType: 'Identifier',
source: ' initialNavHeight = $mainNavMenu.outerHeight();',
},
{
ruleId: 'consistent-return',
severity: 1,
message: 'Expected to return a value at the end of this function.',
line: 76,
column: 14,
nodeType: 'FunctionDeclaration',
source: ' function hideSubmenu(menuItem) {',
},
{
ruleId: 'eqeqeq',
severity: 1,
message: "Expected '===' and instead saw '=='.",
line: 234,
column: 25,
nodeType: 'BinaryExpression',
source: ' if (parentLevel == 1) {',
},
],
errorCount: 0,
warningCount: 3,
};
const fixture = [
fixtureWarnings,
{
filePath: 'C:\\js\\errors.js',
messages: [
{
ruleId: 'no-unused-vars',
severity: 2,
message: "'$' is defined but never used",
line: 2,
column: 26,
nodeType: 'Identifier',
source: 'void function themeStart($) {',
},
{
ruleId: 'no-constant-condition',
severity: 2,
message: 'Unexpected constant condition.',
line: 5,
column: 5,
nodeType: 'IfStatement',
source: ' if (x = 10) {',
},
{
ruleId: 'no-cond-assign',
severity: 2,
message:
'Expected a conditional expression and instead saw an assignment.',
line: 5,
column: 9,
nodeType: 'IfStatement',
source: ' if (x = 10) {',
},
{
ruleId: 'no-undef',
severity: 2,
message: "'x' is not defined.",
line: 5,
column: 9,
nodeType: 'Identifier',
source: ' if (x = 10) {',
},
],
errorCount: 4,
warningCount: 0,
},
{
filePath: 'C:\\js\\good.js',
messages: [],
errorCount: 0,
warningCount: 0,
},
];
test('Given no results, logs nothing', (t) => {
const results = [];
t.is(formatter(results), '');
});
test('Given results with no messages, logs nothing', (t) => {
const results = [
{
filePath: 'tmp/good.js',
messages: [],
errorCount: 0,
warningCount: 0,
},
{
filePath: 'tmp/good2.js',
messages: [],
errorCount: 0,
warningCount: 0,
},
];
t.is(formatter(results), '');
});
test('Given results with errors, logs errors', (t) => {
t.regex(formatter(fixture), /##vso\[task\.logissue type=error/);
});
test('Given results with warnings, logs warnings', (t) => {
t.regex(formatter(fixture), /##vso\[task\.logissue type=warning/);
});
test('Given results with 7 issues, logs 7 issues in valid format', (t) => {
t.regex(
formatter(fixture),
/^(?:##vso\[task\.logissue ((?:type|sourcepath|linenumber|columnnumber|code)=[^;]+;)+\][^\n]+(?:\n|$)){6,7}$/
);
t.regex(
formatter(fixture),
/^(?:##vso\[task\.logissue ((?:type|sourcepath|linenumber|columnnumber|code)=[^;]+;)+\][^\n]+(?:\n|$)){7,8}$/
);
t.notRegex(
formatter(fixture),
/^(?:##vso\[task\.logissue ((?:type|sourcepath|linenumber|columnnumber|code)=[^;]+;)+\][^\n]+(?:\n|$)){5,6}$/
);
t.notRegex(
formatter(fixture),
/^(?:##vso\[task\.logissue ((?:type|sourcepath|linenumber|columnnumber|code)=[^;]+;)+\][^\n]+(?:\n|$)){8,9}$/
);
});
test('Given results meta, logs too many warnings error', (t) => {
t.regex(
formatter([], {
maxWarningsExceeded: {
maxWarnings: 7,
foundWarnings: 9,
},
}),
/##vso\[task.logissue type=error;\]ESLint found too many warnings \(maximum: 7, found: 9\)\./
);
const regex = /ESLint found too many warnings/gis;
t.notRegex(formatter(fixture), regex);
t.notRegex(
formatter([], {
maxWarningsExceeded: {
maxWarnings: 12,
foundWarnings: 9,
},
}),
regex
);
t.notRegex(
formatter([], {
maxWarningsExceeded: {
maxWarnings: 9,
foundWarnings: 9,
},
}),
regex
);
});
test('Does not log task complete without configuration', (t) => {
t.notRegex(formatter([]), /##vso\[task.complete result=/);
t.notRegex(formatter(fixture), /##vso\[task.complete result=/);
t.notRegex(formatter([fixtureWarnings]), /##vso\[task.complete result=/);
t.notRegex(
formatter([], {
maxWarningsExceeded: {
maxWarnings: 7,
foundWarnings: 9,
},
}),
/##vso\[task.complete result=/
);
});
test('Logs task complete with configuration', (t) => {
const shouldLogTaskComplete = formatter.shouldLogTaskComplete;
formatter.shouldLogTaskComplete = () => true;
try {
t.notRegex(formatter([]), /##vso\[task.complete result=/);
t.regex(formatter(fixture), /##vso\[task.complete result=Failed;\]/);
t.regex(
formatter([fixtureWarnings]),
/##vso\[task.complete result=SucceededWithIssues;\]/
);
t.regex(
formatter([], {
maxWarningsExceeded: {
maxWarnings: 7,
foundWarnings: 9,
},
}),
/##vso\[task.complete result=Failed;\]/
);
} finally {
formatter.shouldLogTaskComplete = shouldLogTaskComplete;
}
});