From e69afc6f3d453fb6b963c84633be15f5c15cdb6a Mon Sep 17 00:00:00 2001 From: Jonas Jenwald Date: Sun, 29 Aug 2021 18:27:53 +0200 Subject: [PATCH] Re-factor the `setPDFNetworkStreamFactory` usage for the unit-tests (PR 13549 follow-up) This should have been part of PR 13549, since we no longer support browsers without native Fetch API and ReadableStream implementations. --- test/unit/jasmine-boot.js | 20 +++++++------------- 1 file changed, 7 insertions(+), 13 deletions(-) diff --git a/test/unit/jasmine-boot.js b/test/unit/jasmine-boot.js index a3312ed2c9acb..5dcbd8992bc0a 100644 --- a/test/unit/jasmine-boot.js +++ b/test/unit/jasmine-boot.js @@ -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"; @@ -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";