From 8b82a9251b0f2c60cfaf3cfe9b5bb6b76143fe8a Mon Sep 17 00:00:00 2001 From: Danny Rorabaugh Date: Fri, 24 Apr 2026 17:12:14 -0400 Subject: [PATCH] Transform ESM rather than mock --- README.md | 2 +- __mocks__/platform-bible-react.tsx | 60 ------------------------------ jest.config.ts | 6 +-- 3 files changed, 4 insertions(+), 64 deletions(-) delete mode 100644 __mocks__/platform-bible-react.tsx diff --git a/README.md b/README.md index 5bd167a7..5d5d1880 100644 --- a/README.md +++ b/README.md @@ -95,7 +95,7 @@ The general file structure for an extension is as follows: - `src/` contains the source code for the extension - `src/main.ts` is the main entry file for the extension (registers commands and wires interlinear XML) - `src/types/interlinearizer.d.ts` is this extension's types file that defines how other extensions can use this extension through the `papi`. It is copied into the build folder - - `src/parsers/interlinearXmlParser.ts` parses interlinear XML into structured data (uses fast-xml-parser). The PT9 XML schema and parsed output are documented in `src/parsers/pt9-xml.md` + - `src/parsers/pt9/` contains parser and schema for parsing PT0 interlinear XML into structured data - `*.web-view.tsx` files will be treated as React WebViews - `*.web-view.scss` files provide styles for WebViews - `*.web-view.html` files are a conventional way to provide HTML WebViews (no special functionality) diff --git a/__mocks__/platform-bible-react.tsx b/__mocks__/platform-bible-react.tsx deleted file mode 100644 index 44dba693..00000000 --- a/__mocks__/platform-bible-react.tsx +++ /dev/null @@ -1,60 +0,0 @@ -/** - * @file Jest mock for platform-bible-react. The real package ships ESM which Jest cannot parse - * without extra transform configuration. This stub provides the subset used by extension - * components: `cn`, `Button`, `BookChapterControl`, and `BOOK_CHAPTER_CONTROL_STRING_KEYS`. - */ - -import type { ButtonHTMLAttributes, ReactNode } from 'react'; - -function flattenCn(arg: unknown): string[] { - if (typeof arg === 'string') return arg.length > 0 ? [arg] : []; - if (Array.isArray(arg)) return arg.flatMap(flattenCn); - if (arg !== null && typeof arg === 'object') - return Object.entries(arg as Record) - .filter(([, v]) => Boolean(v)) - .map(([k]) => k); - return []; -} - -export const cn = (...args: unknown[]): string => args.flatMap(flattenCn).join(' '); - -interface ButtonProps extends ButtonHTMLAttributes { - variant?: string; - size?: string; - children?: ReactNode; - asChild?: boolean; -} - -export function Button({ children, variant: _v, size: _s, asChild: _a, ...rest }: ButtonProps) { - return ; -} - -interface ScriptureRef { - book: string; - chapterNum: number; - verseNum: number; -} - -export const BOOK_CHAPTER_CONTROL_STRING_KEYS: string[] = []; - -export function BookChapterControl({ - scrRef, - handleSubmit, -}: { - scrRef: ScriptureRef; - handleSubmit: (ref: ScriptureRef) => void; - className?: string; - localizedStrings?: Record; - recentSearches?: ScriptureRef[]; - onAddRecentSearch?: (scrRef: ScriptureRef) => void; - id?: string; -}) { - return ( -
- {scrRef.book} {scrRef.chapterNum}:{scrRef.verseNum} - -
- ); -} diff --git a/jest.config.ts b/jest.config.ts index b12ee344..88691c9c 100644 --- a/jest.config.ts +++ b/jest.config.ts @@ -92,9 +92,6 @@ const config: Config = { '^@papi/frontend/react$': '/__mocks__/papi-frontend-react.ts', /** Mock so test-helpers get UnsubscriberAsyncList without loading ESM deps. */ '^platform-bible-utils$': '/__mocks__/platform-bible-utils.ts', - /** Mock platform-bible-react and lucide-react — both ship ESM that Jest cannot parse. */ - '^platform-bible-react$': '/__mocks__/platform-bible-react.tsx', - '^lucide-react$': '/__mocks__/lucide-react.tsx', /** Resolve webpack ?inline imports. */ '^(.+)\\.web-view\\?inline$': '/__mocks__/web-view-inline.ts', /** Resolve webpack ?inline imports: SCSS content. */ @@ -128,6 +125,9 @@ const config: Config = { transform: { '\\.[jt]sx?$': 'ts-jest', }, + + /** Transform dependencies with ESM that Jest cannot parse. */ + transformIgnorePatterns: ['node_modules/(?!(platform-bible-react|lucide-react)/)'], }; export default config;