[6a3a178] | 1 | /*
|
---|
| 2 | Copyright (c) 2008-2021 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 | var jasmineRequire = window.jasmineRequire || require('./jasmine.js');
|
---|
| 24 |
|
---|
| 25 | jasmineRequire.html = function (j$) {
|
---|
| 26 | j$.ResultsNode = jasmineRequire.ResultsNode();
|
---|
| 27 | j$.HtmlReporter = jasmineRequire.HtmlReporter(j$);
|
---|
| 28 | j$.QueryString = jasmineRequire.QueryString();
|
---|
| 29 | j$.HtmlSpecFilter = jasmineRequire.HtmlSpecFilter();
|
---|
| 30 | };
|
---|
| 31 |
|
---|
| 32 | jasmineRequire.HtmlReporter = function (j$) {
|
---|
| 33 | function ResultsStateBuilder() {
|
---|
| 34 | this.topResults = new j$.ResultsNode({}, '', null);
|
---|
| 35 | this.currentParent = this.topResults;
|
---|
| 36 | this.specsExecuted = 0;
|
---|
| 37 | this.failureCount = 0;
|
---|
| 38 | this.pendingSpecCount = 0;
|
---|
| 39 | }
|
---|
| 40 |
|
---|
| 41 | ResultsStateBuilder.prototype.suiteStarted = function (result) {
|
---|
| 42 | this.currentParent.addChild(result, 'suite');
|
---|
| 43 | this.currentParent = this.currentParent.last();
|
---|
| 44 | };
|
---|
| 45 |
|
---|
| 46 | ResultsStateBuilder.prototype.suiteDone = function (result) {
|
---|
| 47 | this.currentParent.updateResult(result);
|
---|
| 48 | if (this.currentParent !== this.topResults) {
|
---|
| 49 | this.currentParent = this.currentParent.parent;
|
---|
| 50 | }
|
---|
| 51 |
|
---|
| 52 | if (result.status === 'failed') {
|
---|
| 53 | this.failureCount++;
|
---|
| 54 | }
|
---|
| 55 | };
|
---|
| 56 |
|
---|
| 57 | ResultsStateBuilder.prototype.specStarted = function (result) { };
|
---|
| 58 |
|
---|
| 59 | ResultsStateBuilder.prototype.specDone = function (result) {
|
---|
| 60 | this.currentParent.addChild(result, 'spec');
|
---|
| 61 |
|
---|
| 62 | if (result.status !== 'excluded') {
|
---|
| 63 | this.specsExecuted++;
|
---|
| 64 | }
|
---|
| 65 |
|
---|
| 66 | if (result.status === 'failed') {
|
---|
| 67 | this.failureCount++;
|
---|
| 68 | }
|
---|
| 69 |
|
---|
| 70 | if (result.status == 'pending') {
|
---|
| 71 | this.pendingSpecCount++;
|
---|
| 72 | }
|
---|
| 73 | };
|
---|
| 74 |
|
---|
| 75 | function HtmlReporter(options) {
|
---|
| 76 | var config = function () {
|
---|
| 77 | return (options.env && options.env.configuration()) || {};
|
---|
| 78 | },
|
---|
| 79 | getContainer = options.getContainer,
|
---|
| 80 | createElement = options.createElement,
|
---|
| 81 | createTextNode = options.createTextNode,
|
---|
| 82 | navigateWithNewParam = options.navigateWithNewParam || function () { },
|
---|
| 83 | addToExistingQueryString =
|
---|
| 84 | options.addToExistingQueryString || defaultQueryString,
|
---|
| 85 | filterSpecs = options.filterSpecs,
|
---|
| 86 | htmlReporterMain,
|
---|
| 87 | symbols,
|
---|
| 88 | deprecationWarnings = [];
|
---|
| 89 |
|
---|
| 90 | this.initialize = function () {
|
---|
| 91 | clearPrior();
|
---|
| 92 | htmlReporterMain = createDom(
|
---|
| 93 | 'div',
|
---|
| 94 | { className: 'jasmine_html-reporter' },
|
---|
| 95 | createDom(
|
---|
| 96 | 'div',
|
---|
| 97 | { className: 'jasmine-banner' },
|
---|
| 98 | createDom('a', {
|
---|
| 99 | className: 'jasmine-title',
|
---|
| 100 | href: 'http://jasmine.github.io/',
|
---|
| 101 | target: '_blank'
|
---|
| 102 | }),
|
---|
| 103 | createDom('span', { className: 'jasmine-version' }, j$.version)
|
---|
| 104 | ),
|
---|
| 105 | createDom('ul', { className: 'jasmine-symbol-summary' }),
|
---|
| 106 | createDom('div', { className: 'jasmine-alert' }),
|
---|
| 107 | createDom(
|
---|
| 108 | 'div',
|
---|
| 109 | { className: 'jasmine-results' },
|
---|
| 110 | createDom('div', { className: 'jasmine-failures' })
|
---|
| 111 | )
|
---|
| 112 | );
|
---|
| 113 | getContainer().appendChild(htmlReporterMain);
|
---|
| 114 | };
|
---|
| 115 |
|
---|
| 116 | var totalSpecsDefined;
|
---|
| 117 | this.jasmineStarted = function (options) {
|
---|
| 118 | totalSpecsDefined = options.totalSpecsDefined || 0;
|
---|
| 119 | };
|
---|
| 120 |
|
---|
| 121 | var summary = createDom('div', { className: 'jasmine-summary' });
|
---|
| 122 |
|
---|
| 123 | var stateBuilder = new ResultsStateBuilder();
|
---|
| 124 |
|
---|
| 125 | this.suiteStarted = function (result) {
|
---|
| 126 | stateBuilder.suiteStarted(result);
|
---|
| 127 | };
|
---|
| 128 |
|
---|
| 129 | this.suiteDone = function (result) {
|
---|
| 130 | stateBuilder.suiteDone(result);
|
---|
| 131 |
|
---|
| 132 | if (result.status === 'failed') {
|
---|
| 133 | failures.push(failureDom(result));
|
---|
| 134 | }
|
---|
| 135 | addDeprecationWarnings(result, 'suite');
|
---|
| 136 | };
|
---|
| 137 |
|
---|
| 138 | this.specStarted = function (result) {
|
---|
| 139 | stateBuilder.specStarted(result);
|
---|
| 140 | };
|
---|
| 141 |
|
---|
| 142 | var failures = [];
|
---|
| 143 | this.specDone = function (result) {
|
---|
| 144 | stateBuilder.specDone(result);
|
---|
| 145 |
|
---|
| 146 | if (noExpectations(result)) {
|
---|
| 147 | var noSpecMsg = "Spec '" + result.fullName + "' has no expectations.";
|
---|
| 148 | if (result.status === 'failed') {
|
---|
| 149 | console.error(noSpecMsg);
|
---|
| 150 | } else {
|
---|
| 151 | console.warn(noSpecMsg);
|
---|
| 152 | }
|
---|
| 153 | }
|
---|
| 154 |
|
---|
| 155 | if (!symbols) {
|
---|
| 156 | symbols = find('.jasmine-symbol-summary');
|
---|
| 157 | }
|
---|
| 158 |
|
---|
| 159 | symbols.appendChild(
|
---|
| 160 | createDom('li', {
|
---|
| 161 | className: this.displaySpecInCorrectFormat(result),
|
---|
| 162 | id: 'spec_' + result.id,
|
---|
| 163 | title: result.fullName
|
---|
| 164 | })
|
---|
| 165 | );
|
---|
| 166 |
|
---|
| 167 | if (result.status === 'failed') {
|
---|
| 168 | failures.push(failureDom(result));
|
---|
| 169 | }
|
---|
| 170 |
|
---|
| 171 | addDeprecationWarnings(result, 'spec');
|
---|
| 172 | };
|
---|
| 173 |
|
---|
| 174 | this.displaySpecInCorrectFormat = function (result) {
|
---|
| 175 | return noExpectations(result) && result.status === 'passed'
|
---|
| 176 | ? 'jasmine-empty'
|
---|
| 177 | : this.resultStatus(result.status);
|
---|
| 178 | };
|
---|
| 179 |
|
---|
| 180 | this.resultStatus = function (status) {
|
---|
| 181 | if (status === 'excluded') {
|
---|
| 182 | return config().hideDisabled
|
---|
| 183 | ? 'jasmine-excluded-no-display'
|
---|
| 184 | : 'jasmine-excluded';
|
---|
| 185 | }
|
---|
| 186 | return 'jasmine-' + status;
|
---|
| 187 | };
|
---|
| 188 |
|
---|
| 189 | this.jasmineDone = function (doneResult) {
|
---|
| 190 | var banner = find('.jasmine-banner');
|
---|
| 191 | var alert = find('.jasmine-alert');
|
---|
| 192 | var order = doneResult && doneResult.order;
|
---|
| 193 | var i;
|
---|
| 194 | alert.appendChild(
|
---|
| 195 | createDom(
|
---|
| 196 | 'span',
|
---|
| 197 | { className: 'jasmine-duration' },
|
---|
| 198 | 'finished in ' + doneResult.totalTime / 1000 + 's'
|
---|
| 199 | )
|
---|
| 200 | );
|
---|
| 201 |
|
---|
| 202 | banner.appendChild(optionsMenu(config()));
|
---|
| 203 |
|
---|
| 204 | if (stateBuilder.specsExecuted < totalSpecsDefined) {
|
---|
| 205 | var skippedMessage =
|
---|
| 206 | 'Ran ' +
|
---|
| 207 | stateBuilder.specsExecuted +
|
---|
| 208 | ' of ' +
|
---|
| 209 | totalSpecsDefined +
|
---|
| 210 | ' specs - run all';
|
---|
| 211 | // include window.location.pathname to fix issue with karma-jasmine-html-reporter in angular: see https://github.com/jasmine/jasmine/issues/1906
|
---|
| 212 | var skippedLink =
|
---|
| 213 | (window.location.pathname || '') +
|
---|
| 214 | addToExistingQueryString('spec', '');
|
---|
| 215 | alert.appendChild(
|
---|
| 216 | createDom(
|
---|
| 217 | 'span',
|
---|
| 218 | { className: 'jasmine-bar jasmine-skipped' },
|
---|
| 219 | createDom(
|
---|
| 220 | 'a',
|
---|
| 221 | { href: skippedLink, title: 'Run all specs' },
|
---|
| 222 | skippedMessage
|
---|
| 223 | )
|
---|
| 224 | )
|
---|
| 225 | );
|
---|
| 226 | }
|
---|
| 227 | var statusBarMessage = '';
|
---|
| 228 | var statusBarClassName = 'jasmine-overall-result jasmine-bar ';
|
---|
| 229 | var globalFailures = (doneResult && doneResult.failedExpectations) || [];
|
---|
| 230 | var failed = stateBuilder.failureCount + globalFailures.length > 0;
|
---|
| 231 |
|
---|
| 232 | if (totalSpecsDefined > 0 || failed) {
|
---|
| 233 | statusBarMessage +=
|
---|
| 234 | pluralize('spec', stateBuilder.specsExecuted) +
|
---|
| 235 | ', ' +
|
---|
| 236 | pluralize('failure', stateBuilder.failureCount);
|
---|
| 237 | if (stateBuilder.pendingSpecCount) {
|
---|
| 238 | statusBarMessage +=
|
---|
| 239 | ', ' + pluralize('pending spec', stateBuilder.pendingSpecCount);
|
---|
| 240 | }
|
---|
| 241 | }
|
---|
| 242 |
|
---|
| 243 | if (doneResult.overallStatus === 'passed') {
|
---|
| 244 | statusBarClassName += ' jasmine-passed ';
|
---|
| 245 | } else if (doneResult.overallStatus === 'incomplete') {
|
---|
| 246 | statusBarClassName += ' jasmine-incomplete ';
|
---|
| 247 | statusBarMessage =
|
---|
| 248 | 'Incomplete: ' +
|
---|
| 249 | doneResult.incompleteReason +
|
---|
| 250 | ', ' +
|
---|
| 251 | statusBarMessage;
|
---|
| 252 | } else {
|
---|
| 253 | statusBarClassName += ' jasmine-failed ';
|
---|
| 254 | }
|
---|
| 255 |
|
---|
| 256 | var seedBar;
|
---|
| 257 | if (order && order.random) {
|
---|
| 258 | seedBar = createDom(
|
---|
| 259 | 'span',
|
---|
| 260 | { className: 'jasmine-seed-bar' },
|
---|
| 261 | ', randomized with seed ',
|
---|
| 262 | createDom(
|
---|
| 263 | 'a',
|
---|
| 264 | {
|
---|
| 265 | title: 'randomized with seed ' + order.seed,
|
---|
| 266 | href: seedHref(order.seed)
|
---|
| 267 | },
|
---|
| 268 | order.seed
|
---|
| 269 | )
|
---|
| 270 | );
|
---|
| 271 | }
|
---|
| 272 |
|
---|
| 273 | alert.appendChild(
|
---|
| 274 | createDom(
|
---|
| 275 | 'span',
|
---|
| 276 | { className: statusBarClassName },
|
---|
| 277 | statusBarMessage,
|
---|
| 278 | seedBar
|
---|
| 279 | )
|
---|
| 280 | );
|
---|
| 281 |
|
---|
| 282 | var errorBarClassName = 'jasmine-bar jasmine-errored';
|
---|
| 283 | var afterAllMessagePrefix = 'AfterAll ';
|
---|
| 284 |
|
---|
| 285 | for (i = 0; i < globalFailures.length; i++) {
|
---|
| 286 | alert.appendChild(
|
---|
| 287 | createDom(
|
---|
| 288 | 'span',
|
---|
| 289 | { className: errorBarClassName },
|
---|
| 290 | globalFailureMessage(globalFailures[i])
|
---|
| 291 | )
|
---|
| 292 | );
|
---|
| 293 | }
|
---|
| 294 |
|
---|
| 295 | function globalFailureMessage(failure) {
|
---|
| 296 | if (failure.globalErrorType === 'load') {
|
---|
| 297 | var prefix = 'Error during loading: ' + failure.message;
|
---|
| 298 |
|
---|
| 299 | if (failure.filename) {
|
---|
| 300 | return (
|
---|
| 301 | prefix + ' in ' + failure.filename + ' line ' + failure.lineno
|
---|
| 302 | );
|
---|
| 303 | } else {
|
---|
| 304 | return prefix;
|
---|
| 305 | }
|
---|
| 306 | } else {
|
---|
| 307 | return afterAllMessagePrefix + failure.message;
|
---|
| 308 | }
|
---|
| 309 | }
|
---|
| 310 |
|
---|
| 311 | addDeprecationWarnings(doneResult);
|
---|
| 312 |
|
---|
| 313 | for (i = 0; i < deprecationWarnings.length; i++) {
|
---|
| 314 | var context;
|
---|
| 315 |
|
---|
| 316 | switch (deprecationWarnings[i].runnableType) {
|
---|
| 317 | case 'spec':
|
---|
| 318 | context = '(in spec: ' + deprecationWarnings[i].runnableName + ')';
|
---|
| 319 | break;
|
---|
| 320 | case 'suite':
|
---|
| 321 | context = '(in suite: ' + deprecationWarnings[i].runnableName + ')';
|
---|
| 322 | break;
|
---|
| 323 | default:
|
---|
| 324 | context = '';
|
---|
| 325 | }
|
---|
| 326 |
|
---|
| 327 | alert.appendChild(
|
---|
| 328 | createDom(
|
---|
| 329 | 'span',
|
---|
| 330 | { className: 'jasmine-bar jasmine-warning' },
|
---|
| 331 | 'DEPRECATION: ' + deprecationWarnings[i].message,
|
---|
| 332 | createDom('br'),
|
---|
| 333 | context
|
---|
| 334 | )
|
---|
| 335 | );
|
---|
| 336 | }
|
---|
| 337 |
|
---|
| 338 | var results = find('.jasmine-results');
|
---|
| 339 | results.appendChild(summary);
|
---|
| 340 |
|
---|
| 341 | summaryList(stateBuilder.topResults, summary);
|
---|
| 342 |
|
---|
| 343 | if (failures.length) {
|
---|
| 344 | alert.appendChild(
|
---|
| 345 | createDom(
|
---|
| 346 | 'span',
|
---|
| 347 | { className: 'jasmine-menu jasmine-bar jasmine-spec-list' },
|
---|
| 348 | createDom('span', {}, 'Spec List | '),
|
---|
| 349 | createDom(
|
---|
| 350 | 'a',
|
---|
| 351 | { className: 'jasmine-failures-menu', href: '#' },
|
---|
| 352 | 'Failures'
|
---|
| 353 | )
|
---|
| 354 | )
|
---|
| 355 | );
|
---|
| 356 | alert.appendChild(
|
---|
| 357 | createDom(
|
---|
| 358 | 'span',
|
---|
| 359 | { className: 'jasmine-menu jasmine-bar jasmine-failure-list' },
|
---|
| 360 | createDom(
|
---|
| 361 | 'a',
|
---|
| 362 | { className: 'jasmine-spec-list-menu', href: '#' },
|
---|
| 363 | 'Spec List'
|
---|
| 364 | ),
|
---|
| 365 | createDom('span', {}, ' | Failures ')
|
---|
| 366 | )
|
---|
| 367 | );
|
---|
| 368 |
|
---|
| 369 | find('.jasmine-failures-menu').onclick = function () {
|
---|
| 370 | setMenuModeTo('jasmine-failure-list');
|
---|
| 371 | return false;
|
---|
| 372 | };
|
---|
| 373 | find('.jasmine-spec-list-menu').onclick = function () {
|
---|
| 374 | setMenuModeTo('jasmine-spec-list');
|
---|
| 375 | return false;
|
---|
| 376 | };
|
---|
| 377 |
|
---|
| 378 | setMenuModeTo('jasmine-failure-list');
|
---|
| 379 |
|
---|
| 380 | var failureNode = find('.jasmine-failures');
|
---|
| 381 | for (i = 0; i < failures.length; i++) {
|
---|
| 382 | failureNode.appendChild(failures[i]);
|
---|
| 383 | }
|
---|
| 384 | }
|
---|
| 385 | };
|
---|
| 386 |
|
---|
| 387 | return this;
|
---|
| 388 |
|
---|
| 389 | function failureDom(result) {
|
---|
| 390 | var failure = createDom(
|
---|
| 391 | 'div',
|
---|
| 392 | { className: 'jasmine-spec-detail jasmine-failed' },
|
---|
| 393 | failureDescription(result, stateBuilder.currentParent),
|
---|
| 394 | createDom('div', { className: 'jasmine-messages' })
|
---|
| 395 | );
|
---|
| 396 | var messages = failure.childNodes[1];
|
---|
| 397 |
|
---|
| 398 | for (var i = 0; i < result.failedExpectations.length; i++) {
|
---|
| 399 | var expectation = result.failedExpectations[i];
|
---|
| 400 | messages.appendChild(
|
---|
| 401 | createDom(
|
---|
| 402 | 'div',
|
---|
| 403 | { className: 'jasmine-result-message' },
|
---|
| 404 | expectation.message
|
---|
| 405 | )
|
---|
| 406 | );
|
---|
| 407 | messages.appendChild(
|
---|
| 408 | createDom(
|
---|
| 409 | 'div',
|
---|
| 410 | { className: 'jasmine-stack-trace' },
|
---|
| 411 | expectation.stack
|
---|
| 412 | )
|
---|
| 413 | );
|
---|
| 414 | }
|
---|
| 415 |
|
---|
| 416 | if (result.failedExpectations.length === 0) {
|
---|
| 417 | messages.appendChild(
|
---|
| 418 | createDom(
|
---|
| 419 | 'div',
|
---|
| 420 | { className: 'jasmine-result-message' },
|
---|
| 421 | 'Spec has no expectations'
|
---|
| 422 | )
|
---|
| 423 | );
|
---|
| 424 | }
|
---|
| 425 |
|
---|
| 426 | return failure;
|
---|
| 427 | }
|
---|
| 428 |
|
---|
| 429 | function summaryList(resultsTree, domParent) {
|
---|
| 430 | var specListNode;
|
---|
| 431 | for (var i = 0; i < resultsTree.children.length; i++) {
|
---|
| 432 | var resultNode = resultsTree.children[i];
|
---|
| 433 | if (filterSpecs && !hasActiveSpec(resultNode)) {
|
---|
| 434 | continue;
|
---|
| 435 | }
|
---|
| 436 | if (resultNode.type === 'suite') {
|
---|
| 437 | var suiteListNode = createDom(
|
---|
| 438 | 'ul',
|
---|
| 439 | { className: 'jasmine-suite', id: 'suite-' + resultNode.result.id },
|
---|
| 440 | createDom(
|
---|
| 441 | 'li',
|
---|
| 442 | {
|
---|
| 443 | className:
|
---|
| 444 | 'jasmine-suite-detail jasmine-' + resultNode.result.status
|
---|
| 445 | },
|
---|
| 446 | createDom(
|
---|
| 447 | 'a',
|
---|
| 448 | { href: specHref(resultNode.result) },
|
---|
| 449 | resultNode.result.description
|
---|
| 450 | )
|
---|
| 451 | )
|
---|
| 452 | );
|
---|
| 453 |
|
---|
| 454 | summaryList(resultNode, suiteListNode);
|
---|
| 455 | domParent.appendChild(suiteListNode);
|
---|
| 456 | }
|
---|
| 457 | if (resultNode.type === 'spec') {
|
---|
| 458 | if (domParent.getAttribute('class') !== 'jasmine-specs') {
|
---|
| 459 | specListNode = createDom('ul', { className: 'jasmine-specs' });
|
---|
| 460 | domParent.appendChild(specListNode);
|
---|
| 461 | }
|
---|
| 462 | var specDescription = resultNode.result.description;
|
---|
| 463 | if (noExpectations(resultNode.result)) {
|
---|
| 464 | specDescription = 'SPEC HAS NO EXPECTATIONS ' + specDescription;
|
---|
| 465 | }
|
---|
| 466 | if (
|
---|
| 467 | resultNode.result.status === 'pending' &&
|
---|
| 468 | resultNode.result.pendingReason !== ''
|
---|
| 469 | ) {
|
---|
| 470 | specDescription =
|
---|
| 471 | specDescription +
|
---|
| 472 | ' PENDING WITH MESSAGE: ' +
|
---|
| 473 | resultNode.result.pendingReason;
|
---|
| 474 | }
|
---|
| 475 | specListNode.appendChild(
|
---|
| 476 | createDom(
|
---|
| 477 | 'li',
|
---|
| 478 | {
|
---|
| 479 | className: 'jasmine-' + resultNode.result.status,
|
---|
| 480 | id: 'spec-' + resultNode.result.id
|
---|
| 481 | },
|
---|
| 482 | createDom(
|
---|
| 483 | 'a',
|
---|
| 484 | { href: specHref(resultNode.result) },
|
---|
| 485 | specDescription
|
---|
| 486 | )
|
---|
| 487 | )
|
---|
| 488 | );
|
---|
| 489 | }
|
---|
| 490 | }
|
---|
| 491 | }
|
---|
| 492 |
|
---|
| 493 | function optionsMenu(config) {
|
---|
| 494 | var optionsMenuDom = createDom(
|
---|
| 495 | 'div',
|
---|
| 496 | { className: 'jasmine-run-options' },
|
---|
| 497 | createDom('span', { className: 'jasmine-trigger' }, 'Options'),
|
---|
| 498 | createDom(
|
---|
| 499 | 'div',
|
---|
| 500 | { className: 'jasmine-payload' },
|
---|
| 501 | createDom(
|
---|
| 502 | 'div',
|
---|
| 503 | { className: 'jasmine-stop-on-failure' },
|
---|
| 504 | createDom('input', {
|
---|
| 505 | className: 'jasmine-fail-fast',
|
---|
| 506 | id: 'jasmine-fail-fast',
|
---|
| 507 | type: 'checkbox'
|
---|
| 508 | }),
|
---|
| 509 | createDom(
|
---|
| 510 | 'label',
|
---|
| 511 | { className: 'jasmine-label', for: 'jasmine-fail-fast' },
|
---|
| 512 | 'stop execution on spec failure'
|
---|
| 513 | )
|
---|
| 514 | ),
|
---|
| 515 | createDom(
|
---|
| 516 | 'div',
|
---|
| 517 | { className: 'jasmine-throw-failures' },
|
---|
| 518 | createDom('input', {
|
---|
| 519 | className: 'jasmine-throw',
|
---|
| 520 | id: 'jasmine-throw-failures',
|
---|
| 521 | type: 'checkbox'
|
---|
| 522 | }),
|
---|
| 523 | createDom(
|
---|
| 524 | 'label',
|
---|
| 525 | { className: 'jasmine-label', for: 'jasmine-throw-failures' },
|
---|
| 526 | 'stop spec on expectation failure'
|
---|
| 527 | )
|
---|
| 528 | ),
|
---|
| 529 | createDom(
|
---|
| 530 | 'div',
|
---|
| 531 | { className: 'jasmine-random-order' },
|
---|
| 532 | createDom('input', {
|
---|
| 533 | className: 'jasmine-random',
|
---|
| 534 | id: 'jasmine-random-order',
|
---|
| 535 | type: 'checkbox'
|
---|
| 536 | }),
|
---|
| 537 | createDom(
|
---|
| 538 | 'label',
|
---|
| 539 | { className: 'jasmine-label', for: 'jasmine-random-order' },
|
---|
| 540 | 'run tests in random order'
|
---|
| 541 | )
|
---|
| 542 | ),
|
---|
| 543 | createDom(
|
---|
| 544 | 'div',
|
---|
| 545 | { className: 'jasmine-hide-disabled' },
|
---|
| 546 | createDom('input', {
|
---|
| 547 | className: 'jasmine-disabled',
|
---|
| 548 | id: 'jasmine-hide-disabled',
|
---|
| 549 | type: 'checkbox'
|
---|
| 550 | }),
|
---|
| 551 | createDom(
|
---|
| 552 | 'label',
|
---|
| 553 | { className: 'jasmine-label', for: 'jasmine-hide-disabled' },
|
---|
| 554 | 'hide disabled tests'
|
---|
| 555 | )
|
---|
| 556 | )
|
---|
| 557 | )
|
---|
| 558 | );
|
---|
| 559 |
|
---|
| 560 | var failFastCheckbox = optionsMenuDom.querySelector('#jasmine-fail-fast');
|
---|
| 561 | failFastCheckbox.checked = config.failFast;
|
---|
| 562 | failFastCheckbox.onclick = function () {
|
---|
| 563 | navigateWithNewParam('failFast', !config.failFast);
|
---|
| 564 | };
|
---|
| 565 |
|
---|
| 566 | var throwCheckbox = optionsMenuDom.querySelector(
|
---|
| 567 | '#jasmine-throw-failures'
|
---|
| 568 | );
|
---|
| 569 | throwCheckbox.checked = config.oneFailurePerSpec;
|
---|
| 570 | throwCheckbox.onclick = function () {
|
---|
| 571 | navigateWithNewParam('oneFailurePerSpec', !config.oneFailurePerSpec);
|
---|
| 572 | };
|
---|
| 573 |
|
---|
| 574 | var randomCheckbox = optionsMenuDom.querySelector(
|
---|
| 575 | '#jasmine-random-order'
|
---|
| 576 | );
|
---|
| 577 | randomCheckbox.checked = config.random;
|
---|
| 578 | randomCheckbox.onclick = function () {
|
---|
| 579 | navigateWithNewParam('random', !config.random);
|
---|
| 580 | };
|
---|
| 581 |
|
---|
| 582 | var hideDisabled = optionsMenuDom.querySelector('#jasmine-hide-disabled');
|
---|
| 583 | hideDisabled.checked = config.hideDisabled;
|
---|
| 584 | hideDisabled.onclick = function () {
|
---|
| 585 | navigateWithNewParam('hideDisabled', !config.hideDisabled);
|
---|
| 586 | };
|
---|
| 587 |
|
---|
| 588 | var optionsTrigger = optionsMenuDom.querySelector('.jasmine-trigger'),
|
---|
| 589 | optionsPayload = optionsMenuDom.querySelector('.jasmine-payload'),
|
---|
| 590 | isOpen = /\bjasmine-open\b/;
|
---|
| 591 |
|
---|
| 592 | optionsTrigger.onclick = function () {
|
---|
| 593 | if (isOpen.test(optionsPayload.className)) {
|
---|
| 594 | optionsPayload.className = optionsPayload.className.replace(
|
---|
| 595 | isOpen,
|
---|
| 596 | ''
|
---|
| 597 | );
|
---|
| 598 | } else {
|
---|
| 599 | optionsPayload.className += ' jasmine-open';
|
---|
| 600 | }
|
---|
| 601 | };
|
---|
| 602 |
|
---|
| 603 | return optionsMenuDom;
|
---|
| 604 | }
|
---|
| 605 |
|
---|
| 606 | function failureDescription(result, suite) {
|
---|
| 607 | var wrapper = createDom(
|
---|
| 608 | 'div',
|
---|
| 609 | { className: 'jasmine-description' },
|
---|
| 610 | createDom(
|
---|
| 611 | 'a',
|
---|
| 612 | { title: result.description, href: specHref(result) },
|
---|
| 613 | result.description
|
---|
| 614 | )
|
---|
| 615 | );
|
---|
| 616 | var suiteLink;
|
---|
| 617 |
|
---|
| 618 | while (suite && suite.parent) {
|
---|
| 619 | wrapper.insertBefore(createTextNode(' > '), wrapper.firstChild);
|
---|
| 620 | suiteLink = createDom(
|
---|
| 621 | 'a',
|
---|
| 622 | { href: suiteHref(suite) },
|
---|
| 623 | suite.result.description
|
---|
| 624 | );
|
---|
| 625 | wrapper.insertBefore(suiteLink, wrapper.firstChild);
|
---|
| 626 |
|
---|
| 627 | suite = suite.parent;
|
---|
| 628 | }
|
---|
| 629 |
|
---|
| 630 | return wrapper;
|
---|
| 631 | }
|
---|
| 632 |
|
---|
| 633 | function suiteHref(suite) {
|
---|
| 634 | var els = [];
|
---|
| 635 |
|
---|
| 636 | while (suite && suite.parent) {
|
---|
| 637 | els.unshift(suite.result.description);
|
---|
| 638 | suite = suite.parent;
|
---|
| 639 | }
|
---|
| 640 |
|
---|
| 641 | // include window.location.pathname to fix issue with karma-jasmine-html-reporter in angular: see https://github.com/jasmine/jasmine/issues/1906
|
---|
| 642 | return (
|
---|
| 643 | (window.location.pathname || '') +
|
---|
| 644 | addToExistingQueryString('spec', els.join(' '))
|
---|
| 645 | );
|
---|
| 646 | }
|
---|
| 647 |
|
---|
| 648 | function addDeprecationWarnings(result, runnableType) {
|
---|
| 649 | if (result && result.deprecationWarnings) {
|
---|
| 650 | for (var i = 0; i < result.deprecationWarnings.length; i++) {
|
---|
| 651 | var warning = result.deprecationWarnings[i].message;
|
---|
| 652 | if (!j$.util.arrayContains(warning)) {
|
---|
| 653 | deprecationWarnings.push({
|
---|
| 654 | message: warning,
|
---|
| 655 | runnableName: result.fullName,
|
---|
| 656 | runnableType: runnableType
|
---|
| 657 | });
|
---|
| 658 | }
|
---|
| 659 | }
|
---|
| 660 | }
|
---|
| 661 | }
|
---|
| 662 |
|
---|
| 663 | function find(selector) {
|
---|
| 664 | return getContainer().querySelector('.jasmine_html-reporter ' + selector);
|
---|
| 665 | }
|
---|
| 666 |
|
---|
| 667 | function clearPrior() {
|
---|
| 668 | // return the reporter
|
---|
| 669 | var oldReporter = find('');
|
---|
| 670 |
|
---|
| 671 | if (oldReporter) {
|
---|
| 672 | getContainer().removeChild(oldReporter);
|
---|
| 673 | }
|
---|
| 674 | }
|
---|
| 675 |
|
---|
| 676 | function createDom(type, attrs, childrenVarArgs) {
|
---|
| 677 | var el = createElement(type);
|
---|
| 678 |
|
---|
| 679 | for (var i = 2; i < arguments.length; i++) {
|
---|
| 680 | var child = arguments[i];
|
---|
| 681 |
|
---|
| 682 | if (typeof child === 'string') {
|
---|
| 683 | el.appendChild(createTextNode(child));
|
---|
| 684 | } else {
|
---|
| 685 | if (child) {
|
---|
| 686 | el.appendChild(child);
|
---|
| 687 | }
|
---|
| 688 | }
|
---|
| 689 | }
|
---|
| 690 |
|
---|
| 691 | for (var attr in attrs) {
|
---|
| 692 | if (attr == 'className') {
|
---|
| 693 | el[attr] = attrs[attr];
|
---|
| 694 | } else {
|
---|
| 695 | el.setAttribute(attr, attrs[attr]);
|
---|
| 696 | }
|
---|
| 697 | }
|
---|
| 698 |
|
---|
| 699 | return el;
|
---|
| 700 | }
|
---|
| 701 |
|
---|
| 702 | function pluralize(singular, count) {
|
---|
| 703 | var word = count == 1 ? singular : singular + 's';
|
---|
| 704 |
|
---|
| 705 | return '' + count + ' ' + word;
|
---|
| 706 | }
|
---|
| 707 |
|
---|
| 708 | function specHref(result) {
|
---|
| 709 | // include window.location.pathname to fix issue with karma-jasmine-html-reporter in angular: see https://github.com/jasmine/jasmine/issues/1906
|
---|
| 710 | return (
|
---|
| 711 | (window.location.pathname || '') +
|
---|
| 712 | addToExistingQueryString('spec', result.fullName)
|
---|
| 713 | );
|
---|
| 714 | }
|
---|
| 715 |
|
---|
| 716 | function seedHref(seed) {
|
---|
| 717 | // include window.location.pathname to fix issue with karma-jasmine-html-reporter in angular: see https://github.com/jasmine/jasmine/issues/1906
|
---|
| 718 | return (
|
---|
| 719 | (window.location.pathname || '') +
|
---|
| 720 | addToExistingQueryString('seed', seed)
|
---|
| 721 | );
|
---|
| 722 | }
|
---|
| 723 |
|
---|
| 724 | function defaultQueryString(key, value) {
|
---|
| 725 | return '?' + key + '=' + value;
|
---|
| 726 | }
|
---|
| 727 |
|
---|
| 728 | function setMenuModeTo(mode) {
|
---|
| 729 | htmlReporterMain.setAttribute('class', 'jasmine_html-reporter ' + mode);
|
---|
| 730 | }
|
---|
| 731 |
|
---|
| 732 | function noExpectations(result) {
|
---|
| 733 | var allExpectations =
|
---|
| 734 | result.failedExpectations.length + result.passedExpectations.length;
|
---|
| 735 |
|
---|
| 736 | return (
|
---|
| 737 | allExpectations === 0 &&
|
---|
| 738 | (result.status === 'passed' || result.status === 'failed')
|
---|
| 739 | );
|
---|
| 740 | }
|
---|
| 741 |
|
---|
| 742 | function hasActiveSpec(resultNode) {
|
---|
| 743 | if (resultNode.type == 'spec' && resultNode.result.status != 'excluded') {
|
---|
| 744 | return true;
|
---|
| 745 | }
|
---|
| 746 |
|
---|
| 747 | if (resultNode.type == 'suite') {
|
---|
| 748 | for (var i = 0, j = resultNode.children.length; i < j; i++) {
|
---|
| 749 | if (hasActiveSpec(resultNode.children[i])) {
|
---|
| 750 | return true;
|
---|
| 751 | }
|
---|
| 752 | }
|
---|
| 753 | }
|
---|
| 754 | }
|
---|
| 755 | }
|
---|
| 756 |
|
---|
| 757 | return HtmlReporter;
|
---|
| 758 | };
|
---|
| 759 |
|
---|
| 760 | jasmineRequire.HtmlSpecFilter = function () {
|
---|
| 761 | function HtmlSpecFilter(options) {
|
---|
| 762 | var filterString =
|
---|
| 763 | options &&
|
---|
| 764 | options.filterString() &&
|
---|
| 765 | options.filterString().replace(/[-[\]{}()*+?.,\\^$|#\s]/g, '\\$&');
|
---|
| 766 | var filterPattern = new RegExp(filterString);
|
---|
| 767 |
|
---|
| 768 | this.matches = function (specName) {
|
---|
| 769 | return filterPattern.test(specName);
|
---|
| 770 | };
|
---|
| 771 | }
|
---|
| 772 |
|
---|
| 773 | return HtmlSpecFilter;
|
---|
| 774 | };
|
---|
| 775 |
|
---|
| 776 | jasmineRequire.ResultsNode = function () {
|
---|
| 777 | function ResultsNode(result, type, parent) {
|
---|
| 778 | this.result = result;
|
---|
| 779 | this.type = type;
|
---|
| 780 | this.parent = parent;
|
---|
| 781 |
|
---|
| 782 | this.children = [];
|
---|
| 783 |
|
---|
| 784 | this.addChild = function (result, type) {
|
---|
| 785 | this.children.push(new ResultsNode(result, type, this));
|
---|
| 786 | };
|
---|
| 787 |
|
---|
| 788 | this.last = function () {
|
---|
| 789 | return this.children[this.children.length - 1];
|
---|
| 790 | };
|
---|
| 791 |
|
---|
| 792 | this.updateResult = function (result) {
|
---|
| 793 | this.result = result;
|
---|
| 794 | };
|
---|
| 795 | }
|
---|
| 796 |
|
---|
| 797 | return ResultsNode;
|
---|
| 798 | };
|
---|
| 799 |
|
---|
| 800 | jasmineRequire.QueryString = function () {
|
---|
| 801 | function QueryString(options) {
|
---|
| 802 | this.navigateWithNewParam = function (key, value) {
|
---|
| 803 | options.getWindowLocation().search = this.fullStringWithNewParam(
|
---|
| 804 | key,
|
---|
| 805 | value
|
---|
| 806 | );
|
---|
| 807 | };
|
---|
| 808 |
|
---|
| 809 | this.fullStringWithNewParam = function (key, value) {
|
---|
| 810 | var paramMap = queryStringToParamMap();
|
---|
| 811 | paramMap[key] = value;
|
---|
| 812 | return toQueryString(paramMap);
|
---|
| 813 | };
|
---|
| 814 |
|
---|
| 815 | this.getParam = function (key) {
|
---|
| 816 | return queryStringToParamMap()[key];
|
---|
| 817 | };
|
---|
| 818 |
|
---|
| 819 | return this;
|
---|
| 820 |
|
---|
| 821 | function toQueryString(paramMap) {
|
---|
| 822 | var qStrPairs = [];
|
---|
| 823 | for (var prop in paramMap) {
|
---|
| 824 | qStrPairs.push(
|
---|
| 825 | encodeURIComponent(prop) + '=' + encodeURIComponent(paramMap[prop])
|
---|
| 826 | );
|
---|
| 827 | }
|
---|
| 828 | return '?' + qStrPairs.join('&');
|
---|
| 829 | }
|
---|
| 830 |
|
---|
| 831 | function queryStringToParamMap() {
|
---|
| 832 | var paramStr = options.getWindowLocation().search.substring(1),
|
---|
| 833 | params = [],
|
---|
| 834 | paramMap = {};
|
---|
| 835 |
|
---|
| 836 | if (paramStr.length > 0) {
|
---|
| 837 | params = paramStr.split('&');
|
---|
| 838 | for (var i = 0; i < params.length; i++) {
|
---|
| 839 | var p = params[i].split('=');
|
---|
| 840 | var value = decodeURIComponent(p[1]);
|
---|
| 841 | if (value === 'true' || value === 'false') {
|
---|
| 842 | value = JSON.parse(value);
|
---|
| 843 | }
|
---|
| 844 | paramMap[decodeURIComponent(p[0])] = value;
|
---|
| 845 | }
|
---|
| 846 | }
|
---|
| 847 |
|
---|
| 848 | return paramMap;
|
---|
| 849 | }
|
---|
| 850 | }
|
---|
| 851 |
|
---|
| 852 | return QueryString;
|
---|
| 853 | };
|
---|