jasmine-boot.js 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154
  1. /**
  2. * @licstart The following is the entire license notice for the
  3. * Javascript code in this page
  4. *
  5. * Copyright 2021 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. var _worker_options = require("pdfjs/display/worker_options.js");
  24. var _is_node = require("pdfjs/shared/is_node.js");
  25. var _fetch_stream = require("pdfjs/display/fetch_stream.js");
  26. var _network = require("pdfjs/display/network.js");
  27. var _api = require("pdfjs/display/api.js");
  28. var _testreporter = require("./testreporter.js");
  29. async function initializePDFJS(callback) {
  30. await Promise.all(["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/default_appearance_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/scripting_spec.js", "pdfjs-test/unit/stream_spec.js", "pdfjs-test/unit/struct_tree_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", "pdfjs-test/unit/xfa_formcalc_spec.js", "pdfjs-test/unit/xfa_parser_spec.js", "pdfjs-test/unit/xfa_serialize_data_spec.js", "pdfjs-test/unit/xfa_tohtml_spec.js", "pdfjs-test/unit/xml_spec.js"].map(function (moduleName) {
  31. return import(moduleName);
  32. }));
  33. if (_is_node.isNodeJS) {
  34. throw new Error("The `gulp unittest` command cannot be used in Node.js environments.");
  35. }
  36. if (typeof Response !== "undefined" && "body" in Response.prototype && typeof ReadableStream !== "undefined") {
  37. (0, _api.setPDFNetworkStreamFactory)(function (params) {
  38. return new _fetch_stream.PDFFetchStream(params);
  39. });
  40. } else {
  41. (0, _api.setPDFNetworkStreamFactory)(function (params) {
  42. return new _network.PDFNetworkStream(params);
  43. });
  44. }
  45. _worker_options.GlobalWorkerOptions.workerSrc = "../../build/generic/build/pdf.worker.js";
  46. callback();
  47. }
  48. (function () {
  49. window.jasmine = jasmineRequire.core(jasmineRequire);
  50. jasmineRequire.html(jasmine);
  51. const env = jasmine.getEnv();
  52. const jasmineInterface = jasmineRequire.interface(jasmine, env);
  53. extend(window, jasmineInterface);
  54. const queryString = new jasmine.QueryString({
  55. getWindowLocation() {
  56. return window.location;
  57. }
  58. });
  59. const config = {
  60. failFast: queryString.getParam("failFast"),
  61. oneFailurePerSpec: queryString.getParam("oneFailurePerSpec"),
  62. hideDisabled: queryString.getParam("hideDisabled")
  63. };
  64. const random = queryString.getParam("random");
  65. if (random !== undefined && random !== "") {
  66. config.random = random;
  67. }
  68. const seed = queryString.getParam("seed");
  69. if (seed) {
  70. config.seed = seed;
  71. }
  72. const htmlReporter = new jasmine.HtmlReporter({
  73. env,
  74. navigateWithNewParam(key, value) {
  75. return queryString.navigateWithNewParam(key, value);
  76. },
  77. addToExistingQueryString(key, value) {
  78. return queryString.fullStringWithNewParam(key, value);
  79. },
  80. getContainer() {
  81. return document.body;
  82. },
  83. createElement() {
  84. return document.createElement.apply(document, arguments);
  85. },
  86. createTextNode() {
  87. return document.createTextNode.apply(document, arguments);
  88. },
  89. timer: new jasmine.Timer()
  90. });
  91. env.addReporter(htmlReporter);
  92. if (queryString.getParam("browser")) {
  93. const testReporter = new _testreporter.TestReporter(queryString.getParam("browser"));
  94. env.addReporter(testReporter);
  95. }
  96. const specFilter = new jasmine.HtmlSpecFilter({
  97. filterString() {
  98. return queryString.getParam("spec");
  99. }
  100. });
  101. config.specFilter = function (spec) {
  102. return specFilter.matches(spec.getFullName());
  103. };
  104. env.configure(config);
  105. jasmine.DEFAULT_TIMEOUT_INTERVAL = 30000;
  106. function extend(destination, source) {
  107. for (const property in source) {
  108. destination[property] = source[property];
  109. }
  110. return destination;
  111. }
  112. function unitTestInit() {
  113. initializePDFJS(function () {
  114. htmlReporter.initialize();
  115. env.execute();
  116. });
  117. }
  118. if (document.readyState === "interactive" || document.readyState === "complete") {
  119. unitTestInit();
  120. } else {
  121. document.addEventListener("DOMContentLoaded", unitTestInit, true);
  122. }
  123. })();