comparison src/DML/VendorAssetsBundle/Resources/assets/jasmine/2.1.3/lib/jasmine-2.1.3/jasmine-html_modif.js @ 0:493bcb69166c

added public content
author Daniel Wolff
date Tue, 09 Feb 2016 20:54:02 +0100
parents
children
comparison
equal deleted inserted replaced
-1:000000000000 0:493bcb69166c
1 /*
2 Copyright (c) 2008-2014 Pivotal Labs
3
4 Permission is hereby granted, free of charge, to any person obtaining
5 a copy of this software and associated documentation files (the
6 "Software"), to deal in the Software without restriction, including
7 without limitation the rights to use, copy, modify, merge, publish,
8 distribute, sublicense, and/or sell copies of the Software, and to
9 permit persons to whom the Software is furnished to do so, subject to
10 the following conditions:
11
12 The above copyright notice and this permission notice shall be
13 included in all copies or substantial portions of the Software.
14
15 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
16 EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
17 MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
18 NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
19 LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
20 OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
21 WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
22 */
23 jasmineRequire.html = function(j$) {
24 j$.ResultsNode = jasmineRequire.ResultsNode();
25 j$.HtmlReporter = jasmineRequire.HtmlReporter(j$);
26 j$.QueryString = jasmineRequire.QueryString();
27 j$.HtmlSpecFilter = jasmineRequire.HtmlSpecFilter();
28 };
29
30 jasmineRequire.HtmlReporter = function(j$) {
31
32 var noopTimer = {
33 start: function() {},
34 elapsed: function() { return 0; }
35 };
36
37 function HtmlReporter(options) {
38 var env = options.env || {},
39 getContainer = options.getContainer,
40 createElement = options.createElement,
41 createTextNode = options.createTextNode,
42 onRaiseExceptionsClick = options.onRaiseExceptionsClick || function() {},
43 timer = options.timer || noopTimer,
44 results = [],
45 specsExecuted = 0,
46 failureCount = 0,
47 pendingSpecCount = 0,
48 htmlReporterMain,
49 symbols,
50 failedSuites = [];
51
52 this.initialize = function() {
53 clearPrior();
54 htmlReporterMain = createDom('div', {className: 'jasmine_html-reporter'},
55 createDom('div', {className: 'banner'},
56 createDom('a', {className: 'title', href: 'http://jasmine.github.io/', target: '_blank'}),
57 createDom('span', {className: 'version'}, j$.version)
58 ),
59 createDom('ul', {className: 'symbol-summary'}),
60 createDom('div', {className: 'alert'}),
61 createDom('div', {className: 'results'},
62 createDom('div', {className: 'failures'})
63 )
64 );
65 getContainer().appendChild(htmlReporterMain);
66
67 symbols = find('.symbol-summary');
68 };
69
70 var totalSpecsDefined;
71 this.jasmineStarted = function(options) {
72 totalSpecsDefined = options.totalSpecsDefined || 0;
73 timer.start();
74 };
75
76 var summary = createDom('div', {className: 'summary'});
77
78 var topResults = new j$.ResultsNode({}, '', null),
79 currentParent = topResults;
80
81 this.suiteStarted = function(result) {
82 currentParent.addChild(result, 'suite');
83 currentParent = currentParent.last();
84 };
85
86 this.suiteDone = function(result) {
87 if (result.status == 'failed') {
88 failedSuites.push(result);
89 }
90
91 if (currentParent == topResults) {
92 return;
93 }
94
95 currentParent = currentParent.parent;
96 };
97
98 this.specStarted = function(result) {
99 currentParent.addChild(result, 'spec');
100 };
101
102 var failures = [];
103 this.specDone = function(result) {
104 if(noExpectations(result) && typeof console !== 'undefined' && typeof console.error !== 'undefined') {
105 console.error('Spec \'' + result.fullName + '\' has no expectations.');
106 }
107
108 if (result.status != 'disabled') {
109 specsExecuted++;
110 }
111
112 symbols.appendChild(createDom('li', {
113 className: noExpectations(result) ? 'empty' : result.status,
114 id: 'spec_' + result.id,
115 title: result.fullName
116 }
117 ));
118
119 if (result.status == 'failed') {
120 failureCount++;
121
122 var failure =
123 createDom('div', {className: 'spec-detail failed'},
124 createDom('div', {className: 'description'},
125 createDom('a', {title: result.fullName, href: specHref(result)}, result.fullName)
126 ),
127 createDom('div', {className: 'messages'})
128 );
129 var messages = failure.childNodes[1];
130
131 for (var i = 0; i < result.failedExpectations.length; i++) {
132 var expectation = result.failedExpectations[i];
133 messages.appendChild(createDom('div', {className: 'result-message'}, expectation.message));
134 messages.appendChild(createDom('div', {className: 'stack-trace'}, expectation.stack));
135 }
136
137 failures.push(failure);
138 }
139
140 if (result.status == 'pending') {
141 pendingSpecCount++;
142 }
143 };
144
145 this.jasmineDone = function() {
146 var banner = find('.banner');
147 banner.appendChild(createDom('span', {className: 'duration'}, 'finished in ' + timer.elapsed() / 1000 + 's'));
148
149 var alert = find('.alert');
150
151 alert.appendChild(createDom('span', { className: 'exceptions' },
152 createDom('label', { className: 'label', 'for': 'raise-exceptions' }, 'raise exceptions'),
153 createDom('input', {
154 className: 'raise',
155 id: 'raise-exceptions',
156 type: 'checkbox'
157 })
158 ));
159 var checkbox = find('#raise-exceptions');
160
161 checkbox.checked = !env.catchingExceptions();
162 checkbox.onclick = onRaiseExceptionsClick;
163
164 if (specsExecuted < totalSpecsDefined) {
165 var skippedMessage = 'Ran ' + specsExecuted + ' of ' + totalSpecsDefined + ' specs - run all';
166 alert.appendChild(
167 createDom('span', {className: 'bar skipped'},
168 // MODIFIED
169 // createDom('a', {href: '?', title: 'Run all specs'}, skippedMessage)
170 createDom('a', {href: '?jasmine', title: 'Run all specs'}, skippedMessage)
171 )
172 );
173 }
174 var statusBarMessage = '';
175 var statusBarClassName = 'bar ';
176
177 if (totalSpecsDefined > 0) {
178 statusBarMessage += pluralize('spec', specsExecuted) + ', ' + pluralize('failure', failureCount);
179 if (pendingSpecCount) { statusBarMessage += ', ' + pluralize('pending spec', pendingSpecCount); }
180 statusBarClassName += (failureCount > 0) ? 'failed' : 'passed';
181 } else {
182 statusBarClassName += 'skipped';
183 statusBarMessage += 'No specs found';
184 }
185
186 alert.appendChild(createDom('span', {className: statusBarClassName}, statusBarMessage));
187
188 for(i = 0; i < failedSuites.length; i++) {
189 var failedSuite = failedSuites[i];
190 for(var j = 0; j < failedSuite.failedExpectations.length; j++) {
191 var errorBarMessage = 'AfterAll ' + failedSuite.failedExpectations[j].message;
192 var errorBarClassName = 'bar errored';
193 alert.appendChild(createDom('span', {className: errorBarClassName}, errorBarMessage));
194 }
195 }
196
197 var results = find('.results');
198 results.appendChild(summary);
199
200 summaryList(topResults, summary);
201
202 function summaryList(resultsTree, domParent) {
203 var specListNode;
204 for (var i = 0; i < resultsTree.children.length; i++) {
205 var resultNode = resultsTree.children[i];
206 if (resultNode.type == 'suite') {
207 var suiteListNode = createDom('ul', {className: 'suite', id: 'suite-' + resultNode.result.id},
208 createDom('li', {className: 'suite-detail'},
209 createDom('a', {href: specHref(resultNode.result)}, resultNode.result.description)
210 )
211 );
212
213 summaryList(resultNode, suiteListNode);
214 domParent.appendChild(suiteListNode);
215 }
216 if (resultNode.type == 'spec') {
217 if (domParent.getAttribute('class') != 'specs') {
218 specListNode = createDom('ul', {className: 'specs'});
219 domParent.appendChild(specListNode);
220 }
221 var specDescription = resultNode.result.description;
222 if(noExpectations(resultNode.result)) {
223 specDescription = 'SPEC HAS NO EXPECTATIONS ' + specDescription;
224 }
225 specListNode.appendChild(
226 createDom('li', {
227 className: resultNode.result.status,
228 id: 'spec-' + resultNode.result.id
229 },
230 createDom('a', {href: specHref(resultNode.result)}, specDescription)
231 )
232 );
233 }
234 }
235 }
236
237 if (failures.length) {
238 alert.appendChild(
239 createDom('span', {className: 'menu bar spec-list'},
240 createDom('span', {}, 'Spec List | '),
241 createDom('a', {className: 'failures-menu', href: '#'}, 'Failures')));
242 alert.appendChild(
243 createDom('span', {className: 'menu bar failure-list'},
244 createDom('a', {className: 'spec-list-menu', href: '#'}, 'Spec List'),
245 createDom('span', {}, ' | Failures ')));
246
247 find('.failures-menu').onclick = function() {
248 setMenuModeTo('failure-list');
249 };
250 find('.spec-list-menu').onclick = function() {
251 setMenuModeTo('spec-list');
252 };
253
254 setMenuModeTo('failure-list');
255
256 var failureNode = find('.failures');
257 for (var i = 0; i < failures.length; i++) {
258 failureNode.appendChild(failures[i]);
259 }
260 }
261 };
262
263 return this;
264
265 function find(selector) {
266 return getContainer().querySelector('.jasmine_html-reporter ' + selector);
267 }
268
269 function clearPrior() {
270 // return the reporter
271 var oldReporter = find('');
272
273 if(oldReporter) {
274 getContainer().removeChild(oldReporter);
275 }
276 }
277
278 function createDom(type, attrs, childrenVarArgs) {
279 var el = createElement(type);
280
281 for (var i = 2; i < arguments.length; i++) {
282 var child = arguments[i];
283
284 if (typeof child === 'string') {
285 el.appendChild(createTextNode(child));
286 } else {
287 if (child) {
288 el.appendChild(child);
289 }
290 }
291 }
292
293 for (var attr in attrs) {
294 if (attr == 'className') {
295 el[attr] = attrs[attr];
296 } else {
297 el.setAttribute(attr, attrs[attr]);
298 }
299 }
300
301 return el;
302 }
303
304 function pluralize(singular, count) {
305 var word = (count == 1 ? singular : singular + 's');
306
307 return '' + count + ' ' + word;
308 }
309
310 function specHref(result) {
311 //MODIFIED
312 // return '?spec=' + encodeURIComponent(result.fullName);
313 return '?jasmine=' + encodeURIComponent(result.fullName);
314 }
315
316 function setMenuModeTo(mode) {
317 htmlReporterMain.setAttribute('class', 'jasmine_html-reporter ' + mode);
318 }
319
320 function noExpectations(result) {
321 return (result.failedExpectations.length + result.passedExpectations.length) === 0 &&
322 result.status === 'passed';
323 }
324 }
325
326 return HtmlReporter;
327 };
328
329 jasmineRequire.HtmlSpecFilter = function() {
330 function HtmlSpecFilter(options) {
331 var filterString = options && options.filterString() && options.filterString().replace(/[-[\]{}()*+?.,\\^$|#\s]/g, '\\$&');
332 var filterPattern = new RegExp(filterString);
333
334 this.matches = function(specName) {
335 return filterPattern.test(specName);
336 };
337 }
338
339 return HtmlSpecFilter;
340 };
341
342 jasmineRequire.ResultsNode = function() {
343 function ResultsNode(result, type, parent) {
344 this.result = result;
345 this.type = type;
346 this.parent = parent;
347
348 this.children = [];
349
350 this.addChild = function(result, type) {
351 this.children.push(new ResultsNode(result, type, this));
352 };
353
354 this.last = function() {
355 return this.children[this.children.length - 1];
356 };
357 }
358
359 return ResultsNode;
360 };
361
362 jasmineRequire.QueryString = function() {
363 function QueryString(options) {
364
365 this.setParam = function(key, value) {
366 var paramMap = queryStringToParamMap();
367 paramMap[key] = value;
368 options.getWindowLocation().search = toQueryString(paramMap);
369 };
370
371 this.getParam = function(key) {
372 return queryStringToParamMap()[key];
373 };
374
375 return this;
376
377 function toQueryString(paramMap) {
378 var qStrPairs = [];
379 for (var prop in paramMap) {
380 qStrPairs.push(encodeURIComponent(prop) + '=' + encodeURIComponent(paramMap[prop]));
381 }
382 return '?' + qStrPairs.join('&');
383 }
384
385 function queryStringToParamMap() {
386 var paramStr = options.getWindowLocation().search.substring(1),
387 params = [],
388 paramMap = {};
389
390 if (paramStr.length > 0) {
391 params = paramStr.split('&');
392 for (var i = 0; i < params.length; i++) {
393 var p = params[i].split('=');
394 var value = decodeURIComponent(p[1]);
395 if (value === 'true' || value === 'false') {
396 value = JSON.parse(value);
397 }
398 paramMap[decodeURIComponent(p[0])] = value;
399 }
400 }
401
402 return paramMap;
403 }
404
405 }
406
407 return QueryString;
408 };