Skip to content

Make the tests check what they claim - #78

Merged
alekswebnet merged 1 commit into
chore/pdfjs-6.5.438from
fix/vacuous-tests
Nov 7, 2026
Merged

alekswebnet merged 1 commit into
chore/pdfjs-6.5.438from
fix/vacuous-tests

Conversation

@alekswebnet

Copy link
Copy Markdown
Collaborator

Summary

Fixes #76: several browser tests passed whether or not the feature worked. This PR is stacked on #77. Merge that one first, and this one retargets to master.

Rewritten tests:

  • should render the PDF file opened /sample-pdf-10MB.pdf, which exists nowhere, and asserted inside a pagesloaded handler it never awaited. It now opens a PDF the repository tracks and waits until a page is drawn.
  • should not render PDF with wrong url asserted "no pages" before the load could finish, so it also passed with a valid PDF. It now waits for documenterror, and fails if pages load instead.
  • should open the external file with base64 source called getFileData(), which fetched the base64 string as a relative URL and so returned the dev server's HTML page. PDF.js 6 also rejects a bare Uint8Array. The test now opens { data } and checks for the document's own text, "Hello, world!".
  • defaults to resources that ship next to the runtime files checked HEAD for a 200, which the dev server also returns for a missing file. It now checks that the response isn't the HTML page.

Also:

  • 14 tests set src to that missing PDF without needing a document. Removing it stops a failed load in each of them. It also stops the worker CSP test from downloading a worker from jsDelivr.
  • PdfViewerApplicationOpenParameters no longer includes Uint8Array. PDF.js rejects that at runtime with getDocument - expected either `data`, `range`, or `url` parameter. TypeScript code that passed raw bytes now gets a compile error instead of that runtime error. The docs already use open({ data }).

I reviewed every other test, and each one asserts something real. For example, "should hide the download button" fails without the injected style. Two tests still load an old viewer build from jsDelivr, so they depend on the network: "should load runtime files from assets-base" and "should prefer worker-src over assets-base…". I left those as they are.

Validation

  • pnpm test -- --run: 40 passed, both normally and with the public/ fixtures moved away, as CI sees the repository.
  • Each rewritten test fails when its feature is broken:
    • the render test, when pointed at a missing file;
    • the wrong-URL test, when given a valid PDF;
    • the base64 test, with the old getFileData();
    • the resources test, with a CMap file deleted.
  • pnpm exec tsc --noEmit and pnpm build pass, and types/pdfjs-viewer-element.d.ts is regenerated.

Checklist

  • The change is focused and includes tests for behavior changes.
  • Relevant tests and the build pass locally.
  • Public API, behavior, or user-guidance documentation is updated where needed. The type now matches the docs, which already use open({ data }).
  • Accessibility impact has been considered, including keyboard navigation and focus visibility. There are no UI changes.
  • This pull request does not disclose a security vulnerability.

🤖 Generated with Claude Code

Several tests passed whether or not the feature worked (#76):

- "should render the PDF file" opened a PDF that exists nowhere and
  asserted inside a handler it never awaited. It now opens a PDF in
  the repository and waits for a page to be drawn.
- "should not render PDF with wrong url" asserted before the load could
  finish. It now waits for the load to fail, and fails if pages load.
- "should open the external file with base64 source": getFileData()
  fetched the base64 string as a relative URL, and PDF.js 6 rejects a
  bare Uint8Array. It now opens { data } and checks the document's text.
- "defaults to resources that ship next to the runtime files" checked
  HEAD for a 200, which the dev server also returns for a missing file.
  It now checks the content type.
- 14 tests set src to a missing PDF they didn't need; that's removed.

PdfViewerApplicationOpenParameters no longer allows a bare Uint8Array,
which PDF.js rejects at runtime.

Closes #76

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@alekswebnet
alekswebnet merged commit aeb03de into chore/pdfjs-6.5.438 Nov 7, 2026
3 checks passed
alekswebnet added a commit that referenced this pull request Nov 7, 2026
Make the tests check what they claim (land #78 on master)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant