-
Notifications
You must be signed in to change notification settings - Fork 1
/
test.js
118 lines (101 loc) · 3.88 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
import test from 'ava';
import { stdout, } from 'test-console';
import reporter from './';
const fixture = [
{
getFilename: () => "C:\\js\\warnings.js",
getErrorList: () => [
{
rule: "requirePaddingNewLinesAfterBlocks",
message: "requirePaddingNewLinesAfterBlocks: Missing newline after block",
fixed: false,
line: 238,
column: 9,
},
{
rule: "requireDollarBeforejQueryAssignment",
message: "requireDollarBeforejQueryAssignment: jQuery identifiers must start with a $",
fixed: false,
line: 47,
column: 18,
}, ],
getErrorCount: () => 2,
isEmpty: () => false,
}, {
getFilename: () => "C:\\js\\more-warnings.js",
getErrorList: () => [
{
rule: "disallowMultipleSpaces",
message: "disallowMultipleSpaces: at most 1 spaces required between $ and (",
fixed: false,
line: 31,
column: 26,
},
{
rule: "disallowSpacesInCallExpression",
message: "disallowSpacesInCallExpression: Illegal space before opening round brace",
fixed: false,
line: 31,
column: 26,
}, {
rule: "disallowSpacesInsideParentheses",
message: "disallowSpacesInsideParentheses: Illegal space after opening round bracket",
fixed: false,
line: 31,
column: 29,
},
],
getErrorCount: () => 3,
isEmpty: () => false,
}, {
getFilename: () => "C:\\js\\good.js",
getErrorList: () => [],
getErrorCount: () => 0,
isEmpty: () => true,
},
];
test('Given no results, logs nothing', (assert) => {
const { restore, output, } = stdout.inspect();
const results = [];
reporter(results);
restore();
assert.is(output.join('').trim(), '');
});
test('Given results with no messages, logs nothing', (assert) => {
const { restore, output, } = stdout.inspect();
const results = [{
getFilename: () => 'tmp/good.js',
getErrorList: () => [],
getErrorCount: () => 0,
isEmpty: () => true,
}, {
getFilename: () => 'tmp/good2.js',
getErrorList: () => [],
getErrorCount: () => 0,
isEmpty: () => true,
}, ];
reporter(results)
restore();
assert.is(output.join('').trim(), '');
});
test('Given results with issues, logs warnings by default', (assert) => {
const { restore, output, } = stdout.inspect();
reporter(fixture);
restore();
assert.regex(output.join('').trim(), /##vso\[task\.logissue type=warning/);
});
test('Given results with issues, logs errors if specified', (assert) => {
const { restore, output, } = stdout.inspect();
reporter(fixture, { severity: 'error' });
restore();
assert.regex(output.join('').trim(), /##vso\[task\.logissue type=error/);
});
test('Given results with 5 issues, logs 5 issues in valid format', (assert) => {
const { restore, output, } = stdout.inspect();
reporter(fixture);
restore();
assert.regex(output.join('').trim(), /^(?:##vso\[task\.logissue ((?:type|sourcepath|linenumber|columnnumber|code)=[^;]+;)+\][^\n]+(?:\n|$)){4,5}$/);
assert.regex(output.join('').trim(), /^(?:##vso\[task\.logissue ((?:type|sourcepath|linenumber|columnnumber|code)=[^;]+;)+\][^\n]+(?:\n|$)){5,6}$/);
assert.notRegex(output.join('').trim(), /^(?:##vso\[task\.logissue ((?:type|sourcepath|linenumber|columnnumber|code)=[^;]+;)+\][^\n]+(?:\n|$)){3,4}$/);
assert.notRegex(output.join('').trim(), /^(?:##vso\[task\.logissue ((?:type|sourcepath|linenumber|columnnumber|code)=[^;]+;)+\][^\n]+(?:\n|$)){6,7}$/);
});