jasmine-boot.js 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  1. /**
  2. * @licstart The following is the entire license notice for the
  3. * Javascript code in this page
  4. *
  5. * Copyright 2018 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', 'pdfjs/display/worker_options', 'pdfjs/display/network', 'pdfjs/display/fetch_stream', 'pdfjs/shared/is_node', '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/encodings_spec', 'pdfjs-test/unit/evaluator_spec', 'pdfjs-test/unit/function_spec', 'pdfjs-test/unit/message_handler_spec', 'pdfjs-test/unit/metadata_spec', 'pdfjs-test/unit/murmurhash3_spec', 'pdfjs-test/unit/network_spec', 'pdfjs-test/unit/network_utils_spec', 'pdfjs-test/unit/parser_spec', 'pdfjs-test/unit/pdf_find_controller_spec', 'pdfjs-test/unit/pdf_find_utils_spec', 'pdfjs-test/unit/pdf_history_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'].map(function (moduleName) {
  25. return SystemJS.import(moduleName);
  26. })).then(function (modules) {
  27. var displayApi = modules[0];
  28. var GlobalWorkerOptions = modules[1].GlobalWorkerOptions;
  29. var PDFNetworkStream = modules[2].PDFNetworkStream;
  30. var PDFFetchStream = modules[3].PDFFetchStream;
  31. var isNodeJS = modules[4];
  32. if (isNodeJS()) {
  33. throw new Error('The `gulp unittest` command cannot be used in ' + 'Node.js environments.');
  34. }
  35. if (typeof Response !== 'undefined' && 'body' in Response.prototype && typeof ReadableStream !== 'undefined') {
  36. displayApi.setPDFNetworkStreamFactory(function (params) {
  37. return new PDFFetchStream(params);
  38. });
  39. } else {
  40. displayApi.setPDFNetworkStreamFactory(function (params) {
  41. return new PDFNetworkStream(params);
  42. });
  43. }
  44. GlobalWorkerOptions.workerSrc = '../../build/generic/build/pdf.worker.js';
  45. callback();
  46. });
  47. }
  48. (function () {
  49. window.jasmine = jasmineRequire.core(jasmineRequire);
  50. jasmineRequire.html(jasmine);
  51. var env = jasmine.getEnv();
  52. var jasmineInterface = jasmineRequire.interface(jasmine, env);
  53. extend(window, jasmineInterface);
  54. var queryString = new jasmine.QueryString({
  55. getWindowLocation: function getWindowLocation() {
  56. return window.location;
  57. }
  58. });
  59. var config = {
  60. failFast: queryString.getParam('failFast'),
  61. oneFailurePerSpec: queryString.getParam('oneFailurePerSpec'),
  62. hideDisabled: queryString.getParam('hideDisabled')
  63. };
  64. var random = queryString.getParam('random');
  65. if (random !== undefined && random !== '') {
  66. config.random = random;
  67. }
  68. var seed = queryString.getParam('seed');
  69. if (seed) {
  70. config.seed = seed;
  71. }
  72. var htmlReporter = new jasmine.HtmlReporter({
  73. env: env,
  74. navigateWithNewParam: function navigateWithNewParam(key, value) {
  75. return queryString.navigateWithNewParam(key, value);
  76. },
  77. addToExistingQueryString: function addToExistingQueryString(key, value) {
  78. return queryString.fullStringWithNewParam(key, value);
  79. },
  80. getContainer: function getContainer() {
  81. return document.body;
  82. },
  83. createElement: function createElement() {
  84. return document.createElement.apply(document, arguments);
  85. },
  86. createTextNode: function 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. var testReporter = new TestReporter(queryString.getParam('browser'), queryString.getParam('path'));
  94. env.addReporter(testReporter);
  95. }
  96. var specFilter = new jasmine.HtmlSpecFilter({
  97. filterString: function 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. var currentWindowOnload = window.onload;
  107. window.onload = function () {
  108. if (currentWindowOnload) {
  109. currentWindowOnload();
  110. }
  111. initializePDFJS(function () {
  112. htmlReporter.initialize();
  113. env.execute();
  114. });
  115. };
  116. function extend(destination, source) {
  117. for (var property in source) {
  118. destination[property] = source[property];
  119. }
  120. return destination;
  121. }
  122. })();