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

Commit

Permalink
mark deferred tests as skipped in xml report
Browse files Browse the repository at this point in the history
  • Loading branch information
dwittner committed Dec 16, 2014
1 parent 7a10e17 commit 28b7a61
Show file tree
Hide file tree
Showing 2 changed files with 134 additions and 47 deletions.
19 changes: 15 additions & 4 deletions lib/reporters/xml.js
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,8 @@
startedAt: new Date().getTime(),
tests: 0,
errors: 0,
failures: 0
failures: 0,
skipped: 0
};

if (this.contexts.length == 0) {
Expand All @@ -98,12 +99,12 @@
if (!context || this.contexts.length > 0) {
return;
}

this.suiteTag(context.name, {
tests: this.suite.tests && this.suite.tests.length || 0,
errors: this.suite.errors,
time: elapsedInSec(new Date().getTime() - context.startedAt),
failures: this.suite.failures
failures: this.suite.failures,
skipped: this.suite.skipped
});

this.renderTests(this.suite.tests);
Expand All @@ -130,6 +131,12 @@
test.failures.push(testData.error);
},

"test:deferred": function (testData) {
var test = this.completeTest(this.currentTest || this.addTest(testData));
this.suite.skipped += 1;
test.deferred = true;
},

uncaughtException: function (error) {
this.uncaught.push(error);
},
Expand All @@ -151,8 +158,11 @@
"\" classname=\"" + tests[i].context +
"\" name=\"" + escape(tests[i].name) + "\"");

if (tests[i].errors.length + tests[i].failures.length > 0) {
if (tests[i].errors.length + tests[i].failures.length > 0 || tests[i].deferred) {
this.write(">\n");
if (tests[i].deferred) {
this.writeln(" <skipped/>");
}
this.renderErrors(tests[i].errors);
this.renderErrors(tests[i].failures);
this.writeln(" </testcase>");
Expand Down Expand Up @@ -211,6 +221,7 @@
this.write("\" time=\"" + options.time);
}
this.write("\" failures=\"" + (options.failures || 0) +
"\" skipped=\"" + (options.skipped || 0) +
"\" name=\"" + name + "\">\n");
},

Expand Down
162 changes: 119 additions & 43 deletions test/reporters/xml-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ helper.testCase("XMLReporterTest", {
this.runner.emit("context:end", { name: "Context" });

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

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

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

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

this.assertIO('<testsuite errors="0" tests="0" ' +
'time="0.1" failures="0" name="Context">');
'time="0.1" failures="0" skipped="0" name="Context">');
this.assertIO('<testsuite errors="0" tests="0" ' +
'time="0.2" failures="0" name="Context #2">');
'time="0.2" failures="0" skipped="0" name="Context #2">');
},

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

this.assertIO('<testsuite errors="0" tests="2" ' +
'time="0.03" failures="0" name="Context">');
this.assertIO('<testcase time="0.01" classname="Context" name="should #1"/>');
this.assertIO('<testcase time="0.02" classname="Context" name="should #2"/>');
'time="0.03" failures="0" skipped="0" name="Context">');
this.assertIO('<testcase time="0.01" classname="Context" ' +
'name="should #1"/>');
this.assertIO('<testcase time="0.02" classname="Context" ' +
'name="should #2"/>');
},

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

this.assertIO('<testsuite errors="0" tests="2" time="0" failures="0" name="Context">');
this.assertIO('<testcase time="0" classname="Context" name="Some behavior should #1"/>');
this.assertIO('<testcase time="0" classname="Context" name="Some behavior should #2"/>');
this.assertIO('<testsuite errors="0" tests="2" time="0" ' +
'failures="0" skipped="0" name="Context">');
this.assertIO('<testcase time="0" classname="Context" ' +
'name="Some behavior should #1"/>');
this.assertIO('<testcase time="0" classname="Context" ' +
'name="Some behavior should #2"/>');
},

