Skip to content
This repository was archived by the owner on Jun 5, 2020. It is now read-only.

Commit 28b7a61

Browse files
committed
mark deferred tests as skipped in xml report
1 parent 7a10e17 commit 28b7a61

File tree

2 files changed

+134
-47
lines changed

2 files changed

+134
-47
lines changed

lib/reporters/xml.js

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,8 @@
8181
startedAt: new Date().getTime(),
8282
tests: 0,
8383
errors: 0,
84-
failures: 0
84+
failures: 0,
85+
skipped: 0
8586
};
8687

8788
if (this.contexts.length == 0) {
@@ -98,12 +99,12 @@
9899
if (!context || this.contexts.length > 0) {
99100
return;
100101
}
101-
102102
this.suiteTag(context.name, {
103103
tests: this.suite.tests && this.suite.tests.length || 0,
104104
errors: this.suite.errors,
105105
time: elapsedInSec(new Date().getTime() - context.startedAt),
106-
failures: this.suite.failures
106+
failures: this.suite.failures,
107+
skipped: this.suite.skipped
107108
});
108109

109110
this.renderTests(this.suite.tests);
@@ -130,6 +131,12 @@
130131
test.failures.push(testData.error);
131132
},
132133

134+
"test:deferred": function (testData) {
135+
var test = this.completeTest(this.currentTest || this.addTest(testData));
136+
this.suite.skipped += 1;
137+
test.deferred = true;
138+
},
139+
133140
uncaughtException: function (error) {
134141
this.uncaught.push(error);
135142
},
@@ -151,8 +158,11 @@
151158
"\" classname=\"" + tests[i].context +
152159
"\" name=\"" + escape(tests[i].name) + "\"");
153160

154-
if (tests[i].errors.length + tests[i].failures.length > 0) {
161+
if (tests[i].errors.length + tests[i].failures.length > 0 || tests[i].deferred) {
155162
this.write(">\n");
163+
if (tests[i].deferred) {
164+
this.writeln(" <skipped/>");
165+
}
156166
this.renderErrors(tests[i].errors);
157167
this.renderErrors(tests[i].failures);
158168
this.writeln(" </testcase>");
@@ -211,6 +221,7 @@
211221
this.write("\" time=\"" + options.time);
212222
}
213223
this.write("\" failures=\"" + (options.failures || 0) +
224+
"\" skipped=\"" + (options.skipped || 0) +
214225
"\" name=\"" + name + "\">\n");
215226
},
216227

test/reporters/xml-test.js

Lines changed: 119 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ helper.testCase("XMLReporterTest", {
4040
this.runner.emit("context:end", { name: "Context" });
4141

4242
this.assertIO(' <testsuite errors="0" tests="0" ' +
43-
'time="0" failures="0" name="Context">');
43+
'time="0" failures="0" skipped="0" name="Context">');
4444
this.assertIO(' </testsuite>');
4545
},
4646

@@ -58,7 +58,7 @@ helper.testCase("XMLReporterTest", {
5858
this.runner.emit("context:end", { name: "Context" });
5959

6060
this.assertIO('<testsuite errors="0" tests="0" ' +
61-
'time="0.1" failures="0" name="Context">');
61+
'time="0.1" failures="0" skipped="0" name="Context">');
6262
},
6363

6464
"prints total time for each test suite": function () {
@@ -70,9 +70,9 @@ helper.testCase("XMLReporterTest", {
7070
this.runner.emit("context:end", { name: "Context #2" });
7171

7272
this.assertIO('<testsuite errors="0" tests="0" ' +
73-
'time="0.1" failures="0" name="Context">');
73+
'time="0.1" failures="0" skipped="0" name="Context">');
7474
this.assertIO('<testsuite errors="0" tests="0" ' +
75-
'time="0.2" failures="0" name="Context #2">');
75+
'time="0.2" failures="0" skipped="0" name="Context #2">');
7676
},
7777

