github.com/insionng/yougam@v0.0.0-20170714101924-2bc18d833463/themes/wind/static/libs/vue-1.0.24/test/unit/lib/jasmine-html.js (about) 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 51 this.initialize = function() { 52 clearPrior(); 53 htmlReporterMain = createDom('div', {className: 'jasmine_html-reporter'}, 54 createDom('div', {className: 'banner'}, 55 createDom('a', {className: 'title', href: 'http://jasmine.github.io/', target: '_blank'}), 56 createDom('span', {className: 'version'}, j$.version) 57 ), 58 createDom('ul', {className: 'symbol-summary'}), 59 createDom('div', {className: 'alert'}), 60 createDom('div', {className: 'results'}, 61 createDom('div', {className: 'failures'}) 62 ) 63 ); 64 getContainer().appendChild(htmlReporterMain); 65 66 symbols = find('.symbol-summary'); 67 }; 68 69 var totalSpecsDefined; 70 this.jasmineStarted = function(options) { 71 totalSpecsDefined = options.totalSpecsDefined || 0; 72 timer.start(); 73 }; 74 75 var summary = createDom('div', {className: 'summary'}); 76 77 var topResults = new j$.ResultsNode({}, '', null), 78 currentParent = topResults; 79 80 this.suiteStarted = function(result) { 81 currentParent.addChild(result, 'suite'); 82 currentParent = currentParent.last(); 83 }; 84 85 this.suiteDone = function(result) { 86 if (currentParent == topResults) { 87 return; 88 } 89 90 currentParent = currentParent.parent; 91 }; 92 93 this.specStarted = function(result) { 94 currentParent.addChild(result, 'spec'); 95 }; 96 97 var failures = []; 98 this.specDone = function(result) { 99 if(noExpectations(result) && console && console.error) { 100 console.error('Spec \'' + result.fullName + '\' has no expectations.'); 101 } 102 103 if (result.status != 'disabled') { 104 specsExecuted++; 105 } 106 107 symbols.appendChild(createDom('li', { 108 className: noExpectations(result) ? 'empty' : result.status, 109 id: 'spec_' + result.id, 110 title: result.fullName 111 } 112 )); 113 114 if (result.status == 'failed') { 115 failureCount++; 116 117 var failure = 118 createDom('div', {className: 'spec-detail failed'}, 119 createDom('div', {className: 'description'}, 120 createDom('a', {title: result.fullName, href: specHref(result)}, result.fullName) 121 ), 122 createDom('div', {className: 'messages'}) 123 ); 124 var messages = failure.childNodes[1]; 125 126 for (var i = 0; i < result.failedExpectations.length; i++) { 127 var expectation = result.failedExpectations[i]; 128 messages.appendChild(createDom('div', {className: 'result-message'}, expectation.message)); 129 messages.appendChild(createDom('div', {className: 'stack-trace'}, expectation.stack)); 130 } 131 132 failures.push(failure); 133 } 134 135 if (result.status == 'pending') { 136 pendingSpecCount++; 137 } 138 }; 139 140 this.jasmineDone = function() { 141 var banner = find('.banner'); 142 banner.appendChild(createDom('span', {className: 'duration'}, 'finished in ' + timer.elapsed() / 1000 + 's')); 143 144 var alert = find('.alert'); 145 146 alert.appendChild(createDom('span', { className: 'exceptions' }, 147 createDom('label', { className: 'label', 'for': 'raise-exceptions' }, 'raise exceptions'), 148 createDom('input', { 149 className: 'raise', 150 id: 'raise-exceptions', 151 type: 'checkbox' 152 }) 153 )); 154 var checkbox = find('#raise-exceptions'); 155 156 checkbox.checked = !env.catchingExceptions(); 157 checkbox.onclick = onRaiseExceptionsClick; 158 159 if (specsExecuted < totalSpecsDefined) { 160 var skippedMessage = 'Ran ' + specsExecuted + ' of ' + totalSpecsDefined + ' specs - run all'; 161 alert.appendChild( 162 createDom('span', {className: 'bar skipped'}, 163 createDom('a', {href: '?', title: 'Run all specs'}, skippedMessage) 164 ) 165 ); 166 } 167 var statusBarMessage = ''; 168 var statusBarClassName = 'bar '; 169 170 if (totalSpecsDefined > 0) { 171 statusBarMessage += pluralize('spec', specsExecuted) + ', ' + pluralize('failure', failureCount); 172 if (pendingSpecCount) { statusBarMessage += ', ' + pluralize('pending spec', pendingSpecCount); } 173 statusBarClassName += (failureCount > 0) ? 'failed' : 'passed'; 174 } else { 175 statusBarClassName += 'skipped'; 176 statusBarMessage += 'No specs found'; 177 } 178 179 alert.appendChild(createDom('span', {className: statusBarClassName}, statusBarMessage)); 180 181 var results = find('.results'); 182 results.appendChild(summary); 183 184 summaryList(topResults, summary); 185 186 function summaryList(resultsTree, domParent) { 187 var specListNode; 188 for (var i = 0; i < resultsTree.children.length; i++) { 189 var resultNode = resultsTree.children[i]; 190 if (resultNode.type == 'suite') { 191 var suiteListNode = createDom('ul', {className: 'suite', id: 'suite-' + resultNode.result.id}, 192 createDom('li', {className: 'suite-detail'}, 193 createDom('a', {href: specHref(resultNode.result)}, resultNode.result.description) 194 ) 195 ); 196 197 summaryList(resultNode, suiteListNode); 198 domParent.appendChild(suiteListNode); 199 } 200 if (resultNode.type == 'spec') { 201 if (domParent.getAttribute('class') != 'specs') { 202 specListNode = createDom('ul', {className: 'specs'}); 203 domParent.appendChild(specListNode); 204 } 205 var specDescription = resultNode.result.description; 206 if(noExpectations(resultNode.result)) { 207 specDescription = 'SPEC HAS NO EXPECTATIONS ' + specDescription; 208 } 209 specListNode.appendChild( 210 createDom('li', { 211 className: resultNode.result.status, 212 id: 'spec-' + resultNode.result.id 213 }, 214 createDom('a', {href: specHref(resultNode.result)}, specDescription) 215 ) 216 ); 217 } 218 } 219 } 220 221 if (failures.length) { 222 alert.appendChild( 223 createDom('span', {className: 'menu bar spec-list'}, 224 createDom('span', {}, 'Spec List | '), 225 createDom('a', {className: 'failures-menu', href: '#'}, 'Failures'))); 226 alert.appendChild( 227 createDom('span', {className: 'menu bar failure-list'}, 228 createDom('a', {className: 'spec-list-menu', href: '#'}, 'Spec List'), 229 createDom('span', {}, ' | Failures '))); 230 231 find('.failures-menu').onclick = function() { 232 setMenuModeTo('failure-list'); 233 }; 234 find('.spec-list-menu').onclick = function() { 235 setMenuModeTo('spec-list'); 236 }; 237 238 setMenuModeTo('failure-list'); 239 240 var failureNode = find('.failures'); 241 for (var i = 0; i < failures.length; i++) { 242 failureNode.appendChild(failures[i]); 243 } 244 } 245 }; 246 247 return this; 248 249 function find(selector) { 250 return getContainer().querySelector('.jasmine_html-reporter ' + selector); 251 } 252 253 function clearPrior() { 254 // return the reporter 255 var oldReporter = find(''); 256 257 if(oldReporter) { 258 getContainer().removeChild(oldReporter); 259 } 260 } 261 262 function createDom(type, attrs, childrenVarArgs) { 263 var el = createElement(type); 264 265 for (var i = 2; i < arguments.length; i++) { 266 var child = arguments[i]; 267 268 if (typeof child === 'string') { 269 el.appendChild(createTextNode(child)); 270 } else { 271 if (child) { 272 el.appendChild(child); 273 } 274 } 275 } 276 277 for (var attr in attrs) { 278 if (attr == 'className') { 279 el[attr] = attrs[attr]; 280 } else { 281 el.setAttribute(attr, attrs[attr]); 282 } 283 } 284 285 return el; 286 } 287 288 function pluralize(singular, count) { 289 var word = (count == 1 ? singular : singular + 's'); 290 291 return '' + count + ' ' + word; 292 } 293 294 function specHref(result) { 295 return '?spec=' + encodeURIComponent(result.fullName); 296 } 297 298 function setMenuModeTo(mode) { 299 htmlReporterMain.setAttribute('class', 'jasmine_html-reporter ' + mode); 300 } 301 302 function noExpectations(result) { 303 return (result.failedExpectations.length + result.passedExpectations.length) === 0 && 304 result.status === 'passed'; 305 } 306 } 307 308 return HtmlReporter; 309 }; 310 311 jasmineRequire.HtmlSpecFilter = function() { 312 function HtmlSpecFilter(options) { 313 var filterString = options && options.filterString() && options.filterString().replace(/[-[\]{}()*+?.,\\^$|#\s]/g, '\\$&'); 314 var filterPattern = new RegExp(filterString); 315 316 this.matches = function(specName) { 317 return filterPattern.test(specName); 318 }; 319 } 320 321 return HtmlSpecFilter; 322 }; 323 324 jasmineRequire.ResultsNode = function() { 325 function ResultsNode(result, type, parent) { 326 this.result = result; 327 this.type = type; 328 this.parent = parent; 329 330 this.children = []; 331 332 this.addChild = function(result, type) { 333 this.children.push(new ResultsNode(result, type, this)); 334 }; 335 336 this.last = function() { 337 return this.children[this.children.length - 1]; 338 }; 339 } 340 341 return ResultsNode; 342 }; 343 344 jasmineRequire.QueryString = function() { 345 function QueryString(options) { 346 347 this.setParam = function(key, value) { 348 var paramMap = queryStringToParamMap(); 349 paramMap[key] = value; 350 options.getWindowLocation().search = toQueryString(paramMap); 351 }; 352 353 this.getParam = function(key) { 354 return queryStringToParamMap()[key]; 355 }; 356 357 return this; 358 359 function toQueryString(paramMap) { 360 var qStrPairs = []; 361 for (var prop in paramMap) { 362 qStrPairs.push(encodeURIComponent(prop) + '=' + encodeURIComponent(paramMap[prop])); 363 } 364 return '?' + qStrPairs.join('&'); 365 } 366 367 function queryStringToParamMap() { 368 var paramStr = options.getWindowLocation().search.substring(1), 369 params = [], 370 paramMap = {}; 371 372 if (paramStr.length > 0) { 373 params = paramStr.split('&'); 374 for (var i = 0; i < params.length; i++) { 375 var p = params[i].split('='); 376 var value = decodeURIComponent(p[1]); 377 if (value === 'true' || value === 'false') { 378 value = JSON.parse(value); 379 } 380 paramMap[decodeURIComponent(p[0])] = value; 381 } 382 } 383 384 return paramMap; 385 } 386 387 } 388 389 return QueryString; 390 };