Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Re-factor the setPDFNetworkStreamFactory usage for the unit-tests (PR 13549 follow-up) #13944

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 7 additions & 13 deletions test/unit/jasmine-boot.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@

import { GlobalWorkerOptions } from "pdfjs/display/worker_options.js";
import { isNodeJS } from "pdfjs/shared/is_node.js";
import { isValidFetchUrl } from "pdfjs/display/display_utils.js";
import { PDFFetchStream } from "pdfjs/display/fetch_stream.js";
import { PDFNetworkStream } from "pdfjs/display/network.js";
import { setPDFNetworkStreamFactory } from "pdfjs/display/api.js";
Expand Down Expand Up @@ -102,20 +103,13 @@ async function initializePDFJS(callback) {
"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) {
// Set the network stream factory for the unit-tests.
setPDFNetworkStreamFactory(params => {
if (isValidFetchUrl(params.url)) {
return new PDFFetchStream(params);
});
} else {
setPDFNetworkStreamFactory(function (params) {
return new PDFNetworkStream(params);
});
}
}
return new PDFNetworkStream(params);
});

// Configure the worker.
GlobalWorkerOptions.workerSrc = "../../build/generic/build/pdf.worker.js";
Expand Down