2009-08-11 00:50:03 +00:00
|
|
|
jasmine.TrivialReporter = function(doc) {
|
|
|
|
this.document = doc || document;
|
|
|
|
this.suiteDivs = {};
|
2009-05-29 03:02:15 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
jasmine.TrivialReporter.prototype.createDom = function(type, attrs, childrenVarArgs) {
|
|
|
|
var el = document.createElement(type);
|
|
|
|
|
|
|
|
for (var i = 2; i < arguments.length; i++) {
|
|
|
|
var child = arguments[i];
|
|
|
|
|
|
|
|
if (typeof child === 'string') {
|
|
|
|
el.appendChild(document.createTextNode(child));
|
|
|
|
} else {
|
|
|
|
el.appendChild(child);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
for (var attr in attrs) {
|
|
|
|
if (attr == 'className') {
|
|
|
|
el.setAttribute('class', attrs[attr]);
|
|
|
|
} else {
|
2009-07-08 18:04:35 +00:00
|
|
|
el[attr] = attrs[attr];
|
2009-05-29 03:02:15 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return el;
|
|
|
|
};
|
|
|
|
|
2009-08-11 00:50:03 +00:00
|
|
|
jasmine.TrivialReporter.prototype.reportRunnerStarting = function(runner) {
|
|
|
|
var suites = runner.getAllSuites();
|
2009-08-12 17:15:15 +00:00
|
|
|
|
2009-08-17 20:37:33 +00:00
|
|
|
this.runnerDiv = this.createDom('div', { className: 'runner running' },
|
|
|
|
this.createDom('a', { className: 'runSpec', href: '?' }, "run all"),
|
|
|
|
this.runnerMessageSpan = this.createDom('span', {}, "Running..."));
|
2009-08-12 17:15:15 +00:00
|
|
|
this.document.body.appendChild(this.runnerDiv);
|
|
|
|
|
2009-08-11 00:50:03 +00:00
|
|
|
for (var i = 0; i < suites.length; i++) {
|
|
|
|
var suite = suites[i];
|
|
|
|
var suiteDiv = this.createDom('div', { className: 'suite' },
|
|
|
|
this.createDom('a', { className: 'runSpec', href: '?spec=' + encodeURIComponent(suite.getFullName()) }, "run"),
|
|
|
|
suite.description);
|
|
|
|
this.suiteDivs[suite.getFullName()] = suiteDiv;
|
|
|
|
var parentDiv = this.document.body;
|
|
|
|
if (suite.parentSuite) {
|
|
|
|
parentDiv = this.suiteDivs[suite.parentSuite.getFullName()];
|
|
|
|
}
|
|
|
|
parentDiv.appendChild(suiteDiv);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2009-05-29 03:02:15 +00:00
|
|
|
jasmine.TrivialReporter.prototype.reportRunnerResults = function(runner) {
|
2009-08-12 17:15:15 +00:00
|
|
|
var results = runner.getResults();
|
|
|
|
var className = (results.failedCount > 0) ? "runner failed" : "runner passed";
|
|
|
|
this.runnerDiv.setAttribute("class", className);
|
|
|
|
var message = results.failedCount + " failure" + ((results.failedCount == 1) ? "" : "s");
|
2009-08-17 20:40:32 +00:00
|
|
|
this.runnerMessageSpan.replaceChild(this.document.createTextNode(message), this.runnerMessageSpan.firstChild);
|
2009-05-29 03:02:15 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
jasmine.TrivialReporter.prototype.reportSuiteResults = function(suite) {
|
2009-08-11 00:54:20 +00:00
|
|
|
var results = suite.getResults();
|
|
|
|
var status = results.passed() ? 'passed' : 'failed';
|
|
|
|
if (results.totalCount == 0) { // todo: change this to check results.skipped
|
|
|
|
status = 'skipped';
|
|
|
|
}
|
|
|
|
this.suiteDivs[suite.getFullName()].className += " " + status;
|
2009-05-29 03:02:15 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
jasmine.TrivialReporter.prototype.reportSpecResults = function(spec) {
|
2009-08-10 22:39:48 +00:00
|
|
|
var results = spec.getResults();
|
|
|
|
var status = results.passed() ? 'passed' : 'failed';
|
|
|
|
if (results.skipped) {
|
|
|
|
status = 'skipped';
|
|
|
|
}
|
|
|
|
var specDiv = this.createDom('div', { className: 'spec ' + status },
|
|
|
|
this.createDom('a', { className: 'runSpec', href: '?spec=' + encodeURIComponent(spec.getFullName()) }, "run"),
|
|
|
|
spec.getFullName());
|
2009-05-29 03:02:15 +00:00
|
|
|
|
2009-08-10 22:39:48 +00:00
|
|
|
var resultItems = results.getItems();
|
2009-05-29 03:02:15 +00:00
|
|
|
for (var i = 0; i < resultItems.length; i++) {
|
|
|
|
var result = resultItems[i];
|
|
|
|
if (!result.passed) {
|
2009-08-07 21:11:40 +00:00
|
|
|
var resultMessageDiv = this.createDom('div', {className: 'resultMessage fail'});
|
2009-05-29 03:02:15 +00:00
|
|
|
resultMessageDiv.innerHTML = result.message; // todo: lame; mend
|
|
|
|
specDiv.appendChild(resultMessageDiv);
|
|
|
|
specDiv.appendChild(this.createDom('div', {className: 'stackTrace'}, result.trace.stack));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-08-11 00:50:03 +00:00
|
|
|
this.suiteDivs[spec.suite.getFullName()].appendChild(specDiv);
|
2009-05-29 03:02:15 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
jasmine.TrivialReporter.prototype.log = function() {
|
|
|
|
console.log.apply(console, arguments);
|
|
|
|
};
|
2009-06-25 05:20:07 +00:00
|
|
|
|
2009-08-10 23:00:42 +00:00
|
|
|
jasmine.TrivialReporter.prototype.getLocation = function() {
|
2009-08-11 00:50:03 +00:00
|
|
|
return this.document.location;
|
2009-08-10 23:00:42 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
jasmine.TrivialReporter.prototype.specFilter = function(spec) {
|
|
|
|
var paramMap = {};
|
|
|
|
var params = this.getLocation().search.substring(1).split('&');
|
|
|
|
for (var i = 0; i < params.length; i++) {
|
|
|
|
var p = params[i].split('=');
|
|
|
|
paramMap[decodeURIComponent(p[0])] = decodeURIComponent(p[1]);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!paramMap["spec"]) return true;
|
2009-08-11 00:50:03 +00:00
|
|
|
return spec.getFullName().indexOf(paramMap["spec"]) == 0;
|
2009-08-10 23:00:42 +00:00
|
|
|
};
|
|
|
|
|
2009-06-25 05:20:07 +00:00
|
|
|
//protect against console.log incidents
|
|
|
|
if (!("console" in window) || !("firebug" in console)) {
|
|
|
|
var names = ["log", "debug", "info", "warn", "error", "assert", "dir", "dirxml", "group", "groupEnd", "time", "timeEnd", "count", "trace", "profile", "profileEnd"];
|
|
|
|
window.console = {};
|
|
|
|
for (var i = 0, len = names.length; i < len; ++i) {
|
|
|
|
window.console[names[i]] = function() {
|
|
|
|
};
|
|
|
|
}
|
|
|
|
}
|