7878
"prints total time for each test": function () {
@@ -86,9 +86,11 @@ helper.testCase("XMLReporterTest", {
8686
this.runner.emit("context:end", { name: "Context" });
8787

8888
this.assertIO('<testsuite errors="0" tests="2" ' +
89-
'time="0.03" failures="0" name="Context">');
90-
this.assertIO('<testcase time="0.01" classname="Context" name="should #1"/>');
91-
this.assertIO('<testcase time="0.02" classname="Context" name="should #2"/>');
89+
'time="0.03" failures="0" skipped="0" name="Context">');
90+
this.assertIO('<testcase time="0.01" classname="Context" ' +
91+
'name="should #1"/>');
92+
this.assertIO('<testcase time="0.02" classname="Context" ' +
93+
'name="should #2"/>');
9294
},
9395

9496
"adds nested context names to test names": function () {
@@ -101,9 +103,12 @@ helper.testCase("XMLReporterTest", {
101103
this.runner.emit("context:end", { name: "Some behavior" });
102104
this.runner.emit("context:end", { name: "Context" });
103105

104-
this.assertIO('<testsuite errors="0" tests="2" time="0" failures="0" name="Context">');
105-
this.assertIO('<testcase time="0" classname="Context" name="Some behavior should #1"/>');
106-
this.assertIO('<testcase time="0" classname="Context" name="Some behavior should #2"/>');
106+
this.assertIO('<testsuite errors="0" tests="2" time="0" ' +
107+
'failures="0" skipped="0" name="Context">');
108+
this.assertIO('<testcase time="0" classname="Context" ' +
109+
'name="Some behavior should #1"/>');
110+
this.assertIO('<testcase time="0" classname="Context" ' +
111+
'name="Some behavior should #2"/>');
107112
},
108113

109114
"controls number of contexts to keep in classname": function () {
@@ -114,14 +119,17 @@ helper.testCase("XMLReporterTest", {
114119
this.runner.emit("test:start", { name: "should clear form" });
115120
this.runner.emit("test:success", { name: "should clear form" });
116121
this.runner.emit("test:start", { name: "should save item on server" });
117-
this.runner.emit("test:success", { name: "should save item on server" });
122+
this.runner.emit("test:success",
123+
{ name: "should save item on server" });
118124
this.runner.emit("context:end", { name: "add" });
119125
this.runner.emit("context:end", { name: "Form controller" });
120126
this.runner.emit("context:end", { name: "Firefox 4.0 Linux" });
121127

122128
this.assertIO(/<testsuite .* name="Firefox 4.0 Linux">/);
123-
this.assertIO('classname="Firefox 4.0 Linux.Form controller" name="add should clear form"/>');
124-
this.assertIO('classname="Firefox 4.0 Linux.Form controller" name="add should save item on server"/>');
129+
this.assertIO('classname="Firefox 4.0 Linux.Form controller" ' +
130+
'name="add should clear form"/>');
131+
this.assertIO('classname="Firefox 4.0 Linux.Form controller" ' +
132+
'name="add should save item on server"/>');
125133
},
126134

127135
"counts total successful tests": function () {
@@ -133,7 +141,7 @@ helper.testCase("XMLReporterTest", {
133141
this.runner.emit("context:end", { name: "Context" });
134142

135143
this.assertIO('<testsuite errors="0" tests="2" ' +
136-
'time="0" failures="0" name="Context">');
144+
'time="0" failures="0" skipped="0" name="Context">');
137145
},
138146

139147
"counts test errors": function () {
@@ -145,7 +153,7 @@ helper.testCase("XMLReporterTest", {
145153
this.runner.emit("context:end", { name: "Context" });
146154

147155
this.assertIO('<testsuite errors="1" tests="2" ' +
148-
'time="0" failures="0" name="Context">');
156+
'time="0" failures="0" skipped="0" name="Context">');
149157
},
150158

151159
"counts test failures": function () {
@@ -157,7 +165,7 @@ helper.testCase("XMLReporterTest", {
157165
this.runner.emit("context:end", { name: "Context" });
158166

159167
this.assertIO('<testsuite errors="0" tests="2" ' +
160-
'time="0" failures="1" name="Context">');
168+
'time="0" failures="1" skipped="0" name="Context">');
161169
},
162170

163171
"counts test timeout as failure": function () {
@@ -169,7 +177,19 @@ helper.testCase("XMLReporterTest", {
169177
this.runner.emit("context:end", { name: "Context" });
170178

171179
this.assertIO('<testsuite errors="0" tests="2" ' +
172-
'time="0" failures="1" name="Context">');
180+
'time="0" failures="1" skipped="0" name="Context">');
181+
},
182+
183+
"counts deferred tests as skipped": function () {
184+
this.runner.emit("context:start", { name: "Context" });
185+
this.runner.emit("test:start", { name: "#1" });
186+
this.runner.emit("test:success", { name: "#1" });
187+
this.runner.emit("test:start", { name: "#2" });
188+
this.runner.emit("test:deferred", { name: "#2" });
189+
this.runner.emit("context:end", { name: "Context" });
190+
191+
this.assertIO('<testsuite errors="0" tests="2" ' +
192+
'time="0" failures="0" skipped="1" name="Context">');
173193
},
174194

175195
"resets test count per context": function () {
@@ -182,9 +202,9 @@ helper.testCase("XMLReporterTest", {
182202
this.runner.emit("context:end", { name: "Context #2" });
183203

184204
this.assertIO('<testsuite errors="0" tests="2" ' +
185-
'time="0" failures="0" name="Context">');
205+
'time="0" failures="0" skipped="0" name="Context">');
186206
this.assertIO('<testsuite errors="0" tests="1" ' +
187-
'time="0" failures="0" name="Context #2">');
207+
'time="0" failures="0" skipped="0" name="Context #2">');
188208
},
189209

190210
"resets errors and failures count per context": function () {
@@ -200,9 +220,24 @@ helper.testCase("XMLReporterTest", {
200220
this.runner.emit("context:end", { name: "Context #2" });
201221

202222
this.assertIO('<testsuite errors="1" tests="2" ' +
203-
'time="0" failures="1" name="Context">');
223+
'time="0" failures="1" skipped="0" name="Context">');
204224
this.assertIO('<testsuite errors="2" tests="4" ' +
205-
'time="0" failures="2" name="Context #2">');
225+
'time="0" failures="2" skipped="0" name="Context #2">');
226+
},
227+
228+
"resets deferred count per context": function () {
229+
this.runner.emit("context:start", { name: "Context" });
230+
this.runner.emit("test:deferred", { name: "#1" });
231+
this.runner.emit("test:deferred", { name: "#2" });
232+
this.runner.emit("context:end", { name: "Context" });
233+
this.runner.emit("context:start", { name: "Context #2" });
234+
this.runner.emit("test:deferred", { name: "#1" });
235+
this.runner.emit("context:end", { name: "Context #2" });
236+
237+
this.assertIO('<testsuite errors="0" tests="2" ' +
238+
'time="0" failures="0" skipped="2" name="Context">');
239+
this.assertIO('<testsuite errors="0" tests="1" ' +
240+
'time="0" failures="0" skipped="1" name="Context #2">');
206241
},
207242

208243
"does not reset test count for nested context": function () {
@@ -215,8 +250,9 @@ helper.testCase("XMLReporterTest", {
215250
this.runner.emit("context:end", { name: "Context" });
216251

217252
this.assertIO('<testsuite errors="0" tests="3" ' +
218-
'time="0" failures="0" name="Context">');
219-
refute.match(this.outputStream.toString(), /<testsuite[^>]+name="Context #2">/);
253+
'time="0" failures="0" skipped="0" name="Context">');
254+
refute.match(this.outputStream.toString(),
255+
/<testsuite[^>]+name="Context #2">/);
220256
},
221257

222258
"does not reset error and failures count for nested context": function () {
@@ -230,14 +266,32 @@ helper.testCase("XMLReporterTest", {
230266
this.runner.emit("context:end", { name: "Context" });
231267

232268
this.assertIO('<testsuite errors="2" tests="4" ' +
233-
'time="0" failures="2" name="Context">');
234-
refute.match(this.outputStream.toString(), /<testsuite[^>]+name="Context #2">/);
269+
'time="0" failures="2" skipped="0" name="Context">');
270+
refute.match(this.outputStream.toString(),
271+
/<testsuite[^>]+name="Context #2">/);
272+
},
273+
274+
"does not deferred count for nested context": function () {
275+
this.runner.emit("context:start", { name: "Context" });
276+
this.runner.emit("test:deferred", { name: "#1" });
277+
this.runner.emit("test:deferred", { name: "#2" });
278+
this.runner.emit("context:start", { name: "Context #2" });
279+
this.runner.emit("test:deferred", { name: "#1" });
280+
this.runner.emit("test:deferred", { name: "#2" });
281+
this.runner.emit("context:end", { name: "Context #2" });
282+
this.runner.emit("context:end", { name: "Context" });
283+
284+
this.assertIO('<testsuite errors="0" tests="4" ' +
285+
'time="0" failures="0" skipped="4" name="Context">');
286+
refute.match(this.outputStream.toString(),
287+
/<testsuite[^>]+name="Context #2">/);
235288
},
236289

237290
"includes failure element for failed test": function () {
238291
this.runner.emit("context:start", { name: "Context" });
239292
this.runner.emit("test:failure", { name: "#1", error: {
240-
name: "AssertionError", message: "Expected no failure",
293+
name: "AssertionError",
294+
message: "Expected no failure",
241295
stack: "STACK\nSTACK"
242296
} });
243297
this.runner.emit("context:end", { name: "Context" });
@@ -251,11 +305,13 @@ helper.testCase("XMLReporterTest", {
251305
"includes failure element for all failed tests": function () {
252306
this.runner.emit("context:start", { name: "Context" });
253307
this.runner.emit("test:failure", { name: "#1", error: {
254-
name: "AssertionError", message: "Expected no failure",
308+
name: "AssertionError",
309+
message: "Expected no failure",
255310
stack: "STACK\nSTACK"
256311
} });
257312
this.runner.emit("test:failure", { name: "#1", error: {
258-
name: "AssertionError", message: "#2",
313+
name: "AssertionError",
314+
message: "#2",
259315
stack: "stack"
260316
} });
261317
this.runner.emit("context:end", { name: "Context" });
@@ -272,11 +328,13 @@ helper.testCase("XMLReporterTest", {
272328
"includes failure element for all errored tests": function () {
273329
this.runner.emit("context:start", { name: "Context" });
274330
this.runner.emit("test:error", { name: "#1", error: {
275-
name: "TypeError", message: "Expected no failure",
331+
name: "TypeError",
332+
message: "Expected no failure",
276333
stack: "STACK\nSTACK"
277334
} });
278335
this.runner.emit("test:error", { name: "#1", error: {
279-
name: "TypeError", message: "#2",
336+
name: "TypeError",
337+
message: "#2",
280338
stack: "stack"
281339
} });
282340
this.runner.emit("context:end", { name: "Context" });
@@ -290,6 +348,14 @@ helper.testCase("XMLReporterTest", {
290348
"\n </failure>");
291349
},
292350

351+
"includes skipped element for deferred test": function () {
352+
this.runner.emit("context:start", { name: "Context" });
353+
this.runner.emit("test:deferred", { name: "#1" });
354+
this.runner.emit("context:end", { name: "Context" });
355+
356+
this.assertIO(' <skipped/>');
357+
},
358+
293359
"escapes quotes in error message": function () {
294360
this.runner.emit("context:start", { name: "Context" });
295361
this.runner.emit("test:error", { name: "#1", error: {
@@ -298,7 +364,8 @@ helper.testCase("XMLReporterTest", {
298364
}});
299365
this.runner.emit("context:end", { name: "Context" });
300366

301-
this.assertIO('<failure type="Error" message="&quot;Oops&quot; is quoted">');
367+
this.assertIO('<failure type="Error" ' +
368+
'message="&quot;Oops&quot; is quoted">');
302369
},
303370

304371
"escapes brackets and ampersands in error message": function () {
@@ -309,7 +376,8 @@ helper.testCase("XMLReporterTest", {
309376
}});
310377
this.runner.emit("context:end", { name: "Context" });
311378

312-
this.assertIO('<failure type="Error" message="&lt;Oops&gt; &amp; stuff">');
379+
this.assertIO('<failure type="Error" ' +
380+
'message="&lt;Oops&gt; &amp; stuff">');
313381
},
314382

315383
"escapes quotes in test names": function () {
@@ -355,8 +423,10 @@ helper.testCase("XMLReporterTest", {
355423
});
356424
this.runner.emit("suite:end");
357425

358-
this.assertIO("<testsuite errors=\"1\" tests=\"1\" failures=\"0\" name=\"Uncaught exceptions\">");
359-
this.assertIO("<testcase classname=\"Uncaught exception\" time=\"0\" name=\"#1\">");
426+
this.assertIO("<testsuite errors=\"1\" tests=\"1\" failures=\"0\" " +
427+
"skipped=\"0\" name=\"Uncaught exceptions\">");
428+
this.assertIO("<testcase classname=\"Uncaught exception\" time=\"0\" " +
429+
"name=\"#1\">");
360430
this.assertIO('<failure type="TypeError" ' +
361431
'message="Thingamagiggy">' +
362432
"\n STACK\n STACK" +
@@ -369,15 +439,19 @@ helper.testCase("XMLReporterTest", {
369439
});
370440
this.runner.emit("suite:end");
371441

372-
this.assertIO("<testsuite errors=\"1\" tests=\"1\" failures=\"0\" name=\"Uncaught exceptions\">");
373-
this.assertIO("<testcase classname=\"Uncaught exception\" time=\"0\" name=\"#1\">");
374-
this.assertIO('<failure type="Error" message="Thingamagiggy"></failure>');
442+
this.assertIO("<testsuite errors=\"1\" tests=\"1\" failures=\"0\" " +
443+
"skipped=\"0\" name=\"Uncaught exceptions\">");
444+
this.assertIO("<testcase classname=\"Uncaught exception\" time=\"0\" " +
445+
"name=\"#1\">");
446+
this.assertIO('<failure type="Error" message="Thingamagiggy">' +
447+
'</failure>');
375448
},
376449

377-
"does not include element for uncaught exceptions when there are none": function () {
378-
this.runner.emit("suite:end");
379-
refute.match(this.outputStream.toString(), "Uncaught exceptions");
380-
},
450+
"does not include element for uncaught exceptions when there are none":
451+
function () {
452+
this.runner.emit("suite:end");
453+
refute.match(this.outputStream.toString(), "Uncaught exceptions");
454+
},
381455

382456
"does not produce invalid xml for uncaught exceptions": function () {
383457
this.runner.emit("uncaughtException", {
@@ -392,8 +466,10 @@ helper.testCase("XMLReporterTest", {
392466
this.runner.emit("suite:error", new Error("Borked test suite"));
393467
this.runner.emit("suite:end");
394468

395-
this.assertIO("<testsuite errors=\"1\" tests=\"1\" failures=\"0\" name=\"Uncaught exceptions\">");
396-
this.assertIO("<testcase classname=\"Uncaught exception\" time=\"0\" name=\"#1\">");
469+
this.assertIO("<testsuite errors=\"1\" tests=\"1\" failures=\"0\" " +
470+
"skipped=\"0\" name=\"Uncaught exceptions\">");
471+
this.assertIO("<testcase classname=\"Uncaught exception\" time=\"0\" " +
472+
"name=\"#1\">");
397473
this.assertIO('<failure type="Error" message="Borked test suite">');
398474
}
399475
});

0 commit comments

Comments
 (0)