jasmine.log() and Spec#log() take multiple arguments which are pretty-printed and concatted together.
Log messages are handled correctly in TrivialReporter and JsApiReporter.
This commit is contained in:
@@ -134,7 +134,10 @@ jasmine.TrivialReporter.prototype.reportSpecResults = function(spec) {
|
||||
var messagesDiv = this.createDom('div', { className: 'messages' });
|
||||
for (var i = 0; i < resultItems.length; i++) {
|
||||
var result = resultItems[i];
|
||||
if (result.passed && !result.passed()) {
|
||||
|
||||
if (result.type == 'MessageResult') {
|
||||
messagesDiv.appendChild(this.createDom('div', {className: 'resultMessage log'}, result.toString()));
|
||||
} else if (result.type == 'ExpectationResult' && result.passed && !result.passed()) {
|
||||
messagesDiv.appendChild(this.createDom('div', {className: 'resultMessage fail'}, result.message));
|
||||
|
||||
if (result.trace.stack) {
|
||||
|
||||
@@ -51,14 +51,23 @@ jasmine.clearTimeout = jasmine.bindOriginal_(window, 'clearTimeout');
|
||||
jasmine.setInterval = jasmine.bindOriginal_(window, 'setInterval');
|
||||
jasmine.clearInterval = jasmine.bindOriginal_(window, 'clearInterval');
|
||||
|
||||
jasmine.MessageResult = function(text) {
|
||||
jasmine.MessageResult = function(values) {
|
||||
this.type = 'MessageResult';
|
||||
this.text = text;
|
||||
this.values = values;
|
||||
this.trace = new Error(); // todo: test better
|
||||
};
|
||||
|
||||
jasmine.MessageResult.prototype.toString = function() {
|
||||
return this.text;
|
||||
var text = "";
|
||||
for(var i = 0; i < this.values.length; i++) {
|
||||
if (i > 0) text += " ";
|
||||
if (jasmine.isString_(this.values[i])) {
|
||||
text += this.values[i];
|
||||
} else {
|
||||
text += jasmine.pp(this.values[i]);
|
||||
}
|
||||
}
|
||||
return text;
|
||||
};
|
||||
|
||||
jasmine.ExpectationResult = function(params) {
|
||||
@@ -395,8 +404,9 @@ jasmine.createSpyObj = function(baseName, methodNames) {
|
||||
return obj;
|
||||
};
|
||||
|
||||
jasmine.log = function(message) {
|
||||
jasmine.getEnv().currentSpec.log(message);
|
||||
jasmine.log = function() {
|
||||
var spec = jasmine.getEnv().currentSpec;
|
||||
spec.log.apply(spec, arguments);
|
||||
};
|
||||
|
||||
/**
|
||||
@@ -1045,11 +1055,11 @@ jasmine.JsApiReporter.prototype.resultsForSpecs = function(specIds){
|
||||
|
||||
jasmine.JsApiReporter.prototype.summarizeResult_ = function(result){
|
||||
var summaryMessages = [];
|
||||
var messagesLength = result.messages.length
|
||||
var messagesLength = result.messages.length;
|
||||
for (var messageIndex = 0; messageIndex < messagesLength; messageIndex++) {
|
||||
var resultMessage = result.messages[messageIndex];
|
||||
summaryMessages.push({
|
||||
text: resultMessage.text,
|
||||
text: resultMessage.type == 'MessageResult' ? resultMessage.toString() : jasmine.undefined,
|
||||
passed: resultMessage.passed ? resultMessage.passed() : true,
|
||||
type: resultMessage.type,
|
||||
message: resultMessage.message,
|
||||
@@ -1057,14 +1067,12 @@ jasmine.JsApiReporter.prototype.summarizeResult_ = function(result){
|
||||
stack: resultMessage.passed && !resultMessage.passed() ? resultMessage.trace.stack : jasmine.undefined
|
||||
}
|
||||
});
|
||||
};
|
||||
}
|
||||
|
||||
var summaryResult = {
|
||||
return {
|
||||
result : result.result,
|
||||
messages : summaryMessages
|
||||
};
|
||||
|
||||
return summaryResult;
|
||||
};
|
||||
|
||||
/**
|
||||
@@ -1471,11 +1479,11 @@ jasmine.NestedResults.prototype.rollupCounts = function(result) {
|
||||
};
|
||||
|
||||
/**
|
||||
* Tracks a result's message.
|
||||
* @param message
|
||||
* Adds a log message.
|
||||
* @param values Array of message parts which will be concatenated later.
|
||||
*/
|
||||
jasmine.NestedResults.prototype.log = function(message) {
|
||||
this.items_.push(new jasmine.MessageResult(message));
|
||||
jasmine.NestedResults.prototype.log = function(values) {
|
||||
this.items_.push(new jasmine.MessageResult(values));
|
||||
};
|
||||
|
||||
/**
|
||||
@@ -1886,8 +1894,8 @@ jasmine.Spec.prototype.results = function() {
|
||||
return this.results_;
|
||||
};
|
||||
|
||||
jasmine.Spec.prototype.log = function(message) {
|
||||
return this.results_.log(message);
|
||||
jasmine.Spec.prototype.log = function() {
|
||||
return this.results_.log(arguments);
|
||||
};
|
||||
|
||||
/** @deprecated */
|
||||
@@ -2106,15 +2114,15 @@ jasmine.Suite.prototype.results = function() {
|
||||
return this.queue.results();
|
||||
};
|
||||
|
||||
jasmine.Suite.prototype.add = function(block) {
|
||||
this.children_.push(block);
|
||||
if (block instanceof jasmine.Suite) {
|
||||
this.suites_.push(block);
|
||||
this.env.currentRunner().addSuite(block);
|
||||
jasmine.Suite.prototype.add = function(suiteOrSpec) {
|
||||
this.children_.push(suiteOrSpec);
|
||||
if (suiteOrSpec instanceof jasmine.Suite) {
|
||||
this.suites_.push(suiteOrSpec);
|
||||
this.env.currentRunner().addSuite(suiteOrSpec);
|
||||
} else {
|
||||
this.specs_.push(block);
|
||||
this.specs_.push(suiteOrSpec);
|
||||
}
|
||||
this.queue.add(block);
|
||||
this.queue.add(suiteOrSpec);
|
||||
};
|
||||
|
||||
jasmine.Suite.prototype.specs = function() {
|
||||
@@ -2367,5 +2375,5 @@ jasmine.version_= {
|
||||
"major": 0,
|
||||
"minor": 10,
|
||||
"build": 4,
|
||||
"revision": 1277227072
|
||||
"revision": 1277234552
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user