jasmine-boot.js 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  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/display/api', 'pdfjs/display/network', '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/colorspace_spec', 'pdfjs-test/unit/crypto_spec', 'pdfjs-test/unit/custom_spec', 'pdfjs-test/unit/display_svg_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', 'pdfjs-test/unit/util_stream_spec'].map(function (moduleName) {
  18. return SystemJS.import(moduleName);
  19. })).then(function (modules) {
  20. var displayGlobal = modules[0];
  21. var displayApi = modules[1];
  22. var PDFNetworkStream = modules[2].PDFNetworkStream;
  23. displayApi.setPDFNetworkStreamClass(PDFNetworkStream);
  24. displayGlobal.PDFJS.workerSrc = '../../build/generic/build/pdf.worker.js';
  25. displayGlobal.PDFJS.pdfjsNext = true;
  26. callback();
  27. });
  28. }
  29. (function () {
  30. window.jasmine = jasmineRequire.core(jasmineRequire);
  31. jasmineRequire.html(jasmine);
  32. var env = jasmine.getEnv();
  33. var jasmineInterface = jasmineRequire.interface(jasmine, env);
  34. extend(window, jasmineInterface);
  35. var queryString = new jasmine.QueryString({
  36. getWindowLocation: function getWindowLocation() {
  37. return window.location;
  38. }
  39. });
  40. var catchingExceptions = queryString.getParam('catch');
  41. env.catchExceptions(typeof catchingExceptions === 'undefined' ? true : catchingExceptions);
  42. var throwingExpectationFailures = queryString.getParam('throwFailures');
  43. env.throwOnExpectationFailure(throwingExpectationFailures);
  44. var random = queryString.getParam('random');
  45. env.randomizeTests(random);
  46. var seed = queryString.getParam('seed');
  47. if (seed) {
  48. env.seed(seed);
  49. }
  50. var htmlReporter = new jasmine.HtmlReporter({
  51. env: env,
  52. onRaiseExceptionsClick: function onRaiseExceptionsClick() {
  53. queryString.navigateWithNewParam('catch', !env.catchingExceptions());
  54. },
  55. onThrowExpectationsClick: function onThrowExpectationsClick() {
  56. queryString.navigateWithNewParam('throwFailures', !env.throwingExpectationFailures());
  57. },
  58. onRandomClick: function onRandomClick() {
  59. queryString.navigateWithNewParam('random', !env.randomTests());
  60. },
  61. addToExistingQueryString: function addToExistingQueryString(key, value) {
  62. return queryString.fullStringWithNewParam(key, value);
  63. },
  64. getContainer: function getContainer() {
  65. return document.body;
  66. },
  67. createElement: function createElement() {
  68. return document.createElement.apply(document, arguments);
  69. },
  70. createTextNode: function createTextNode() {
  71. return document.createTextNode.apply(document, arguments);
  72. },
  73. timer: new jasmine.Timer()
  74. });
  75. env.addReporter(htmlReporter);
  76. if (queryString.getParam('browser')) {
  77. var testReporter = new TestReporter(queryString.getParam('browser'), queryString.getParam('path'));
  78. env.addReporter(testReporter);
  79. }
  80. var specFilter = new jasmine.HtmlSpecFilter({
  81. filterString: function filterString() {
  82. return queryString.getParam('spec');
  83. }
  84. });
  85. env.specFilter = function (spec) {
  86. return specFilter.matches(spec.getFullName());
  87. };
  88. jasmine.DEFAULT_TIMEOUT_INTERVAL = 30000;
  89. var currentWindowOnload = window.onload;
  90. window.onload = function () {
  91. if (currentWindowOnload) {
  92. currentWindowOnload();
  93. }
  94. initializePDFJS(function () {
  95. htmlReporter.initialize();
  96. env.execute();
  97. });
  98. };
  99. function extend(destination, source) {
  100. for (var property in source) {
  101. destination[property] = source[property];
  102. }
  103. return destination;
  104. }
  105. })();