jasmine-boot.js 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. /* Copyright 2017 Mozilla Foundation
  2. *
  3. * Licensed under the Apache License, Version 2.0 (the "License");
  4. * you may not use this file except in compliance with the License.
  5. * You may obtain a copy of the License at
  6. *
  7. * http://www.apache.org/licenses/LICENSE-2.0
  8. *
  9. * Unless required by applicable law or agreed to in writing, software
  10. * distributed under the License is distributed on an "AS IS" BASIS,
  11. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. * See the License for the specific language governing permissions and
  13. * limitations under the License.
  14. */
  15. 'use strict';
  16. function initializePDFJS(callback) {
  17. Promise.all(['pdfjs/display/global', 'pdfjs-test/unit/annotation_spec', 'pdfjs-test/unit/api_spec', 'pdfjs-test/unit/bidi_spec', 'pdfjs-test/unit/cff_parser_spec', 'pdfjs-test/unit/cmap_spec', 'pdfjs-test/unit/crypto_spec', 'pdfjs-test/unit/document_spec', 'pdfjs-test/unit/dom_utils_spec', 'pdfjs-test/unit/evaluator_spec', 'pdfjs-test/unit/fonts_spec', 'pdfjs-test/unit/function_spec', 'pdfjs-test/unit/metadata_spec', 'pdfjs-test/unit/murmurhash3_spec', 'pdfjs-test/unit/network_spec', 'pdfjs-test/unit/parser_spec', 'pdfjs-test/unit/primitives_spec', 'pdfjs-test/unit/stream_spec', 'pdfjs-test/unit/type1_parser_spec', 'pdfjs-test/unit/ui_utils_spec', 'pdfjs-test/unit/unicode_spec', 'pdfjs-test/unit/util_spec'].map(function (moduleName) {
  18. return SystemJS.import(moduleName);
  19. })).then(function (modules) {
  20. var displayGlobal = modules[0];
  21. displayGlobal.PDFJS.workerSrc = '../../src/worker_loader.js';
  22. displayGlobal.PDFJS.pdfjsNext = true;
  23. callback();
  24. });
  25. }
  26. (function () {
  27. window.jasmine = jasmineRequire.core(jasmineRequire);
  28. jasmineRequire.html(jasmine);
  29. var env = jasmine.getEnv();
  30. var jasmineInterface = jasmineRequire.interface(jasmine, env);
  31. extend(window, jasmineInterface);
  32. var queryString = new jasmine.QueryString({
  33. getWindowLocation: function getWindowLocation() {
  34. return window.location;
  35. }
  36. });
  37. var catchingExceptions = queryString.getParam('catch');
  38. env.catchExceptions(typeof catchingExceptions === 'undefined' ? true : catchingExceptions);
  39. var throwingExpectationFailures = queryString.getParam('throwFailures');
  40. env.throwOnExpectationFailure(throwingExpectationFailures);
  41. var random = queryString.getParam('random');
  42. env.randomizeTests(random);
  43. var seed = queryString.getParam('seed');
  44. if (seed) {
  45. env.seed(seed);
  46. }
  47. var htmlReporter = new jasmine.HtmlReporter({
  48. env: env,
  49. onRaiseExceptionsClick: function onRaiseExceptionsClick() {
  50. queryString.navigateWithNewParam('catch', !env.catchingExceptions());
  51. },
  52. onThrowExpectationsClick: function onThrowExpectationsClick() {
  53. queryString.navigateWithNewParam('throwFailures', !env.throwingExpectationFailures());
  54. },
  55. onRandomClick: function onRandomClick() {
  56. queryString.navigateWithNewParam('random', !env.randomTests());
  57. },
  58. addToExistingQueryString: function addToExistingQueryString(key, value) {
  59. return queryString.fullStringWithNewParam(key, value);
  60. },
  61. getContainer: function getContainer() {
  62. return document.body;
  63. },
  64. createElement: function createElement() {
  65. return document.createElement.apply(document, arguments);
  66. },
  67. createTextNode: function createTextNode() {
  68. return document.createTextNode.apply(document, arguments);
  69. },
  70. timer: new jasmine.Timer()
  71. });
  72. env.addReporter(htmlReporter);
  73. if (queryString.getParam('browser')) {
  74. var testReporter = new TestReporter(queryString.getParam('browser'), queryString.getParam('path'));
  75. env.addReporter(testReporter);
  76. }
  77. var specFilter = new jasmine.HtmlSpecFilter({
  78. filterString: function filterString() {
  79. return queryString.getParam('spec');
  80. }
  81. });
  82. env.specFilter = function (spec) {
  83. return specFilter.matches(spec.getFullName());
  84. };
  85. jasmine.DEFAULT_TIMEOUT_INTERVAL = 30000;
  86. var currentWindowOnload = window.onload;
  87. window.onload = function () {
  88. if (currentWindowOnload) {
  89. currentWindowOnload();
  90. }
  91. initializePDFJS(function () {
  92. htmlReporter.initialize();
  93. env.execute();
  94. });
  95. };
  96. function extend(destination, source) {
  97. for (var property in source) {
  98. destination[property] = source[property];
  99. }
  100. return destination;
  101. }
  102. })();