"controls number of contexts to keep in classname": function () {
Expand All @@ -114,14 +119,17 @@ helper.testCase("XMLReporterTest", {
this.runner.emit("test:start", { name: "should clear form" });
this.runner.emit("test:success", { name: "should clear form" });
this.runner.emit("test:start", { name: "should save item on server" });
this.runner.emit("test:success", { name: "should save item on server" });
this.runner.emit("test:success",
{ name: "should save item on server" });
this.runner.emit("context:end", { name: "add" });
this.runner.emit("context:end", { name: "Form controller" });
this.runner.emit("context:end", { name: "Firefox 4.0 Linux" });

this.assertIO(/<testsuite .* name="Firefox 4.0 Linux">/);
this.assertIO('classname="Firefox 4.0 Linux.Form controller" name="add should clear form"/>');
this.assertIO('classname="Firefox 4.0 Linux.Form controller" name="add should save item on server"/>');
this.assertIO('classname="Firefox 4.0 Linux.Form controller" ' +
'name="add should clear form"/>');
this.assertIO('classname="Firefox 4.0 Linux.Form controller" ' +
'name="add should save item on server"/>');
},

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

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

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

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

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

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

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

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

"counts deferred tests as skipped": function () {
this.runner.emit("context:start", { name: "Context" });
this.runner.emit("test:start", { name: "#1" });
this.runner.emit("test:success", { name: "#1" });
this.runner.emit("test:start", { name: "#2" });
this.runner.emit("test:deferred", { name: "#2" });
this.runner.emit("context:end", { name: "Context" });

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

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

this.assertIO('<testsuite errors="0" tests="2" ' +
'time="0" failures="0" name="Context">');
'time="0" failures="0" skipped="0" name="Context">');
this.assertIO('<testsuite errors="0" tests="1" ' +
'time="0" failures="0" name="Context #2">');
'time="0" failures="0" skipped="0" name="Context #2">');
},

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

this.assertIO('<testsuite errors="1" tests="2" ' +
'time="0" failures="1" name="Context">');
'time="0" failures="1" skipped="0" name="Context">');
this.assertIO('<testsuite errors="2" tests="4" ' +
'time="0" failures="2" name="Context #2">');
'time="0" failures="2" skipped="0" name="Context #2">');
},

"resets deferred count per context": function () {
this.runner.emit("context:start", { name: "Context" });
this.runner.emit("test:deferred", { name: "#1" });
this.runner.emit("test:deferred", { name: "#2" });
this.runner.emit("context:end", { name: "Context" });
this.runner.emit("context:start", { name: "Context #2" });
this.runner.emit("test:deferred", { name: "#1" });
this.runner.emit("context:end", { name: "Context #2" });

this.assertIO('<testsuite errors="0" tests="2" ' +
'time="0" failures="0" skipped="2" name="Context">');
this.assertIO('<testsuite errors="0" tests="1" ' +
'time="0" failures="0" skipped="1" name="Context #2">');
},

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

this.assertIO('<testsuite errors="0" tests="3" ' +
'time="0" failures="0" name="Context">');
refute.match(this.outputStream.toString(), /<testsuite[^>]+name="Context #2">/);
'time="0" failures="0" skipped="0" name="Context">');
refute.match(this.outputStream.toString(),
/<testsuite[^>]+name="Context #2">/);
},

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

this.assertIO('<testsuite errors="2" tests="4" ' +
'time="0" failures="2" name="Context">');
refute.match(this.outputStream.toString(), /<testsuite[^>]+name="Context #2">/);
'time="0" failures="2" skipped="0" name="Context">');
refute.match(this.outputStream.toString(),
/<testsuite[^>]+name="Context #2">/);
},

"does not deferred count for nested context": function () {
this.runner.emit("context:start", { name: "Context" });
this.runner.emit("test:deferred", { name: "#1" });
this.runner.emit("test:deferred", { name: "#2" });
this.runner.emit("context:start", { name: "Context #2" });
this.runner.emit("test:deferred", { name: "#1" });
this.runner.emit("test:deferred", { name: "#2" });
this.runner.emit("context:end", { name: "Context #2" });
this.runner.emit("context:end", { name: "Context" });

this.assertIO('<testsuite errors="0" tests="4" ' +
'time="0" failures="0" skipped="4" name="Context">');
refute.match(this.outputStream.toString(),
/<testsuite[^>]+name="Context #2">/);
},

