Skip to content

Transform ESM rather than mock#31

Closed
imnasnainaec wants to merge 1 commit into
tokenize-bookfrom
tokenize-book-unmock
Closed

Transform ESM rather than mock#31
imnasnainaec wants to merge 1 commit into
tokenize-bookfrom
tokenize-book-unmock

Conversation

@imnasnainaec

@imnasnainaec imnasnainaec commented Apr 24, 2026

Copy link
Copy Markdown
Contributor

Suggestion for #30
An optional alternative to creating mocks for Jest-unfriendly deps.


This change is Reviewable

Summary by CodeRabbit

Release Notes

  • Documentation

    • Updated README to reflect restructured parser organization.
  • Tests

    • Updated Jest configuration to improve external dependency handling.
    • Removed obsolete mock configuration file.

@imnasnainaec imnasnainaec self-assigned this Apr 24, 2026
@imnasnainaec imnasnainaec added the 🟪Idea Idea-priority PR: can be closed... label Apr 24, 2026
@coderabbitai

coderabbitai Bot commented Apr 24, 2026

Copy link
Copy Markdown

Important

Review skipped

Auto reviews are disabled on base/target branches other than the default branch.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: fe3e9082-5b9d-4c20-9f0f-439ee2ee947e

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • ✅ Review completed - (🔄 Check again to review again)
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch tokenize-book-unmock

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@jest.config.ts`:
- Around line 125-130: The transform configuration currently uses ts-jest as a
plain string and the transformIgnorePatterns only whitelists
platform-bible-react and lucide-react; update the ts-jest configuration to
explicitly override allowJs (so ts-jest will compile .js/.mjs from node_modules
if those packages ship JS) by providing ts-jest options (either via the
transform entry as ['ts-jest', { tsconfig: { allowJs: true } }] or via the
globals/'ts-jest' config), keep the existing transformIgnorePatterns whitelist
for platform-bible-react and lucide-react, and be prepared to extend that
whitelist if transitive ESM deps fail to parse during the full test run.

In `@README.md`:
- Line 98: Update the README entry that currently reads "parsing PT0 interlinear
XML" to "parsing PT9 interlinear XML" so the documentation matches the actual
parser directory and schema (reference: src/parsers/pt9/ and pt9-xml.md); locate
the string in the README and replace "PT0" with "PT9" in that description.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: dee307f3-b28d-4bf8-8931-fb64a21711ec

📥 Commits

Reviewing files that changed from the base of the PR and between a590bde and 8b82a92.

📒 Files selected for processing (3)
  • README.md
  • __mocks__/platform-bible-react.tsx
  • jest.config.ts
💤 Files with no reviewable changes (1)
  • mocks/platform-bible-react.tsx

Comment thread jest.config.ts
Comment on lines 125 to +130
transform: {
'\\.[jt]sx?$': 'ts-jest',
},

/** Transform dependencies with ESM that Jest cannot parse. */
transformIgnorePatterns: ['node_modules/(?!(platform-bible-react|lucide-react)/)'],

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟡 Minor

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
# 1) Which package manager is in use?
fd -HI -t f -d 2 '^(package-lock\.json|pnpm-lock\.yaml|yarn\.lock|bun\.lockb)$'

# 2) Does tsconfig enable allowJs (needed for ts-jest to transform .js in node_modules)?
fd -HI -t f '^tsconfig(\..*)?\.json$' --exec sh -c 'echo "=== $1 ==="; cat "$1"' _ {}

# 3) Look for ts-jest transform options in jest config(s) / package.json
rg -nP -C2 '\b(ts-jest|allowJs|useESM|isolatedModules)\b' --type=ts --type=json

# 4) Peek at the entry points / deps of the two packages being transformed
fd -HI -t f '^package\.json$' node_modules/platform-bible-react node_modules/lucide-react 2>/dev/null \
  | xargs -I{} sh -c 'echo "=== {} ==="; jq "{name, type, main, module, exports, dependencies, peerDependencies}" {}'

Repository: sillsdev/interlinearizer-extension

Length of output: 50391


🏁 Script executed:

# 1) Check the full jest.config.ts to see if there's a ts-jest allowJs override
cat jest.config.ts | head -150

# 2) Look for ts-jest preset or options
rg -A 10 -B 2 "ts-jest" jest.config.ts

# 3) Check if the two packages exist in node_modules
ls -la node_modules/platform-bible-react node_modules/lucide-react 2>&1 | head -20

Repository: sillsdev/interlinearizer-extension

Length of output: 6137


🏁 Script executed:

# Check package.json for the two packages and jest/ts-jest versions
rg -A 20 '"dependencies"|"devDependencies"' package.json | head -40

# Check if there's any ts-jest preset or globals config in jest.config.ts
rg -i "preset|globals|jest" jest.config.ts

# Look at comment around the transform to see if there's rationale for the format
grep -B 5 -A 5 "Transform TS/TSX" jest.config.ts

Repository: sillsdev/interlinearizer-extension

Length of output: 2544


🏁 Script executed:

# Check if platform-bible-react or lucide-react are referenced anywhere in the codebase
rg -i "platform-bible-react|lucide-react" src/ --type ts --type tsx --type json

# Check if there's a TODO or comment about adding these packages
rg -B 3 -A 3 "platform-bible-react|lucide-react" jest.config.ts

# Check git status or recent changes to understand context
git log --oneline -20 jest.config.ts 2>/dev/null | head -10

Repository: sillsdev/interlinearizer-extension

Length of output: 347


🏁 Script executed:

# Check jest/ts-jest version to understand current capabilities
rg '"jest"|"ts-jest"' package.json --type json -A 1

# Search for any issues or comments in code about these packages or ESM
rg -i "esm|@module|import\.meta" src/ --type ts --type js 2>/dev/null | head -20

Repository: sillsdev/interlinearizer-extension

Length of output: 260


Verify ts-jest config handles ESM from platform-bible-react and lucide-react.

The two packages are whitelisted to be transformed by ts-jest instead of mocked, but a few things need checking:

  1. allowJs override: The main tsconfig.json has allowJs: false, and jest.config.ts specifies ts-jest as a plain string (no options object). This means ts-jest will inherit that setting and won't emit .js files from node_modules. If either package ships .js/.mjs files, they'll fail to parse. Consider either:

    • Adding allowJs: true as an override in the ts-jest transform config, or
    • Verifying those packages export only TypeScript or pre-compiled ESM
  2. Transitive ESM dependencies: The negative-lookahead pattern only whitelists these two packages. If either re-exports from another ESM-only package (common for icon libraries or Radix/class-variance-authority), those will still be ignored and tests will fail at import time. Be prepared to extend the list once tests run and reveal missing deps.

Worth running the full test suite (not just a single file) to surface any of these issues before merging.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@jest.config.ts` around lines 125 - 130, The transform configuration currently
uses ts-jest as a plain string and the transformIgnorePatterns only whitelists
platform-bible-react and lucide-react; update the ts-jest configuration to
explicitly override allowJs (so ts-jest will compile .js/.mjs from node_modules
if those packages ship JS) by providing ts-jest options (either via the
transform entry as ['ts-jest', { tsconfig: { allowJs: true } }] or via the
globals/'ts-jest' config), keep the existing transformIgnorePatterns whitelist
for platform-bible-react and lucide-react, and be prepared to extend that
whitelist if transitive ESM deps fail to parse during the full test run.

