2
0

jasmine-boot.js 5.5 KB

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