From fc9d9e49deca8f22b478bc71bc6f22b943bf3efb Mon Sep 17 00:00:00 2001 From: Jonas Jenwald Date: Sun, 26 Apr 2026 13:32:18 +0200 Subject: [PATCH] Improve unit-testing for the `PDFDocumentProxy.prototype.getPageIndex` method Given the existing worker-thread caching it doesn't seem, based on the coverage report, that all of the `getPageIndex` code is being tested. --- test/unit/api_spec.js | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/test/unit/api_spec.js b/test/unit/api_spec.js index 0e1f49f88..b0c4cd95b 100644 --- a/test/unit/api_spec.js +++ b/test/unit/api_spec.js @@ -1258,6 +1258,22 @@ describe("api", function () { expect(pageIndex).toEqual(1); }); + it("gets page index, for a non-cached page", async function () { + const loadingTask = getDocument( + buildGetDocumentParams("pdf.pdf", { + disableAutoFetch: true, + disableStream: true, + }) + ); + const pdfDoc = await loadingTask.promise; + + const ref = { num: 1427, gen: 0 }; // Reference to 500th page. + const pageIndex = await pdfDoc.getPageIndex(ref); + expect(pageIndex).toEqual(499); + + await pdfDoc.destroy(); + }); + it("gets invalid page index", async function () { const pageRefs = [ /* fontRef = */ { num: 3, gen: 0 },