Comment thread README.md
- `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

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟡 Minor

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
# Description: Check parser directory contents and references to PT0/PT9 terminology

# Check what files exist in the pt9 directory
echo "=== Files in src/parsers/pt9/ directory ==="
fd . src/parsers/pt9/ --type f

# Search for PT0 references in parser code and docs
echo -e "\n=== References to 'PT0' in parser files ==="
rg -i 'pt0' src/parsers/ -C2

# Search for PT9 references in parser code and docs
echo -e "\n=== References to 'PT9' in parser files ==="
rg -i 'pt9' src/parsers/ -C2

# Check test data filenames for version indicators
echo -e "\n=== Test data files ==="
fd . test-data/ --type f

Repository: sillsdev/interlinearizer-extension

Length of output: 2043


Fix terminology: "PT0" should be "PT9".

Line 98 states "parsing PT0 interlinear XML," but the directory src/parsers/pt9/ and all parser documentation (pt9-xml.md) consistently reference PT9. Update the description to "parsing PT9 interlinear XML" to match the actual schema and code.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@README.md` at line 98, Update the README entry that currently reads "parsing
PT0 interlinear XML" to "parsing PT9 interlinear XML" so the documentation
matches the actual parser directory and schema (reference: src/parsers/pt9/ and
pt9-xml.md); locate the string in the README and replace "PT0" with "PT9" in
that description.

@alex-rawlings-yyc

Copy link
Copy Markdown
Contributor

I can't get this to work on my end. Here's what I found:

The platform-bible-react mock cannot be removed because platform-bible-react/dist/index.cjs
imports @eten-tech-foundation/platform-editor as an external peer dep rather than bundling it
inline. platform-editor is ESM-only (no CJS export), so Jest — which runs in CommonJS mode —
cannot evaluate it.

The cascade that follows:

  • platform-bible-react/dist/index.cjs → requires platform-editor
  • platform-editor/dist/index.js → imports @lexical/react/LexicalErrorBoundary (also ESM)
  • @lexical/react/LexicalErrorBoundary → requires react-error-boundary (also ESM)

transformIgnorePatterns cannot fix this cleanly:

  • platform-editor lives under paranext-core/.yalc/ — no node_modules/ segment in its path,
    so it reaches ts-jest, but ts-jest won't compile .js without allowJs: true, which is
    intentionally false in tsconfig.json.
  • The @lexical/* and react-error-boundary packages are under paranext-core/node_modules/,
    so they match the ignore pattern and are skipped — each would need its own exception entry,
    with no guarantee the chain ends there.

Perhaps I'm misunderstanding something here.

@imnasnainaec

Copy link
Copy Markdown
Contributor Author

I'm not sure why the tests ran just fine for me locally with these changes, but it's probably not worth trying to sort out.

@imnasnainaec
imnasnainaec deleted the tokenize-book-unmock branch April 27, 2026 14:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

🟪Idea Idea-priority PR: can be closed...

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants