jasmine-boot.js 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161
  1. /* Copyright 2016 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. /*
  16. Copyright (c) 2008-2016 Pivotal Labs
  17. Permission is hereby granted, free of charge, to any person obtaining
  18. a copy of this software and associated documentation files (the
  19. "Software"), to deal in the Software without restriction, including
  20. without limitation the rights to use, copy, modify, merge, publish,
  21. distribute, sublicense, and/or sell copies of the Software, and to
  22. permit persons to whom the Software is furnished to do so, subject to
  23. the following conditions:
  24. The above copyright notice and this permission notice shall be
  25. included in all copies or substantial portions of the Software.
  26. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  27. EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  28. MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  29. NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
  30. LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
  31. OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
  32. WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  33. */
  34. /* globals jasmineRequire */
  35. // Modified jasmine's boot.js file to load PDF.js libraries async.
  36. "use strict";
  37. import { TestReporter } from "../unit/testreporter.js";
  38. async function initializePDFJS(callback) {
  39. await Promise.all(
  40. [
  41. "pdfjs-test/font/font_core_spec.js",
  42. "pdfjs-test/font/font_os2_spec.js",
  43. "pdfjs-test/font/font_post_spec.js",
  44. "pdfjs-test/font/font_fpgm_spec.js",
  45. ].map(function (moduleName) {
  46. // eslint-disable-next-line no-unsanitized/method
  47. return import(moduleName);
  48. })
  49. );
  50. callback();
  51. }
  52. (function () {
  53. window.jasmine = jasmineRequire.core(jasmineRequire);
  54. jasmineRequire.html(jasmine);
  55. const env = jasmine.getEnv();
  56. const jasmineInterface = jasmineRequire.interface(jasmine, env);
  57. extend(window, jasmineInterface);
  58. // Runner Parameters
  59. const queryString = new jasmine.QueryString({
  60. getWindowLocation() {
  61. return window.location;
  62. },
  63. });
  64. const config = {
  65. failFast: queryString.getParam("failFast"),
  66. oneFailurePerSpec: queryString.getParam("oneFailurePerSpec"),
  67. hideDisabled: queryString.getParam("hideDisabled"),
  68. };
  69. const random = queryString.getParam("random");
  70. if (random !== undefined && random !== "") {
  71. config.random = random;
  72. }
  73. const seed = queryString.getParam("seed");
  74. if (seed) {
  75. config.seed = seed;
  76. }
  77. // Reporters
  78. const htmlReporter = new jasmine.HtmlReporter({
  79. env,
  80. navigateWithNewParam(key, value) {
  81. return queryString.navigateWithNewParam(key, value);
  82. },
  83. addToExistingQueryString(key, value) {
  84. return queryString.fullStringWithNewParam(key, value);
  85. },
  86. getContainer() {
  87. return document.body;
  88. },
  89. createElement() {
  90. return document.createElement(...arguments);
  91. },
  92. createTextNode() {
  93. return document.createTextNode(...arguments);
  94. },
  95. timer: new jasmine.Timer(),
  96. });
  97. env.addReporter(htmlReporter);
  98. if (queryString.getParam("browser")) {
  99. const testReporter = new TestReporter(queryString.getParam("browser"));
  100. env.addReporter(testReporter);
  101. }
  102. // Filter which specs will be run by matching the start of the full name
  103. // against the `spec` query param.
  104. const 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. // Sets longer timeout.
  114. jasmine.DEFAULT_TIMEOUT_INTERVAL = 30000;
  115. function extend(destination, source) {
  116. for (const property in source) {
  117. destination[property] = source[property];
  118. }
  119. return destination;
  120. }
  121. function fontTestInit() {
  122. initializePDFJS(function () {
  123. htmlReporter.initialize();
  124. env.execute();
  125. });
  126. }
  127. if (
  128. document.readyState === "interactive" ||
  129. document.readyState === "complete"
  130. ) {
  131. fontTestInit();
  132. } else {
  133. document.addEventListener("DOMContentLoaded", fontTestInit, true);
  134. }
  135. })();