From 2c9e690dfb2a5f6b070c1767fa1ea888ffe49685 Mon Sep 17 00:00:00 2001 From: shamoon <4887959+shamoon@users.noreply.github.com> Date: Mon, 12 May 2025 21:04:18 -0700 Subject: [PATCH] Chore: resolve dynamic import warnings from pdfjs, again (#9924) --- src-ui/__mocks__/pdfjs-dist.ts | 13 +++++++++++++ src-ui/setup-jest.ts | 17 +---------------- 2 files changed, 14 insertions(+), 16 deletions(-) create mode 100644 src-ui/__mocks__/pdfjs-dist.ts diff --git a/src-ui/__mocks__/pdfjs-dist.ts b/src-ui/__mocks__/pdfjs-dist.ts new file mode 100644 index 000000000..e975a40d4 --- /dev/null +++ b/src-ui/__mocks__/pdfjs-dist.ts @@ -0,0 +1,13 @@ +export const getDocument = jest.fn(() => ({ + promise: Promise.resolve({ numPages: 3 }), +})) + +export const GlobalWorkerOptions = { workerSrc: '' } +export const VerbosityLevel = { ERRORS: 0 } + +globalThis.pdfjsLib = { + getDocument, + GlobalWorkerOptions, + VerbosityLevel, + AbortException: class AbortException extends Error {}, +} diff --git a/src-ui/setup-jest.ts b/src-ui/setup-jest.ts index 162884feb..6ac94a275 100644 --- a/src-ui/setup-jest.ts +++ b/src-ui/setup-jest.ts @@ -121,19 +121,4 @@ HTMLCanvasElement.prototype.getContext = < typeof HTMLCanvasElement.prototype.getContext >jest.fn() -// pdfjs -jest.mock('pdfjs-dist', () => ({ - getDocument: jest.fn(() => ({ - promise: Promise.resolve({ numPages: 3 }), - })), - GlobalWorkerOptions: { workerSrc: '' }, - VerbosityLevel: { ERRORS: 0 }, - globalThis: { - pdfjsLib: { - GlobalWorkerOptions: { - workerSrc: '', - }, - }, - }, -})) -jest.mock('pdfjs-dist/web/pdf_viewer', () => ({})) +jest.mock('pdfjs-dist')