1
/* @deprecated Use jasmine.HtmlReporter instead
3
jasmine.TrivialReporter = function(doc) {
4
this.document = doc || document;
6
this.logRunningSpecs = false;
9
jasmine.TrivialReporter.prototype.createDom = function(type, attrs, childrenVarArgs) {
10
var el = document.createElement(type);
12
for (var i = 2; i < arguments.length; i++) {
13
var child = arguments[i];
15
if (typeof child === 'string') {
16
el.appendChild(document.createTextNode(child));
18
if (child) { el.appendChild(child); }
22
for (var attr in attrs) {
23
if (attr == "className") {
24
el[attr] = attrs[attr];
26
el.setAttribute(attr, attrs[attr]);
33
jasmine.TrivialReporter.prototype.reportRunnerStarting = function(runner) {
34
var showPassed, showSkipped;
36
this.outerDiv = this.createDom('div', { id: 'TrivialReporter', className: 'jasmine_reporter' },
37
this.createDom('div', { className: 'banner' },
38
this.createDom('div', { className: 'logo' },
39
this.createDom('span', { className: 'title' }, "Jasmine"),
40
this.createDom('span', { className: 'version' }, runner.env.versionString())),
41
this.createDom('div', { className: 'options' },
43
showPassed = this.createDom('input', { id: "__jasmine_TrivialReporter_showPassed__", type: 'checkbox' }),
44
this.createDom('label', { "for": "__jasmine_TrivialReporter_showPassed__" }, " passed "),
45
showSkipped = this.createDom('input', { id: "__jasmine_TrivialReporter_showSkipped__", type: 'checkbox' }),
46
this.createDom('label', { "for": "__jasmine_TrivialReporter_showSkipped__" }, " skipped")
50
this.runnerDiv = this.createDom('div', { className: 'runner running' },
51
this.createDom('a', { className: 'run_spec', href: '?' }, "run all"),
52
this.runnerMessageSpan = this.createDom('span', {}, "Running..."),
53
this.finishedAtSpan = this.createDom('span', { className: 'finished-at' }, ""))
56
this.document.body.appendChild(this.outerDiv);
58
var suites = runner.suites();
59
for (var i = 0; i < suites.length; i++) {
60
var suite = suites[i];
61
var suiteDiv = this.createDom('div', { className: 'suite' },
62
this.createDom('a', { className: 'run_spec', href: '?spec=' + encodeURIComponent(suite.getFullName()) }, "run"),
63
this.createDom('a', { className: 'description', href: '?spec=' + encodeURIComponent(suite.getFullName()) }, suite.description));
64
this.suiteDivs[suite.id] = suiteDiv;
65
var parentDiv = this.outerDiv;
66
if (suite.parentSuite) {
67
parentDiv = this.suiteDivs[suite.parentSuite.id];
69
parentDiv.appendChild(suiteDiv);
72
this.startedAt = new Date();
75
showPassed.onclick = function(evt) {
76
if (showPassed.checked) {
77
self.outerDiv.className += ' show-passed';
79
self.outerDiv.className = self.outerDiv.className.replace(/ show-passed/, '');
83
showSkipped.onclick = function(evt) {
84
if (showSkipped.checked) {
85
self.outerDiv.className += ' show-skipped';
87
self.outerDiv.className = self.outerDiv.className.replace(/ show-skipped/, '');
92
jasmine.TrivialReporter.prototype.reportRunnerResults = function(runner) {
93
var results = runner.results();
94
var className = (results.failedCount > 0) ? "runner failed" : "runner passed";
95
this.runnerDiv.setAttribute("class", className);
97
this.runnerDiv.setAttribute("className", className);
98
var specs = runner.specs();
100
for (var i = 0; i < specs.length; i++) {
101
if (this.specFilter(specs[i])) {
105
var message = "" + specCount + " spec" + (specCount == 1 ? "" : "s" ) + ", " + results.failedCount + " failure" + ((results.failedCount == 1) ? "" : "s");
106
message += " in " + ((new Date().getTime() - this.startedAt.getTime()) / 1000) + "s";
107
this.runnerMessageSpan.replaceChild(this.createDom('a', { className: 'description', href: '?'}, message), this.runnerMessageSpan.firstChild);
109
this.finishedAtSpan.appendChild(document.createTextNode("Finished at " + new Date().toString()));
112
jasmine.TrivialReporter.prototype.reportSuiteResults = function(suite) {
113
var results = suite.results();
114
var status = results.passed() ? 'passed' : 'failed';
115
if (results.totalCount === 0) { // todo: change this to check results.skipped
118
this.suiteDivs[suite.id].className += " " + status;
121
jasmine.TrivialReporter.prototype.reportSpecStarting = function(spec) {
122
if (this.logRunningSpecs) {
123
this.log('>> Jasmine Running ' + spec.suite.description + ' ' + spec.description + '...');
127
jasmine.TrivialReporter.prototype.reportSpecResults = function(spec) {
128
var results = spec.results();
129
var status = results.passed() ? 'passed' : 'failed';
130
if (results.skipped) {
133
var specDiv = this.createDom('div', { className: 'spec ' + status },
134
this.createDom('a', { className: 'run_spec', href: '?spec=' + encodeURIComponent(spec.getFullName()) }, "run"),
135
this.createDom('a', {
136
className: 'description',
137
href: '?spec=' + encodeURIComponent(spec.getFullName()),
138
title: spec.getFullName()
139
}, spec.description));
142
var resultItems = results.getItems();
143
var messagesDiv = this.createDom('div', { className: 'messages' });
144
for (var i = 0; i < resultItems.length; i++) {
145
var result = resultItems[i];
147
if (result.type == 'log') {
148
messagesDiv.appendChild(this.createDom('div', {className: 'resultMessage log'}, result.toString()));
149
} else if (result.type == 'expect' && result.passed && !result.passed()) {
150
messagesDiv.appendChild(this.createDom('div', {className: 'resultMessage fail'}, result.message));
152
if (result.trace.stack) {
153
messagesDiv.appendChild(this.createDom('div', {className: 'stackTrace'}, result.trace.stack));
158
if (messagesDiv.childNodes.length > 0) {
159
specDiv.appendChild(messagesDiv);
162
this.suiteDivs[spec.suite.id].appendChild(specDiv);
165
jasmine.TrivialReporter.prototype.log = function() {
166
var console = jasmine.getGlobal().console;
167
if (console && console.log) {
168
if (console.log.apply) {
169
console.log.apply(console, arguments);
171
console.log(arguments); // ie fix: console.log.apply doesn't exist on ie
176
jasmine.TrivialReporter.prototype.getLocation = function() {
177
return this.document.location;
180
jasmine.TrivialReporter.prototype.specFilter = function(spec) {
182
var params = this.getLocation().search.substring(1).split('&');
183
for (var i = 0; i < params.length; i++) {
184
var p = params[i].split('=');
185
paramMap[decodeURIComponent(p[0])] = decodeURIComponent(p[1]);
188
if (!paramMap.spec) {
191
return spec.getFullName().indexOf(paramMap.spec) === 0;