1 jasmine
.TrivialReporter = function(doc
) {
2 this.document
= doc
|| document
;
4 this.logRunningSpecs
= false;
7 jasmine
.TrivialReporter
.prototype.createDom = function(type
, attrs
, childrenVarArgs
) {
8 var el
= document
.createElement(type
);
10 for (var i
= 2; i
< arguments
.length
; i
++) {
11 var child
= arguments
[i
];
13 if (typeof child
=== 'string') {
14 el
.appendChild(document
.createTextNode(child
));
16 if (child
) { el
.appendChild(child
); }
20 for (var attr
in attrs
) {
21 if (attr
== "className") {
22 el
[attr
] = attrs
[attr
];
24 el
.setAttribute(attr
, attrs
[attr
]);
31 jasmine
.TrivialReporter
.prototype.reportRunnerStarting = function(runner
) {
32 var showPassed
, showSkipped
;
34 this.outerDiv
= this.createDom('div', { className
: 'jasmine_reporter' },
35 this.createDom('div', { className
: 'banner' },
36 this.createDom('div', { className
: 'logo' },
38 this.createDom('span', { className
: 'version' }, runner
.env
.versionString())),
39 this.createDom('div', { className
: 'options' },
41 showPassed
= this.createDom('input', { id
: "__jasmine_TrivialReporter_showPassed__", type
: 'checkbox' }),
42 this.createDom('label', { "for": "__jasmine_TrivialReporter_showPassed__" }, " passed "),
43 showSkipped
= this.createDom('input', { id
: "__jasmine_TrivialReporter_showSkipped__", type
: 'checkbox' }),
44 this.createDom('label', { "for": "__jasmine_TrivialReporter_showSkipped__" }, " skipped")
48 this.runnerDiv
= this.createDom('div', { className
: 'runner running' },
49 this.createDom('a', { className
: 'run_spec', href
: '?' }, "run all"),
50 this.runnerMessageSpan
= this.createDom('span', {}, "Running..."),
51 this.finishedAtSpan
= this.createDom('span', { className
: 'finished-at' }, ""))
54 this.document
.body
.appendChild(this.outerDiv
);
56 var suites
= runner
.suites();
57 for (var i
= 0; i
< suites
.length
; i
++) {
58 var suite
= suites
[i
];
59 var suiteDiv
= this.createDom('div', { className
: 'suite' },
60 this.createDom('a', { className
: 'run_spec', href
: '?spec=' + encodeURIComponent(suite
.getFullName()) }, "run"),
61 this.createDom('a', { className
: 'description', href
: '?spec=' + encodeURIComponent(suite
.getFullName()) }, suite
.description
));
62 this.suiteDivs
[suite
.id
] = suiteDiv
;
63 var parentDiv
= this.outerDiv
;
64 if (suite
.parentSuite
) {
65 parentDiv
= this.suiteDivs
[suite
.parentSuite
.id
];
67 parentDiv
.appendChild(suiteDiv
);
70 this.startedAt
= new Date();
73 showPassed
.onchange = function(evt
) {
74 if (evt
.target
.checked
) {
75 self
.outerDiv
.className
+= ' show-passed';
77 self
.outerDiv
.className
= self
.outerDiv
.className
.replace(/ show
-passed
/, '');
81 showSkipped
.onchange = function(evt
) {
82 if (evt
.target
.checked
) {
83 self
.outerDiv
.className
+= ' show-skipped';
85 self
.outerDiv
.className
= self
.outerDiv
.className
.replace(/ show
-skipped
/, '');
90 jasmine
.TrivialReporter
.prototype.reportRunnerResults = function(runner
) {
91 var results
= runner
.results();
92 var className
= (results
.failedCount
> 0) ? "runner failed" : "runner passed";
93 this.runnerDiv
.setAttribute("class", className
);
95 this.runnerDiv
.setAttribute("className", className
);
96 var specs
= runner
.specs();
98 for (var i
= 0; i
< specs
.length
; i
++) {
99 if (this.specFilter(specs
[i
])) {
103 var message
= "" + specCount
+ " spec" + (specCount
== 1 ? "" : "s" ) + ", " + results
.failedCount
+ " failure" + ((results
.failedCount
== 1) ? "" : "s");
104 message
+= " in " + ((new Date().getTime() - this.startedAt
.getTime()) / 1000) + "s";
105 this.runnerMessageSpan
.replaceChild(this.createDom('a', { className
: 'description', href
: '?'}, message
), this.runnerMessageSpan
.firstChild
);
107 this.finishedAtSpan
.appendChild(document
.createTextNode("Finished at " + new Date().toString()));
110 jasmine
.TrivialReporter
.prototype.reportSuiteResults = function(suite
) {
111 var results
= suite
.results();
112 var status
= results
.passed() ? 'passed' : 'failed';
113 if (results
.totalCount
== 0) { // todo: change this to check results.skipped
116 this.suiteDivs
[suite
.id
].className
+= " " + status
;
119 jasmine
.TrivialReporter
.prototype.reportSpecStarting = function(spec
) {
120 if (this.logRunningSpecs
) {
121 this.log('>> Jasmine Running ' + spec
.suite
.description
+ ' ' + spec
.description
+ '...');
125 jasmine
.TrivialReporter
.prototype.reportSpecResults = function(spec
) {
126 var results
= spec
.results();
127 var status
= results
.passed() ? 'passed' : 'failed';
128 if (results
.skipped
) {
131 var specDiv
= this.createDom('div', { className
: 'spec ' + status
},
132 this.createDom('a', { className
: 'run_spec', href
: '?spec=' + encodeURIComponent(spec
.getFullName()) }, "run"),
133 this.createDom('a', {
134 className
: 'description',
135 href
: '?spec=' + encodeURIComponent(spec
.getFullName()),
136 title
: spec
.getFullName()
137 }, spec
.description
));
140 var resultItems
= results
.getItems();
141 var messagesDiv
= this.createDom('div', { className
: 'messages' });
142 for (var i
= 0; i
< resultItems
.length
; i
++) {
143 var result
= resultItems
[i
];
145 if (result
.type
== 'log') {
146 messagesDiv
.appendChild(this.createDom('div', {className
: 'resultMessage log'}, result
.toString()));
147 } else if (result
.type
== 'expect' && result
.passed
&& !result
.passed()) {
148 messagesDiv
.appendChild(this.createDom('div', {className
: 'resultMessage fail'}, result
.message
));
150 if (result
.trace
.stack
) {
151 messagesDiv
.appendChild(this.createDom('div', {className
: 'stackTrace'}, result
.trace
.stack
));
156 if (messagesDiv
.childNodes
.length
> 0) {
157 specDiv
.appendChild(messagesDiv
);
160 this.suiteDivs
[spec
.suite
.id
].appendChild(specDiv
);
163 jasmine
.TrivialReporter
.prototype.log = function() {
164 var console
= jasmine
.getGlobal().console
;
165 if (console
&& console
.log
) console
.log
.apply(console
, arguments
);
168 jasmine
.TrivialReporter
.prototype.getLocation = function() {
169 return this.document
.location
;
172 jasmine
.TrivialReporter
.prototype.specFilter = function(spec
) {
174 var params
= this.getLocation().search
.substring(1).split('&');
175 for (var i
= 0; i
< params
.length
; i
++) {
176 var p
= params
[i
].split('=');
177 paramMap
[decodeURIComponent(p
[0])] = decodeURIComponent(p
[1]);
180 if (!paramMap
["spec"]) return true;
181 return spec
.getFullName().indexOf(paramMap
["spec"]) == 0;