mirror of
https://github.com/mozilla/pdf.js.git
synced 2025-04-21 23:58:07 +02:00
Load all unit-tests with native import
, rather than SystemJS
This commit is contained in:
parent
d9084c0be2
commit
1c4495843c
3 changed files with 72 additions and 55 deletions
|
@ -14,7 +14,6 @@
|
|||
*/
|
||||
/* globals __non_webpack_require__ */
|
||||
|
||||
import { setStubs, unsetStubs } from "../../examples/node/domstubs.js";
|
||||
import { buildGetDocumentParams } from "./test_utils.js";
|
||||
import { getDocument } from "../../src/display/api.js";
|
||||
import { isNodeJS } from "../../src/shared/is_node.js";
|
||||
|
@ -95,6 +94,9 @@ describe("SVGGraphics", function () {
|
|||
// This points to the XObject image in xobject-image.pdf.
|
||||
const xobjectObjId = "img_p0_1";
|
||||
if (isNodeJS) {
|
||||
const { setStubs } = __non_webpack_require__(
|
||||
"../../examples/node/domstubs.js"
|
||||
);
|
||||
setStubs(global);
|
||||
}
|
||||
try {
|
||||
|
@ -102,6 +104,9 @@ describe("SVGGraphics", function () {
|
|||
svgGfx.paintInlineImageXObject(imgData, elementContainer);
|
||||
} finally {
|
||||
if (isNodeJS) {
|
||||
const { unsetStubs } = __non_webpack_require__(
|
||||
"../../examples/node/domstubs.js"
|
||||
);
|
||||
unsetStubs(global);
|
||||
}
|
||||
}
|
||||
|
@ -113,10 +118,10 @@ describe("SVGGraphics", function () {
|
|||
function testFunc() {
|
||||
__non_webpack_require__("zlib");
|
||||
}
|
||||
// Verifies that the script loader replaces __non_webpack_require__ with
|
||||
// require.
|
||||
expect(testFunc.toString()).toMatch(/\srequire\(["']zlib["']\)/);
|
||||
if (isNodeJS) {
|
||||
// Verifies that the script loader replaces __non_webpack_require__ with
|
||||
// require.
|
||||
expect(testFunc.toString()).toMatch(/\srequire\(["']zlib["']\)/);
|
||||
expect(testFunc).not.toThrow();
|
||||
} else {
|
||||
// require not defined, require('zlib') not a module, etc.
|
||||
|
|
|
@ -40,8 +40,8 @@
|
|||
|
||||
"use strict";
|
||||
|
||||
function initializePDFJS(callback) {
|
||||
Promise.all(
|
||||
async function initializePDFJS(callback) {
|
||||
const modules = await Promise.all(
|
||||
[
|
||||
"pdfjs/display/api.js",
|
||||
"pdfjs/display/worker_options.js",
|
||||
|
@ -83,40 +83,42 @@ function initializePDFJS(callback) {
|
|||
"pdfjs-test/unit/writer_spec.js",
|
||||
"pdfjs-test/unit/xml_spec.js",
|
||||
].map(function (moduleName) {
|
||||
return SystemJS.import(moduleName);
|
||||
// eslint-disable-next-line no-unsanitized/method
|
||||
return import(moduleName);
|
||||
})
|
||||
).then(function (modules) {
|
||||
const displayApi = modules[0];
|
||||
const { GlobalWorkerOptions } = modules[1];
|
||||
const { PDFNetworkStream } = modules[2];
|
||||
const { PDFFetchStream } = modules[3];
|
||||
const { isNodeJS } = modules[4];
|
||||
);
|
||||
const [
|
||||
{ setPDFNetworkStreamFactory },
|
||||
{ GlobalWorkerOptions },
|
||||
{ PDFNetworkStream },
|
||||
{ PDFFetchStream },
|
||||
{ isNodeJS },
|
||||
] = modules;
|
||||
|
||||
if (isNodeJS) {
|
||||
throw new Error(
|
||||
"The `gulp unittest` command cannot be used in Node.js environments."
|
||||
);
|
||||
}
|
||||
// Set the network stream factory for unit-tests.
|
||||
if (
|
||||
typeof Response !== "undefined" &&
|
||||
"body" in Response.prototype &&
|
||||
typeof ReadableStream !== "undefined"
|
||||
) {
|
||||
displayApi.setPDFNetworkStreamFactory(function (params) {
|
||||
return new PDFFetchStream(params);
|
||||
});
|
||||
} else {
|
||||
displayApi.setPDFNetworkStreamFactory(function (params) {
|
||||
return new PDFNetworkStream(params);
|
||||
});
|
||||
}
|
||||
if (isNodeJS) {
|
||||
throw new Error(
|
||||
"The `gulp unittest` command cannot be used in Node.js environments."
|
||||
);
|
||||
}
|
||||
// Set the network stream factory for unit-tests.
|
||||
if (
|
||||
typeof Response !== "undefined" &&
|
||||
"body" in Response.prototype &&
|
||||
typeof ReadableStream !== "undefined"
|
||||
) {
|
||||
setPDFNetworkStreamFactory(function (params) {
|
||||
return new PDFFetchStream(params);
|
||||
});
|
||||
} else {
|
||||
setPDFNetworkStreamFactory(function (params) {
|
||||
return new PDFNetworkStream(params);
|
||||
});
|
||||
}
|
||||
|
||||
// Configure the worker.
|
||||
GlobalWorkerOptions.workerSrc = "../../build/generic/build/pdf.worker.js";
|
||||
// Configure the worker.
|
||||
GlobalWorkerOptions.workerSrc = "../../build/generic/build/pdf.worker.js";
|
||||
|
||||
callback();
|
||||
});
|
||||
callback();
|
||||
}
|
||||
|
||||
(function () {
|
||||
|
@ -197,26 +199,26 @@ function initializePDFJS(callback) {
|
|||
// Sets longer timeout.
|
||||
jasmine.DEFAULT_TIMEOUT_INTERVAL = 30000;
|
||||
|
||||
// Replace the browser window's `onload`, ensure it's called, and then run
|
||||
// all of the loaded specs. This includes initializing the `HtmlReporter`
|
||||
// instance and then executing the loaded Jasmine environment.
|
||||
const currentWindowOnload = window.onload;
|
||||
|
||||
window.onload = function () {
|
||||
if (currentWindowOnload) {
|
||||
currentWindowOnload();
|
||||
}
|
||||
|
||||
initializePDFJS(function () {
|
||||
htmlReporter.initialize();
|
||||
env.execute();
|
||||
});
|
||||
};
|
||||
|
||||
function extend(destination, source) {
|
||||
for (const property in source) {
|
||||
destination[property] = source[property];
|
||||
}
|
||||
return destination;
|
||||
}
|
||||
|
||||
function unitTestInit() {
|
||||
initializePDFJS(function () {
|
||||
htmlReporter.initialize();
|
||||
env.execute();
|
||||
});
|
||||
}
|
||||
|
||||
if (
|
||||
document.readyState === "interactive" ||
|
||||
document.readyState === "complete"
|
||||
) {
|
||||
unitTestInit();
|
||||
} else {
|
||||
document.addEventListener("DOMContentLoaded", unitTestInit, true);
|
||||
}
|
||||
})();
|
||||
|
|
|
@ -5,12 +5,22 @@
|
|||
|
||||
<link rel="stylesheet" type="text/css" href="../../node_modules/jasmine-core/lib/jasmine-core/jasmine.css">
|
||||
|
||||
<script src="../../node_modules/systemjs/dist/system.js"></script>
|
||||
<script src="../../systemjs.config.js"></script>
|
||||
<script src="../../node_modules/jasmine-core/lib/jasmine-core/jasmine.js"></script>
|
||||
<script src="../../node_modules/jasmine-core/lib/jasmine-core/jasmine-html.js"></script>
|
||||
<script src="testreporter.js"></script>
|
||||
<script src="jasmine-boot.js"></script>
|
||||
|
||||
<script defer src="../../node_modules/es-module-shims/dist/es-module-shims.js"></script>
|
||||
<script type="importmap-shim">
|
||||
{
|
||||
"imports": {
|
||||
"pdfjs/": "../../src/",
|
||||
"pdfjs-lib": "../../src/pdf.js",
|
||||
"pdfjs-web/": "../../web/",
|
||||
"pdfjs-test/": "../"
|
||||
}
|
||||
}
|
||||
</script>
|
||||
<script src="jasmine-boot.js" type="module-shim"></script>
|
||||
</head>
|
||||
<body>
|
||||
</body>
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue