jasmine-boot.js 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155
  1. /**
  2. * @licstart The following is the entire license notice for the
  3. * Javascript code in this page
  4. *
  5. * Copyright 2020 Mozilla Foundation
  6. *
  7. * Licensed under the Apache License, Version 2.0 (the "License");
  8. * you may not use this file except in compliance with the License.
  9. * You may obtain a copy of the License at
  10. *
  11. * http://www.apache.org/licenses/LICENSE-2.0
  12. *
  13. * Unless required by applicable law or agreed to in writing, software
  14. * distributed under the License is distributed on an "AS IS" BASIS,
  15. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  16. * See the License for the specific language governing permissions and
  17. * limitations under the License.
  18. *
  19. * @licend The above is the entire license notice for the
  20. * Javascript code in this page
  21. */
  22. "use strict";
  23. function initializePDFJS(callback) {
  24. Promise.all(["pdfjs/display/api.js", "pdfjs/display/worker_options.js", "pdfjs/display/network.js", "pdfjs/display/fetch_stream.js", "pdfjs/shared/is_node.js", "pdfjs-test/unit/annotation_spec.js", "pdfjs-test/unit/annotation_storage_spec.js", "pdfjs-test/unit/api_spec.js", "pdfjs-test/unit/bidi_spec.js", "pdfjs-test/unit/cff_parser_spec.js", "pdfjs-test/unit/cmap_spec.js", "pdfjs-test/unit/colorspace_spec.js", "pdfjs-test/unit/core_utils_spec.js", "pdfjs-test/unit/crypto_spec.js", "pdfjs-test/unit/custom_spec.js", "pdfjs-test/unit/display_svg_spec.js", "pdfjs-test/unit/display_utils_spec.js", "pdfjs-test/unit/document_spec.js", "pdfjs-test/unit/encodings_spec.js", "pdfjs-test/unit/evaluator_spec.js", "pdfjs-test/unit/function_spec.js", "pdfjs-test/unit/fetch_stream_spec.js", "pdfjs-test/unit/message_handler_spec.js", "pdfjs-test/unit/metadata_spec.js", "pdfjs-test/unit/murmurhash3_spec.js", "pdfjs-test/unit/network_spec.js", "pdfjs-test/unit/network_utils_spec.js", "pdfjs-test/unit/parser_spec.js", "pdfjs-test/unit/pdf_find_controller_spec.js", "pdfjs-test/unit/pdf_find_utils_spec.js", "pdfjs-test/unit/pdf_history_spec.js", "pdfjs-test/unit/primitives_spec.js", "pdfjs-test/unit/stream_spec.js", "pdfjs-test/unit/type1_parser_spec.js", "pdfjs-test/unit/ui_utils_spec.js", "pdfjs-test/unit/unicode_spec.js", "pdfjs-test/unit/util_spec.js", "pdfjs-test/unit/writer_spec.js"].map(function (moduleName) {
  25. return SystemJS.import(moduleName);
  26. })).then(function (modules) {
  27. const displayApi = modules[0];
  28. const {
  29. GlobalWorkerOptions
  30. } = modules[1];
  31. const {
  32. PDFNetworkStream
  33. } = modules[2];
  34. const {
  35. PDFFetchStream
  36. } = modules[3];
  37. const {
  38. isNodeJS
  39. } = modules[4];
  40. if (isNodeJS) {
  41. throw new Error("The `gulp unittest` command cannot be used in Node.js environments.");
  42. }
  43. if (typeof Response !== "undefined" && "body" in Response.prototype && typeof ReadableStream !== "undefined") {
  44. displayApi.setPDFNetworkStreamFactory(function (params) {
  45. return new PDFFetchStream(params);
  46. });
  47. } else {
  48. displayApi.setPDFNetworkStreamFactory(function (params) {
  49. return new PDFNetworkStream(params);
  50. });
  51. }
  52. GlobalWorkerOptions.workerSrc = "../../build/generic/build/pdf.worker.js";
  53. callback();
  54. });
  55. }
  56. (function () {
  57. window.jasmine = jasmineRequire.core(jasmineRequire);
  58. jasmineRequire.html(jasmine);
  59. var env = jasmine.getEnv();
  60. var jasmineInterface = jasmineRequire.interface(jasmine, env);
  61. extend(window, jasmineInterface);
  62. var queryString = new jasmine.QueryString({
  63. getWindowLocation() {
  64. return window.location;
  65. }
  66. });
  67. var config = {
  68. failFast: queryString.getParam("failFast"),
  69. oneFailurePerSpec: queryString.getParam("oneFailurePerSpec"),
  70. hideDisabled: queryString.getParam("hideDisabled")
  71. };
  72. var random = queryString.getParam("random");
  73. if (random !== undefined && random !== "") {
  74. config.random = random;
  75. }
  76. var seed = queryString.getParam("seed");
  77. if (seed) {
  78. config.seed = seed;
  79. }
  80. var htmlReporter = new jasmine.HtmlReporter({
  81. env,
  82. navigateWithNewParam(key, value) {
  83. return queryString.navigateWithNewParam(key, value);
  84. },
  85. addToExistingQueryString(key, value) {
  86. return queryString.fullStringWithNewParam(key, value);
  87. },
  88. getContainer() {
  89. return document.body;
  90. },
  91. createElement() {
  92. return document.createElement.apply(document, arguments);
  93. },
  94. createTextNode() {
  95. return document.createTextNode.apply(document, arguments);
  96. },
  97. timer: new jasmine.Timer()
  98. });
  99. env.addReporter(htmlReporter);
  100. if (queryString.getParam("browser")) {
  101. var testReporter = new TestReporter(queryString.getParam("browser"));
  102. env.addReporter(testReporter);
  103. }
  104. var specFilter = new jasmine.HtmlSpecFilter({
  105. filterString() {
  106. return queryString.getParam("spec");
  107. }
  108. });
  109. config.specFilter = function (spec) {
  110. return specFilter.matches(spec.getFullName());
  111. };
  112. env.configure(config);
  113. jasmine.DEFAULT_TIMEOUT_INTERVAL = 30000;
  114. var currentWindowOnload = window.onload;
  115. window.onload = function () {
  116. if (currentWindowOnload) {
  117. currentWindowOnload();
  118. }
  119. initializePDFJS(function () {
  120. htmlReporter.initialize();
  121. env.execute();
  122. });
  123. };
  124. function extend(destination, source) {
  125. for (var property in source) {
  126. destination[property] = source[property];
  127. }
  128. return destination;
  129. }
  130. })();