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 {
|
2009-09-30 05:09:30 +00:00
|
|
|
if (child) { el.appendChild(child); }
|
2009-05-29 03:02:15 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
for (var attr in attrs) {
|
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) {
|
2009-09-02 14:52:11 +00:00
|
|
|
var suites = runner.suites();
|
2009-08-12 17:15:15 +00:00
|
|
|
|
2009-08-17 20:37:33 +00:00
|
|
|
this.runnerDiv = this.createDom('div', { className: 'runner running' },
|
2009-10-16 03:00:41 +00:00
|
|
|
this.createDom('a', { className: 'run_spec', href: '?' }, "run all"),
|
2009-08-17 20:37:33 +00:00
|
|
|
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' },
|
2009-10-16 03:00:41 +00:00
|
|
|
this.createDom('a', { className: 'run_spec', href: '?spec=' + encodeURIComponent(suite.getFullName()) }, "run"),
|
2009-10-16 01:58:52 +00:00
|
|
|
this.createDom('a', { className: 'description', href: '?spec=' + encodeURIComponent(suite.getFullName()) }, suite.description));
|
2009-08-11 00:50:03 +00:00
|
|
|
this.suiteDivs[suite.getFullName()] = suiteDiv;
|
|
|
|
var parentDiv = this.document.body;
|
|
|
|
if (suite.parentSuite) {
|
|
|
|
parentDiv = this.suiteDivs[suite.parentSuite.getFullName()];
|
|
|
|
}
|
|
|
|
parentDiv.appendChild(suiteDiv);
|
|
|
|
}
|
2009-09-02 22:32:57 +00:00
|
|
|
|
|
|
|
this.startedAt = new Date();
|
2009-08-11 00:50:03 +00:00
|
|
|
};
|
|
|
|
|
2009-05-29 03:02:15 +00:00
|
|
|
jasmine.TrivialReporter.prototype.reportRunnerResults = function(runner) {
|
2009-09-28 18:13:44 +00:00
|
|
|
var results = runner.results();
|
2009-08-12 17:15:15 +00:00
|
|
|
var className = (results.failedCount > 0) ? "runner failed" : "runner passed";
|
|
|
|
this.runnerDiv.setAttribute("class", className);
|
2009-10-16 03:00:41 +00:00
|
|
|
//do it twice for IE
|
|
|
|
this.runnerDiv.setAttribute("className", className);
|
2009-10-16 01:58:52 +00:00
|
|
|
var specs = runner.specs();
|
|
|
|
var specCount = 0;
|
|
|
|
for (var i = 0; i < specs.length; i++) {
|
|
|
|
if (this.specFilter(specs[i])) {
|
|
|
|
specCount++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
var message = "" + specCount + " spec" + (specCount == 1 ? "" : "s" ) + ", " + results.failedCount + " failure" + ((results.failedCount == 1) ? "" : "s");
|
2009-09-02 22:32:57 +00:00
|
|
|
message += " in " + ((new Date().getTime() - this.startedAt.getTime()) / 1000) + "s";
|
2009-10-16 01:58:52 +00:00
|
|
|
this.runnerMessageSpan.replaceChild(this.createDom('a', { className: 'description', href: '?'}, message), this.runnerMessageSpan.firstChild);
|
2009-05-29 03:02:15 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
jasmine.TrivialReporter.prototype.reportSuiteResults = function(suite) {
|
2009-09-28 18:13:44 +00:00
|
|
|
var results = suite.results();
|
2009-08-11 00:54:20 +00:00
|
|
|
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-09-28 18:13:44 +00:00
|
|
|
var results = spec.results();
|
2009-08-10 22:39:48 +00:00
|
|
|
var status = results.passed() ? 'passed' : 'failed';
|
|
|
|
if (results.skipped) {
|
|
|
|
status = 'skipped';
|
|
|
|
}
|
|
|
|
var specDiv = this.createDom('div', { className: 'spec ' + status },
|
2009-10-16 03:00:41 +00:00
|
|
|
this.createDom('a', { className: 'run_spec', href: '?spec=' + encodeURIComponent(spec.getFullName()) }, "run"),
|
2009-10-16 01:58:52 +00:00
|
|
|
this.createDom('a', { className: 'description', href: '?spec=' + encodeURIComponent(spec.getFullName()) }, spec.getFullName()));
|
2009-05-29 03:02:15 +00:00
|
|
|
|
2009-08-19 14:42:47 +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];
|
2009-08-26 22:55:08 +00:00
|
|
|
if (result.passed && !result.passed()) {
|
2009-11-12 21:13:44 +00:00
|
|
|
specDiv.appendChild(this.createDom('div', {className: 'resultMessage fail'}, result.message));
|
2009-05-29 03:02:15 +00:00
|
|
|
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-10-30 02:48:23 +00:00
|
|
|
};
|