"includes failure element for failed test": function () {
this.runner.emit("context:start", { name: "Context" });
this.runner.emit("test:failure", { name: "#1", error: {
name: "AssertionError", message: "Expected no failure",
name: "AssertionError",
message: "Expected no failure",
stack: "STACK\nSTACK"
} });
this.runner.emit("context:end", { name: "Context" });
Expand All @@ -251,11 +305,13 @@ helper.testCase("XMLReporterTest", {
"includes failure element for all failed tests": function () {
this.runner.emit("context:start", { name: "Context" });
this.runner.emit("test:failure", { name: "#1", error: {
name: "AssertionError", message: "Expected no failure",
name: "AssertionError",
message: "Expected no failure",
stack: "STACK\nSTACK"
} });
this.runner.emit("test:failure", { name: "#1", error: {
name: "AssertionError", message: "#2",
name: "AssertionError",
message: "#2",
stack: "stack"
} });
this.runner.emit("context:end", { name: "Context" });
Expand All @@ -272,11 +328,13 @@ helper.testCase("XMLReporterTest", {
"includes failure element for all errored tests": function () {
this.runner.emit("context:start", { name: "Context" });
this.runner.emit("test:error", { name: "#1", error: {
name: "TypeError", message: "Expected no failure",
name: "TypeError",
message: "Expected no failure",
stack: "STACK\nSTACK"
} });
this.runner.emit("test:error", { name: "#1", error: {
name: "TypeError", message: "#2",
name: "TypeError",
message: "#2",
stack: "stack"
} });
this.runner.emit("context:end", { name: "Context" });
Expand All @@ -290,6 +348,14 @@ helper.testCase("XMLReporterTest", {
"\n </failure>");
},

"includes skipped element for deferred test": function () {
this.runner.emit("context:start", { name: "Context" });
this.runner.emit("test:deferred", { name: "#1" });
this.runner.emit("context:end", { name: "Context" });

this.assertIO(' <skipped/>');
},

"escapes quotes in error message": function () {
this.runner.emit("context:start", { name: "Context" });
this.runner.emit("test:error", { name: "#1", error: {
Expand All @@ -298,7 +364,8 @@ helper.testCase("XMLReporterTest", {
}});
this.runner.emit("context:end", { name: "Context" });

this.assertIO('<failure type="Error" message="&quot;Oops&quot; is quoted">');
this.assertIO('<failure type="Error" ' +
'message="&quot;Oops&quot; is quoted">');
},

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

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

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

this.assertIO("<testsuite errors=\"1\" tests=\"1\" failures=\"0\" name=\"Uncaught exceptions\">");
this.assertIO("<testcase classname=\"Uncaught exception\" time=\"0\" name=\"#1\">");
this.assertIO("<testsuite errors=\"1\" tests=\"1\" failures=\"0\" " +
"skipped=\"0\" name=\"Uncaught exceptions\">");
this.assertIO("<testcase classname=\"Uncaught exception\" time=\"0\" " +
"name=\"#1\">");
this.assertIO('<failure type="TypeError" ' +
'message="Thingamagiggy">' +
"\n STACK\n STACK" +
Expand All @@ -369,15 +439,19 @@ helper.testCase("XMLReporterTest", {
});
this.runner.emit("suite:end");

this.assertIO("<testsuite errors=\"1\" tests=\"1\" failures=\"0\" name=\"Uncaught exceptions\">");
this.assertIO("<testcase classname=\"Uncaught exception\" time=\"0\" name=\"#1\">");
this.assertIO('<failure type="Error" message="Thingamagiggy"></failure>');
this.assertIO("<testsuite errors=\"1\" tests=\"1\" failures=\"0\" " +
"skipped=\"0\" name=\"Uncaught exceptions\">");
this.assertIO("<testcase classname=\"Uncaught exception\" time=\"0\" " +
"name=\"#1\">");
this.assertIO('<failure type="Error" message="Thingamagiggy">' +
'</failure>');
},

"does not include element for uncaught exceptions when there are none": function () {
this.runner.emit("suite:end");
refute.match(this.outputStream.toString(), "Uncaught exceptions");
},
"does not include element for uncaught exceptions when there are none":
function () {
this.runner.emit("suite:end");
refute.match(this.outputStream.toString(), "Uncaught exceptions");
},

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

this.assertIO("<testsuite errors=\"1\" tests=\"1\" failures=\"0\" name=\"Uncaught exceptions\">");
this.assertIO("<testcase classname=\"Uncaught exception\" time=\"0\" name=\"#1\">");
this.assertIO("<testsuite errors=\"1\" tests=\"1\" failures=\"0\" " +
"skipped=\"0\" name=\"Uncaught exceptions\">");
this.assertIO("<testcase classname=\"Uncaught exception\" time=\"0\" " +
"name=\"#1\">");
this.assertIO('<failure type="Error" message="Borked test suite">');
}
});

0 comments on commit 28b7a61

Please sign in to comment.