Support pending specs with:
- xit
- it with a null function body ( it("should be pending");
- calling pending() inside a spec
- having a spec without any expectations
Pending and Filtered specs now call Reporter interface specStarted so that reporting acts as expected.
Pending and Filtered spec names are present and styled in the HTML reporter
Using xit used to disable a spec. Disabling is now just when a spec is filtered out at run time (usually w/ the reporter).
Suites are still disabled with xdescribe and means its specs are never executed.
This commit is contained in:
@@ -7,6 +7,7 @@ jasmine.ConsoleReporter = function(options) {
|
||||
specCount,
|
||||
failureCount,
|
||||
failedSpecs = [],
|
||||
pendingCount,
|
||||
ansi = {
|
||||
green: '\033[32m',
|
||||
red: '\033[31m',
|
||||
@@ -18,6 +19,7 @@ jasmine.ConsoleReporter = function(options) {
|
||||
startTime = now();
|
||||
specCount = 0;
|
||||
failureCount = 0;
|
||||
pendingCount = 0;
|
||||
print("Started");
|
||||
printNewline();
|
||||
};
|
||||
@@ -33,6 +35,11 @@ jasmine.ConsoleReporter = function(options) {
|
||||
printNewline();
|
||||
var specCounts = specCount + " " + plural("spec", specCount) + ", " +
|
||||
failureCount + " " + plural("failure", failureCount);
|
||||
|
||||
if (pendingCount) {
|
||||
specCounts += ", " + pendingCount + " pending " + plural("spec", pendingCount);
|
||||
}
|
||||
|
||||
print(specCounts);
|
||||
|
||||
printNewline();
|
||||
@@ -47,6 +54,12 @@ jasmine.ConsoleReporter = function(options) {
|
||||
this.specDone = function(result) {
|
||||
specCount++;
|
||||
|
||||
if(result.status == "pending") {
|
||||
pendingCount++;
|
||||
print(colored("yellow", "*"));
|
||||
return;
|
||||
}
|
||||
|
||||
if (result.status == "passed") {
|
||||
print(colored("green", '.'));
|
||||
return;
|
||||
@@ -97,7 +110,7 @@ jasmine.ConsoleReporter = function(options) {
|
||||
for (var i = 0; i < result.failedExpectations.length; i++) {
|
||||
var failedExpectation = result.failedExpectations[i];
|
||||
printNewline();
|
||||
print(indent(failedExpectation.trace.stack, 2));
|
||||
print(indent(failedExpectation.stack, 2));
|
||||
}
|
||||
|
||||
printNewline();
|
||||
|
||||
@@ -97,6 +97,10 @@
|
||||
return catchExceptions;
|
||||
};
|
||||
|
||||
this.catchException = function(e){
|
||||
return jasmine.Spec.isPendingSpecException(e) || catchExceptions;
|
||||
};
|
||||
|
||||
var maximumSpecCallbackDepth = 100;
|
||||
var currentSpecCallbackDepth = 0;
|
||||
|
||||
@@ -111,13 +115,12 @@
|
||||
}
|
||||
|
||||
var queueRunnerFactory = function(options) {
|
||||
options.catchingExceptions = self.catchingExceptions;
|
||||
options.catchException = self.catchException;
|
||||
options.encourageGC = options.encourageGarbageCollection || encourageGarbageCollection;
|
||||
|
||||
new jasmine.QueueRunner(options).run(options.fns, 0);
|
||||
};
|
||||
|
||||
|
||||
var totalSpecsDefined = 0;
|
||||
this.specFactory = function(description, fn, suite) {
|
||||
totalSpecsDefined++;
|
||||
@@ -322,7 +325,7 @@
|
||||
// TODO: move this to closure
|
||||
jasmine.Env.prototype.xit = function(description, fn) {
|
||||
var spec = this.it(description, fn);
|
||||
spec.disable();
|
||||
spec.pend();
|
||||
return spec;
|
||||
};
|
||||
|
||||
@@ -336,6 +339,11 @@
|
||||
this.currentSuite.afterEach(afterEachFunction);
|
||||
};
|
||||
|
||||
// TODO: move this to closure
|
||||
jasmine.Env.prototype.pending = function() {
|
||||
throw new Error(jasmine.Spec.pendingSpecExceptionMessage);
|
||||
};
|
||||
|
||||
// TODO: Still needed?
|
||||
jasmine.Env.prototype.currentRunner = function() {
|
||||
return this.topSuite;
|
||||
|
||||
@@ -38,12 +38,12 @@ jasmine.JsApiReporter = function(jasmine) {
|
||||
};
|
||||
|
||||
var specs = [];
|
||||
this.specStarted = function(result) {
|
||||
this.specStarted = function(result) { };
|
||||
|
||||
this.specDone = function(result) {
|
||||
specs.push(result);
|
||||
};
|
||||
|
||||
this.specDone = function(result) { };
|
||||
|
||||
this.specResults = function(index, length) {
|
||||
return specs.slice(index, index + length);
|
||||
};
|
||||
|
||||
@@ -3,7 +3,7 @@ jasmine.QueueRunner = function(attrs) {
|
||||
this.onComplete = attrs.onComplete || function() {};
|
||||
this.encourageGC = attrs.encourageGC || function(fn) {fn()};
|
||||
this.onException = attrs.onException || function() {};
|
||||
this.catchingExceptions = attrs.catchingExceptions || function() { return true; };
|
||||
this.catchException = attrs.catchException || function() { return true; };
|
||||
};
|
||||
|
||||
jasmine.QueueRunner.prototype.execute = function() {
|
||||
@@ -30,7 +30,7 @@ jasmine.QueueRunner.prototype.run = function(fns, index) {
|
||||
fn();
|
||||
} catch (e) {
|
||||
self.onException(e);
|
||||
if (!self.catchingExceptions()) {
|
||||
if (!self.catchException(e)) {
|
||||
//TODO: set a var when we catch an exception and
|
||||
//use a finally block to close the loop in a nice way..
|
||||
throw e;
|
||||
|
||||
@@ -11,10 +11,14 @@ jasmine.Spec = function(attrs) {
|
||||
this.onStart = attrs.onStart || function() {};
|
||||
this.exceptionFormatter = attrs.exceptionFormatter || function() {};
|
||||
this.getSpecName = attrs.getSpecName || function() { return ''; };
|
||||
this.expectationResultFactory = attrs.expectationResultFactory || function() {};
|
||||
this.queueRunner = attrs.queueRunner || { execute: function() {}};
|
||||
this.expectationResultFactory = attrs.expectationResultFactory || function() { };
|
||||
this.queueRunner = attrs.queueRunner || function() {};
|
||||
this.catchingExceptions = attrs.catchingExceptions || function() { return true; };
|
||||
|
||||
if (!this.fn) {
|
||||
this.pend();
|
||||
}
|
||||
|
||||
this.result = {
|
||||
id: this.id,
|
||||
description: this.description,
|
||||
@@ -39,7 +43,9 @@ jasmine.Spec.prototype.expect = function(actual) {
|
||||
jasmine.Spec.prototype.execute = function(onComplete) {
|
||||
var self = this;
|
||||
|
||||
if (this.disabled) {
|
||||
this.onStart(this);
|
||||
|
||||
if (this.markedPending || this.disabled) {
|
||||
complete();
|
||||
return;
|
||||
}
|
||||
@@ -48,10 +54,14 @@ jasmine.Spec.prototype.execute = function(onComplete) {
|
||||
afters = this.afterFns() || [];
|
||||
var allFns = befores.concat(this.fn).concat(afters);
|
||||
|
||||
this.onStart(this);
|
||||
this.queueRunner({
|
||||
fns: allFns,
|
||||
onException: function(e) {
|
||||
if (jasmine.Spec.isPendingSpecException(e)) {
|
||||
self.pend();
|
||||
return;
|
||||
}
|
||||
|
||||
self.addExpectationResult(false, {
|
||||
matcherName: "",
|
||||
passed: false,
|
||||
@@ -77,13 +87,17 @@ jasmine.Spec.prototype.disable = function() {
|
||||
this.disabled = true;
|
||||
};
|
||||
|
||||
jasmine.Spec.prototype.pend = function() {
|
||||
this.markedPending = true;
|
||||
};
|
||||
|
||||
jasmine.Spec.prototype.status = function() {
|
||||
if (this.disabled) {
|
||||
return 'disabled';
|
||||
}
|
||||
|
||||
if (!this.encounteredExpectations) {
|
||||
return null;
|
||||
if (this.markedPending || !this.encounteredExpectations) {
|
||||
return 'pending';
|
||||
}
|
||||
|
||||
if (this.result.failedExpectations.length > 0) {
|
||||
@@ -96,3 +110,9 @@ jasmine.Spec.prototype.status = function() {
|
||||
jasmine.Spec.prototype.getFullName = function() {
|
||||
return this.getSpecName(this);
|
||||
};
|
||||
|
||||
jasmine.Spec.pendingSpecExceptionMessage = "=> marked Pending";
|
||||
|
||||
jasmine.Spec.isPendingSpecException = function(e) {
|
||||
return e.message.indexOf(jasmine.Spec.pendingSpecExceptionMessage) === 0;
|
||||
};
|
||||
@@ -8,6 +8,7 @@ jasmine.HtmlReporter = function(options) {
|
||||
startTime,
|
||||
specsExecuted = 0,
|
||||
failureCount = 0,
|
||||
pendingSpecCount = 0,
|
||||
htmlReporterMain,
|
||||
symbols;
|
||||
|
||||
@@ -85,6 +86,10 @@ jasmine.HtmlReporter = function(options) {
|
||||
|
||||
failures.push(failure);
|
||||
}
|
||||
|
||||
if(result.status == "pending") {
|
||||
pendingSpecCount++;
|
||||
}
|
||||
};
|
||||
|
||||
this.jasmineDone = function() {
|
||||
@@ -116,8 +121,10 @@ jasmine.HtmlReporter = function(options) {
|
||||
)
|
||||
);
|
||||
}
|
||||
var statusBarMessage = "" + pluralize("spec", specsExecuted) + ", " + pluralize("failure", failureCount),
|
||||
statusBarClassName = "bar " + ((failureCount > 0) ? "failed" : "passed");
|
||||
var statusBarMessage = "" + pluralize("spec", specsExecuted) + ", " + pluralize("failure", failureCount);
|
||||
if(pendingSpecCount) { statusBarMessage += ", " + pluralize("pending spec", pendingSpecCount); }
|
||||
|
||||
var statusBarClassName = "bar " + ((failureCount > 0) ? "failed" : "passed");
|
||||
alert.appendChild(createDom("span", {className: statusBarClassName}, statusBarMessage));
|
||||
|
||||
var results = find(".results")[0];
|
||||
|
||||
@@ -14,6 +14,7 @@ $passing-color: #5e7d00;
|
||||
|
||||
$light-failing-color: #cf867e;
|
||||
$failing-color: #b03911;
|
||||
$pending-color: #ba9d37;
|
||||
|
||||
$neutral-color: #bababa;
|
||||
|
||||
@@ -120,21 +121,20 @@ body {
|
||||
}
|
||||
}
|
||||
|
||||
&.disabled {
|
||||
font-size: 14px;
|
||||
&.disabled {
|
||||
font-size: 14px;
|
||||
|
||||
&:before {
|
||||
color: $neutral-color;
|
||||
content: "\02022";
|
||||
&:before {
|
||||
color: $neutral-color;
|
||||
content: "\02022";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
&.pending {
|
||||
line-height: ($line-height / 2) + 4;
|
||||
|
||||
line-height: 17px;
|
||||
&:before {
|
||||
color: $faint-text-color;
|
||||
content: "-";
|
||||
color: $pending-color;
|
||||
content: "*";
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -264,6 +264,10 @@ body {
|
||||
&.failed a {
|
||||
color: $failing-color;
|
||||
}
|
||||
|
||||
&.pending a {
|
||||
color: $pending-color;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -18,8 +18,8 @@ body { background-color: #eeeeee; padding: 0; margin: 5px; overflow-y: scroll; }
|
||||
.html-reporter .symbol-summary li.failed:before { color: #b03911; content: "x"; font-weight: bold; margin-left: -1px; }
|
||||
.html-reporter .symbol-summary li.disabled { font-size: 14px; }
|
||||
.html-reporter .symbol-summary li.disabled:before { color: #bababa; content: "\02022"; }
|
||||
.html-reporter .symbol-summary li.pending { line-height: 11px; }
|
||||
.html-reporter .symbol-summary li.pending:before { color: #aaaaaa; content: "-"; }
|
||||
.html-reporter .symbol-summary li.pending { line-height: 17px; }
|
||||
.html-reporter .symbol-summary li.pending:before { color: #ba9d37; content: "*"; }
|
||||
.html-reporter .exceptions { color: #fff; float: right; margin-top: 5px; margin-right: 5px; }
|
||||
.html-reporter .bar { line-height: 28px; font-size: 14px; display: block; color: #eee; }
|
||||
.html-reporter .bar.failed { background-color: #b03911; }
|
||||
@@ -43,6 +43,7 @@ body { background-color: #eeeeee; padding: 0; margin: 5px; overflow-y: scroll; }
|
||||
.html-reporter .summary ul.suite { margin-top: 7px; margin-bottom: 7px; }
|
||||
.html-reporter .summary li.passed a { color: #5e7d00; }
|
||||
.html-reporter .summary li.failed a { color: #b03911; }
|
||||
.html-reporter .summary li.pending a { color: #ba9d37; }
|
||||
.html-reporter .description + .suite { margin-top: 0; }
|
||||
.html-reporter .suite { margin-top: 14px; }
|
||||
.html-reporter .suite a { color: #333333; }
|
||||
|
||||
Reference in New Issue
Block a user