Allow pending to take a reason and show it in the HtmlReporter
[#78954014] Fix #671
This commit is contained in:
@@ -221,6 +221,9 @@ jasmineRequire.HtmlReporter = function(j$) {
|
|||||||
if(noExpectations(resultNode.result)) {
|
if(noExpectations(resultNode.result)) {
|
||||||
specDescription = 'SPEC HAS NO EXPECTATIONS ' + specDescription;
|
specDescription = 'SPEC HAS NO EXPECTATIONS ' + specDescription;
|
||||||
}
|
}
|
||||||
|
if(resultNode.result.status === 'pending' && resultNode.result.pendingReason !== '') {
|
||||||
|
specDescription = specDescription + ' PENDING WITH MESSAGE: ' + resultNode.result.pendingReason;
|
||||||
|
}
|
||||||
specListNode.appendChild(
|
specListNode.appendChild(
|
||||||
createDom('li', {
|
createDom('li', {
|
||||||
className: resultNode.result.status,
|
className: resultNode.result.status,
|
||||||
|
|||||||
@@ -312,7 +312,8 @@ getJasmineRequireObj().Spec = function(j$) {
|
|||||||
description: this.description,
|
description: this.description,
|
||||||
fullName: this.getFullName(),
|
fullName: this.getFullName(),
|
||||||
failedExpectations: [],
|
failedExpectations: [],
|
||||||
passedExpectations: []
|
passedExpectations: [],
|
||||||
|
pendingReason: ''
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -361,7 +362,7 @@ getJasmineRequireObj().Spec = function(j$) {
|
|||||||
|
|
||||||
Spec.prototype.onException = function onException(e) {
|
Spec.prototype.onException = function onException(e) {
|
||||||
if (Spec.isPendingSpecException(e)) {
|
if (Spec.isPendingSpecException(e)) {
|
||||||
this.pend();
|
this.pend(extractCustomPendingMessage(e));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -378,8 +379,11 @@ getJasmineRequireObj().Spec = function(j$) {
|
|||||||
this.disabled = true;
|
this.disabled = true;
|
||||||
};
|
};
|
||||||
|
|
||||||
Spec.prototype.pend = function() {
|
Spec.prototype.pend = function(message) {
|
||||||
this.markedPending = true;
|
this.markedPending = true;
|
||||||
|
if (message) {
|
||||||
|
this.result.pendingReason = message;
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
Spec.prototype.status = function() {
|
Spec.prototype.status = function() {
|
||||||
@@ -406,6 +410,14 @@ getJasmineRequireObj().Spec = function(j$) {
|
|||||||
return this.getSpecName(this);
|
return this.getSpecName(this);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
var extractCustomPendingMessage = function(e) {
|
||||||
|
var fullMessage = e.toString(),
|
||||||
|
boilerplateStart = fullMessage.indexOf(Spec.pendingSpecExceptionMessage),
|
||||||
|
boilerplateEnd = boilerplateStart + Spec.pendingSpecExceptionMessage.length;
|
||||||
|
|
||||||
|
return fullMessage.substr(boilerplateEnd);
|
||||||
|
};
|
||||||
|
|
||||||
Spec.pendingSpecExceptionMessage = '=> marked Pending';
|
Spec.pendingSpecExceptionMessage = '=> marked Pending';
|
||||||
|
|
||||||
Spec.isPendingSpecException = function(e) {
|
Spec.isPendingSpecException = function(e) {
|
||||||
@@ -851,8 +863,12 @@ getJasmineRequireObj().Env = function(j$) {
|
|||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
this.pending = function() {
|
this.pending = function(message) {
|
||||||
throw j$.Spec.pendingSpecExceptionMessage;
|
var fullMessage = j$.Spec.pendingSpecExceptionMessage;
|
||||||
|
if(message) {
|
||||||
|
fullMessage += message;
|
||||||
|
}
|
||||||
|
throw fullMessage;
|
||||||
};
|
};
|
||||||
|
|
||||||
this.fail = function(error) {
|
this.fail = function(error) {
|
||||||
@@ -2994,7 +3010,7 @@ getJasmineRequireObj().interface = function(jasmine, env) {
|
|||||||
},
|
},
|
||||||
|
|
||||||
pending: function() {
|
pending: function() {
|
||||||
return env.pending();
|
return env.pending.apply(env, arguments);
|
||||||
},
|
},
|
||||||
|
|
||||||
fail: function() {
|
fail: function() {
|
||||||
|
|||||||
@@ -11,6 +11,12 @@ describe("Env", function() {
|
|||||||
env.pending();
|
env.pending();
|
||||||
}).toThrow(j$.Spec.pendingSpecExceptionMessage);
|
}).toThrow(j$.Spec.pendingSpecExceptionMessage);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it("throws the Pending Spec exception with a custom message", function() {
|
||||||
|
expect(function() {
|
||||||
|
env.pending('custom message');
|
||||||
|
}).toThrow(j$.Spec.pendingSpecExceptionMessage + 'custom message');
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe("#topSuite", function() {
|
describe("#topSuite", function() {
|
||||||
|
|||||||
@@ -14,6 +14,10 @@ describe("Spec", function() {
|
|||||||
expect(j$.Spec.isPendingSpecException(fakeError)).toBe(true);
|
expect(j$.Spec.isPendingSpecException(fakeError)).toBe(true);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it("#isPendingSpecException returns true for a pending spec exception with a custom message", function() {
|
||||||
|
expect(j$.Spec.isPendingSpecException(j$.Spec.pendingSpecExceptionMessage + 'foo')).toBe(true);
|
||||||
|
});
|
||||||
|
|
||||||
it("#isPendingSpecException returns false for not a pending spec exception", function() {
|
it("#isPendingSpecException returns false for not a pending spec exception", function() {
|
||||||
var e = new Error("foo");
|
var e = new Error("foo");
|
||||||
|
|
||||||
@@ -174,7 +178,8 @@ describe("Spec", function() {
|
|||||||
description: 'with a spec',
|
description: 'with a spec',
|
||||||
fullName: 'a suite with a spec',
|
fullName: 'a suite with a spec',
|
||||||
failedExpectations: [],
|
failedExpectations: [],
|
||||||
passedExpectations: []
|
passedExpectations: [],
|
||||||
|
pendingReason: ''
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -254,6 +259,24 @@ describe("Spec", function() {
|
|||||||
spec.execute();
|
spec.execute();
|
||||||
|
|
||||||
expect(spec.status()).toEqual("pending");
|
expect(spec.status()).toEqual("pending");
|
||||||
|
expect(spec.result.pendingReason).toEqual('');
|
||||||
|
});
|
||||||
|
|
||||||
|
it("should set the pendingReason", function() {
|
||||||
|
var fakeQueueRunner = function(opts) {
|
||||||
|
opts.onException(new Error(j$.Spec.pendingSpecExceptionMessage + 'custom message'));
|
||||||
|
},
|
||||||
|
spec = new j$.Spec({
|
||||||
|
description: 'my test',
|
||||||
|
id: 'some-id',
|
||||||
|
queueableFn: { fn: function() { } },
|
||||||
|
queueRunnerFactory: fakeQueueRunner
|
||||||
|
});
|
||||||
|
|
||||||
|
spec.execute();
|
||||||
|
|
||||||
|
expect(spec.status()).toEqual("pending");
|
||||||
|
expect(spec.result.pendingReason).toEqual('custom message');
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -1137,6 +1137,30 @@ describe("Env integration", function() {
|
|||||||
env.execute();
|
env.execute();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('should report pending spec messages', function(done) {
|
||||||
|
var env = new j$.Env(),
|
||||||
|
reporter = jasmine.createSpyObj('fakeReporter', [
|
||||||
|
'specDone',
|
||||||
|
'jasmineDone'
|
||||||
|
]);
|
||||||
|
|
||||||
|
reporter.jasmineDone.and.callFake(function() {
|
||||||
|
var specStatus = reporter.specDone.calls.argsFor(0)[0];
|
||||||
|
|
||||||
|
expect(specStatus.pendingReason).toBe('with a message');
|
||||||
|
|
||||||
|
done();
|
||||||
|
});
|
||||||
|
|
||||||
|
env.addReporter(reporter);
|
||||||
|
|
||||||
|
env.it('will be pending', function() {
|
||||||
|
env.pending('with a message');
|
||||||
|
});
|
||||||
|
|
||||||
|
env.execute();
|
||||||
|
});
|
||||||
|
|
||||||
it('should report xdescribes as expected', function(done) {
|
it('should report xdescribes as expected', function(done) {
|
||||||
var env = new j$.Env(),
|
var env = new j$.Env(),
|
||||||
reporter = jasmine.createSpyObj('fakeReporter', [
|
reporter = jasmine.createSpyObj('fakeReporter', [
|
||||||
|
|||||||
@@ -533,14 +533,17 @@ describe("New HtmlReporter", function() {
|
|||||||
reporter.initialize();
|
reporter.initialize();
|
||||||
|
|
||||||
reporter.jasmineStarted({ totalSpecsDefined: 1 });
|
reporter.jasmineStarted({ totalSpecsDefined: 1 });
|
||||||
reporter.specDone({
|
var specStatus = {
|
||||||
id: 123,
|
id: 123,
|
||||||
description: "with a spec",
|
description: "with a spec",
|
||||||
fullName: "A Suite with a spec",
|
fullName: "A Suite with a spec",
|
||||||
status: "pending",
|
status: "pending",
|
||||||
passedExpectations: [],
|
passedExpectations: [],
|
||||||
failedExpectations: []
|
failedExpectations: [],
|
||||||
});
|
pendingReason: "my custom pending reason"
|
||||||
|
};
|
||||||
|
reporter.specStarted(specStatus);
|
||||||
|
reporter.specDone(specStatus);
|
||||||
reporter.jasmineDone({});
|
reporter.jasmineDone({});
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -555,6 +558,12 @@ describe("New HtmlReporter", function() {
|
|||||||
|
|
||||||
expect(specFailure.childNodes.length).toEqual(0);
|
expect(specFailure.childNodes.length).toEqual(0);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it("displays the custom pending reason", function() {
|
||||||
|
var pendingDetails = container.querySelector(".summary .pending");
|
||||||
|
|
||||||
|
expect(pendingDetails.innerHTML).toContain("my custom pending reason");
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe("and some tests fail", function() {
|
describe("and some tests fail", function() {
|
||||||
|
|||||||
@@ -430,8 +430,12 @@ getJasmineRequireObj().Env = function(j$) {
|
|||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
this.pending = function() {
|
this.pending = function(message) {
|
||||||
throw j$.Spec.pendingSpecExceptionMessage;
|
var fullMessage = j$.Spec.pendingSpecExceptionMessage;
|
||||||
|
if(message) {
|
||||||
|
fullMessage += message;
|
||||||
|
}
|
||||||
|
throw fullMessage;
|
||||||
};
|
};
|
||||||
|
|
||||||
this.fail = function(error) {
|
this.fail = function(error) {
|
||||||
|
|||||||
@@ -22,7 +22,8 @@ getJasmineRequireObj().Spec = function(j$) {
|
|||||||
description: this.description,
|
description: this.description,
|
||||||
fullName: this.getFullName(),
|
fullName: this.getFullName(),
|
||||||
failedExpectations: [],
|
failedExpectations: [],
|
||||||
passedExpectations: []
|
passedExpectations: [],
|
||||||
|
pendingReason: ''
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -71,7 +72,7 @@ getJasmineRequireObj().Spec = function(j$) {
|
|||||||
|
|
||||||
Spec.prototype.onException = function onException(e) {
|
Spec.prototype.onException = function onException(e) {
|
||||||
if (Spec.isPendingSpecException(e)) {
|
if (Spec.isPendingSpecException(e)) {
|
||||||
this.pend();
|
this.pend(extractCustomPendingMessage(e));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -88,8 +89,11 @@ getJasmineRequireObj().Spec = function(j$) {
|
|||||||
this.disabled = true;
|
this.disabled = true;
|
||||||
};
|
};
|
||||||
|
|
||||||
Spec.prototype.pend = function() {
|
Spec.prototype.pend = function(message) {
|
||||||
this.markedPending = true;
|
this.markedPending = true;
|
||||||
|
if (message) {
|
||||||
|
this.result.pendingReason = message;
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
Spec.prototype.status = function() {
|
Spec.prototype.status = function() {
|
||||||
@@ -116,6 +120,14 @@ getJasmineRequireObj().Spec = function(j$) {
|
|||||||
return this.getSpecName(this);
|
return this.getSpecName(this);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
var extractCustomPendingMessage = function(e) {
|
||||||
|
var fullMessage = e.toString(),
|
||||||
|
boilerplateStart = fullMessage.indexOf(Spec.pendingSpecExceptionMessage),
|
||||||
|
boilerplateEnd = boilerplateStart + Spec.pendingSpecExceptionMessage.length;
|
||||||
|
|
||||||
|
return fullMessage.substr(boilerplateEnd);
|
||||||
|
};
|
||||||
|
|
||||||
Spec.pendingSpecExceptionMessage = '=> marked Pending';
|
Spec.pendingSpecExceptionMessage = '=> marked Pending';
|
||||||
|
|
||||||
Spec.isPendingSpecException = function(e) {
|
Spec.isPendingSpecException = function(e) {
|
||||||
|
|||||||
@@ -45,7 +45,7 @@ getJasmineRequireObj().interface = function(jasmine, env) {
|
|||||||
},
|
},
|
||||||
|
|
||||||
pending: function() {
|
pending: function() {
|
||||||
return env.pending();
|
return env.pending.apply(env, arguments);
|
||||||
},
|
},
|
||||||
|
|
||||||
fail: function() {
|
fail: function() {
|
||||||
|
|||||||
@@ -192,6 +192,9 @@ jasmineRequire.HtmlReporter = function(j$) {
|
|||||||
if(noExpectations(resultNode.result)) {
|
if(noExpectations(resultNode.result)) {
|
||||||
specDescription = 'SPEC HAS NO EXPECTATIONS ' + specDescription;
|
specDescription = 'SPEC HAS NO EXPECTATIONS ' + specDescription;
|
||||||
}
|
}
|
||||||
|
if(resultNode.result.status === 'pending' && resultNode.result.pendingReason !== '') {
|
||||||
|
specDescription = specDescription + ' PENDING WITH MESSAGE: ' + resultNode.result.pendingReason;
|
||||||
|
}
|
||||||
specListNode.appendChild(
|
specListNode.appendChild(
|
||||||
createDom('li', {
|
createDom('li', {
|
||||||
className: resultNode.result.status,
|
className: resultNode.result.status,
|
||||||
|
|||||||
Reference in New Issue
Block a user