jasmine-boot.js 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  1. /**
  2. * @licstart The following is the entire license notice for the
  3. * Javascript code in this page
  4. *
  5. * Copyright 2017 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/global', 'pdfjs/display/api', '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/fonts_spec', 'pdfjs-test/unit/function_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_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', 'pdfjs-test/unit/util_stream_spec'].map(function (moduleName) {
  25. return SystemJS.import(moduleName);
  26. })).then(function (modules) {
  27. var displayGlobal = modules[0];
  28. var displayApi = modules[1];
  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. displayGlobal.PDFJS.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 catchingExceptions = queryString.getParam('catch');
  60. env.catchExceptions(typeof catchingExceptions === 'undefined' ? true : catchingExceptions);
  61. var throwingExpectationFailures = queryString.getParam('throwFailures');
  62. env.throwOnExpectationFailure(throwingExpectationFailures);
  63. var random = queryString.getParam('random');
  64. env.randomizeTests(random);
  65. var seed = queryString.getParam('seed');
  66. if (seed) {
  67. env.seed(seed);
  68. }
  69. var htmlReporter = new jasmine.HtmlReporter({
  70. env: env,
  71. onRaiseExceptionsClick: function onRaiseExceptionsClick() {
  72. queryString.navigateWithNewParam('catch', !env.catchingExceptions());
  73. },
  74. onThrowExpectationsClick: function onThrowExpectationsClick() {
  75. queryString.navigateWithNewParam('throwFailures', !env.throwingExpectationFailures());
  76. },
  77. onRandomClick: function onRandomClick() {
  78. queryString.navigateWithNewParam('random', !env.randomTests());
  79. },
  80. addToExistingQueryString: function addToExistingQueryString(key, value) {
  81. return queryString.fullStringWithNewParam(key, value);
  82. },
  83. getContainer: function getContainer() {
  84. return document.body;
  85. },
  86. createElement: function createElement() {
  87. return document.createElement.apply(document, arguments);
  88. },
  89. createTextNode: function createTextNode() {
  90. return document.createTextNode.apply(document, arguments);
  91. },
  92. timer: new jasmine.Timer()
  93. });
  94. env.addReporter(htmlReporter);
  95. if (queryString.getParam('browser')) {
  96. var testReporter = new TestReporter(queryString.getParam('browser'), queryString.getParam('path'));
  97. env.addReporter(testReporter);
  98. }
  99. var specFilter = new jasmine.HtmlSpecFilter({
  100. filterString: function filterString() {
  101. return queryString.getParam('spec');
  102. }
  103. });
  104. env.specFilter = function (spec) {
  105. return specFilter.matches(spec.getFullName());
  106. };
  107. jasmine.DEFAULT_TIMEOUT_INTERVAL = 30000;
  108. var currentWindowOnload = window.onload;
  109. window.onload = function () {
  110. if (currentWindowOnload) {
  111. currentWindowOnload();
  112. }
  113. initializePDFJS(function () {
  114. htmlReporter.initialize();
  115. env.execute();
  116. });
  117. };
  118. function extend(destination, source) {
  119. for (var property in source) {
  120. destination[property] = source[property];
  121. }
  122. return destination;
  123. }
  124. })();