From a7d32f451876a3dd472825ffdeea63c35ff4721f Mon Sep 17 00:00:00 2001 From: Jonas Jenwald Date: Fri, 5 Jun 2026 23:11:52 +0200 Subject: [PATCH] Add a unit-test for passing a filesystem URL-string (in Node.js) to `getDocument` This improves coverage for a part of the API that previously wasn't tested. --- test/unit/api_spec.js | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/test/unit/api_spec.js b/test/unit/api_spec.js index c31bc5797..edf97fa39 100644 --- a/test/unit/api_spec.js +++ b/test/unit/api_spec.js @@ -228,6 +228,28 @@ describe("api", function () { await loadingTask.destroy(); }); + it("creates pdf doc from filesystem URL-string (in Node.js)", async function () { + if (!isNodeJS) { + pending("Testing Node.js functionality."); + } + const url = process.getBuiltinModule("url"); + const cwdURL = url.pathToFileURL(process.cwd()) + "/"; + const urlStr = new URL("./test/pdfs/basicapi.pdf", cwdURL).href; + + const loadingTask = getDocument({ url: urlStr }); + expect(loadingTask).toBeInstanceOf(PDFDocumentLoadingTask); + const pdfDocument = await loadingTask.promise; + + expect(typeof urlStr).toEqual("string"); + expect(pdfDocument).toBeInstanceOf(PDFDocumentProxy); + expect(pdfDocument.numPages).toEqual(3); + + // Ensure that Node.js streaming was used to load the PDF document. + expect(pdfDocument.getNetworkStreamName()).toEqual("PDFNodeStream"); + + await loadingTask.destroy(); + }); + it("creates pdf doc from URL and aborts before worker initialized", async function () { const loadingTask = getDocument(basicApiGetDocumentParams); expect(loadingTask).toBeInstanceOf(PDFDocumentLoadingTask);