forked from eslint/eslint
-
Notifications
You must be signed in to change notification settings - Fork 0
/
junit.js
193 lines (155 loc) · 7.46 KB
/
junit.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
/**
* @fileoverview Tests for jUnit Formatter.
* @author Jamund Ferguson
*/
/*jshint node:true*/
//------------------------------------------------------------------------------
// Requirements
//------------------------------------------------------------------------------
var vows = require("vows"),
assert = require("assert"),
sinon = require("sinon"),
formatter = require("../../../lib/formatters/junit");
//------------------------------------------------------------------------------
// Tests
//------------------------------------------------------------------------------
vows.describe("formatter:junit").addBatch({
"when there are no problems": {
topic: [],
"should not complain about anything": function(topic) {
var config = {}; // not needed for this test
var result = formatter(topic, config);
assert.equal('<?xml version="1.0" encoding="utf-8"?><testsuites></testsuites>', result.replace(/\n/g, ""));
}
},
"when passed a single message": {
topic: [{
filePath: "foo.js",
messages: [{
message: "Unexpected foo.",
line: 5,
column: 10,
ruleId: "foo"
}]
}],
"should return a single <testcase> with a message and the line and col number in the body (error)": function(topic) {
var config = {
rules: { foo: 2 }
};
var result = formatter(topic, config);
assert.equal('<?xml version="1.0" encoding="utf-8"?><testsuites><testsuite package="org.eslint" time="0" tests="1" errors="1" name="foo.js"><testcase time="0" name="org.eslint.foo"><failure message="Unexpected foo."><![CDATA[line 5, col 10, Error - Unexpected foo.]]></failure></testcase></testsuite></testsuites>', result.replace(/\n/g, ""));
},
"should return a single <testcase> with a message and the line and col number in the body (warning)": function(topic) {
var config = {
rules: { foo: 1 }
};
var result = formatter(topic, config);
assert.equal('<?xml version="1.0" encoding="utf-8"?><testsuites><testsuite package="org.eslint" time="0" tests="1" errors="1" name="foo.js"><testcase time="0" name="org.eslint.foo"><failure message="Unexpected foo."><![CDATA[line 5, col 10, Warning - Unexpected foo.]]></failure></testcase></testsuite></testsuites>', result.replace(/\n/g, ""));
}
},
"when passed a fatal error message": {
topic: [{
filePath: "foo.js",
messages: [{
fatal: true,
message: "Unexpected foo.",
line: 5,
column: 10,
ruleId: "foo"
}]
}],
"should return a single <testcase> and an <error>": function(topic) {
var config = {};
var result = formatter(topic, config);
assert.equal('<?xml version="1.0" encoding="utf-8"?><testsuites><testsuite package="org.eslint" time="0" tests="1" errors="1" name="foo.js"><testcase time="0" name="org.eslint.foo"><error message="Unexpected foo."><![CDATA[line 5, col 10, Error - Unexpected foo.]]></error></testcase></testsuite></testsuites>', result.replace(/\n/g, ""));
}
},
"when passed multiple messages": {
topic: [{
filePath: "foo.js",
messages: [{
message: "Unexpected foo.",
line: 5,
column: 10,
ruleId: "foo"
}, {
message: "Unexpected bar.",
line: 6,
column: 11,
ruleId: "bar"
}]
}],
"should return a multiple <testcase>'s": function(topic) {
var config = {
rules: { foo: 2, bar: 1 }
};
var result = formatter(topic, config);
assert.equal('<?xml version="1.0" encoding="utf-8"?><testsuites><testsuite package="org.eslint" time="0" tests="2" errors="2" name="foo.js"><testcase time="0" name="org.eslint.foo"><failure message="Unexpected foo."><![CDATA[line 5, col 10, Error - Unexpected foo.]]></failure></testcase><testcase time="0" name="org.eslint.bar"><failure message="Unexpected bar."><![CDATA[line 6, col 11, Warning - Unexpected bar.]]></failure></testcase></testsuite></testsuites>', result.replace(/\n/g, ""));
}
},
"when passed special characters": {
topic: [{
filePath: "foo.js",
messages: [{
message: "Unexpected <foo></foo>.",
line: 5,
column: 10,
ruleId: "foo"
}]
}],
"should make them go away": function(topic) {
var config = {
rules: { foo: 1 }
};
var result = formatter(topic, config);
assert.equal('<?xml version="1.0" encoding="utf-8"?><testsuites><testsuite package="org.eslint" time="0" tests="1" errors="1" name="foo.js"><testcase time="0" name="org.eslint.foo"><failure message="Unexpected <foo></foo>."><![CDATA[line 5, col 10, Warning - Unexpected <foo></foo>.]]></failure></testcase></testsuite></testsuites>', result.replace(/\n/g, ""));
}
},
"when passed multiple files with 1 message each": {
topic: [{
filePath: "foo.js",
messages: [{
message: "Unexpected foo.",
line: 5,
column: 10,
ruleId: "foo"
}]
}, {
filePath: "bar.js",
messages: [{
message: "Unexpected bar.",
line: 6,
column: 11,
ruleId: "bar"
}]
}],
"should return 2 <testsuite>'s": function(topic) {
var config = {
rules: { foo: 1, bar: 2 }
};
var result = formatter(topic, config);
assert.equal('<?xml version="1.0" encoding="utf-8"?><testsuites><testsuite package="org.eslint" time="0" tests="1" errors="1" name="foo.js"><testcase time="0" name="org.eslint.foo"><failure message="Unexpected foo."><![CDATA[line 5, col 10, Warning - Unexpected foo.]]></failure></testcase></testsuite><testsuite package="org.eslint" time="0" tests="1" errors="1" name="bar.js"><testcase time="0" name="org.eslint.bar"><failure message="Unexpected bar."><![CDATA[line 6, col 11, Error - Unexpected bar.]]></failure></testcase></testsuite></testsuites>', result.replace(/\n/g, ""));
}
},
"when passed multiple files with total 1 failure": {
topic: [{
filePath: "foo.js",
messages: [{
message: "Unexpected foo.",
line: 5,
column: 10,
ruleId: "foo"
}]
}, {
filePath: "bar.js",
messages: []
}],
"should return 1 <testsuite>'": function(topic) {
var config = {
rules: { foo: 1, bar: 2 }
};
var result = formatter(topic, config);
assert.equal('<?xml version="1.0" encoding="utf-8"?><testsuites><testsuite package="org.eslint" time="0" tests="1" errors="1" name="foo.js"><testcase time="0" name="org.eslint.foo"><failure message="Unexpected foo."><![CDATA[line 5, col 10, Warning - Unexpected foo.]]></failure></testcase></testsuite></testsuites>', result.replace(/\n/g, ""));
}
}
}).export(module);