Skip to content

chore(test): revive jest suite (ttypescript→ts-patch, ts-jest pin, native mocks)#640

Closed
islandbitcoin wants to merge 1 commit into
feat/fygarofrom
chore/fix-jest-suite
Closed

chore(test): revive jest suite (ttypescript→ts-patch, ts-jest pin, native mocks)#640
islandbitcoin wants to merge 1 commit into
feat/fygarofrom
chore/fix-jest-suite

Conversation

@islandbitcoin

Copy link
Copy Markdown
Contributor

Summary

The Jest unit-test suite could not run at all (0 tests executable). This PR fixes the toolchain so the suite runs again. It went from 0 → ~119 passing locally.

This is infra only — no app/source code is changed.

Root causes & fixes

  1. ttypescript is unmaintained & incompatible with TS 5.x (Cannot set property createProgram).

    • Migrated to ts-patch (the maintained successor that ts-auto-mock itself uses).
    • Added ts-patch dep + a hack:ts-patch script wired into the existing prepare hook.
    • Switched the ts-jest compiler to the standard "typescript", which ts-patch patches in place to enable the ts-auto-mock transformer declared in tsconfig.jest.json.
  2. ts-jest floated to 29.4.x, which requires ts.JSDocParsingMode.ParseAll (TS 5.3+) and crashes on the pinned typescript@5.0.4 (Cannot read properties of undefined (reading 'ParseAll')).

    • Pinned ts-jest to ~29.2.6 (last line without that requirement).
  3. Pre-existing cross-file type errors aborted the whole run.

    • Set ts-jest diagnostics: { warnOnly: true } so type errors are surfaced as warnings without killing the runner.
  4. Native modules crash at import time under jest.

    • Added manual mocks: react-native-fs, react-native-keychain, react-native-share, @breeztech/breez-sdk-spark-react-native, @breeztech/react-native-breez-sdk-liquid, and @env (+ moduleNameMapper).
    • Rewrote the AsyncStorage mock, whose re-export resolved to undefined and broke redux-persist (config.storage is required).
  5. ESM-only packages (@reduxjs/toolkit v2, react-redux, uuid) resolve via the react-native export condition to ESM/source jest can't parse.

    • Added a custom jest.resolver.js that forces those through their CommonJS condition, added cjs/mjs to moduleFileExtensions, and extended transformIgnorePatterns.

Result

  • Before: suite fails to compile, 0 tests run.
  • After: ~119 passing, 18 failing.

The remaining failures are pre-existing and out of scope for this PR:

  • Test/code assertion drift (URI formats, btc address, creation-data defaults).
  • Breez SDK Spark migration (Breez SDK Spark migration #585) tests that were never updated for the native SDK (Breez SDK not initialized).
  • Screen tests that still need redux store/persist bootstrapping + a longer ESM resolver allowlist.

Test plan

yarn install        # runs ts-patch install via prepare hook
yarn jest --runInBand

Expect the suite to run (no compile error) with ~119 passing.

…ative mocks)

The jest suite could not run at all. Several layered issues:

1. jest.config used `compiler: "ttypescript"`, which is unmaintained and
   incompatible with TypeScript 5.x ("Cannot set property createProgram").
   Migrate to ts-patch (the maintained successor used by ts-auto-mock itself):
   - add ts-patch dependency + a `hack:ts-patch` script wired into `prepare`
   - switch the ts-jest compiler to the standard "typescript", which ts-patch
     patches in place to enable the ts-auto-mock transformer from
     tsconfig.jest.json.

2. ts-jest had floated to 29.4.x, which requires ts.JSDocParsingMode.ParseAll
   (TypeScript 5.3+) and crashes on the pinned typescript@5.0.4. Pin ts-jest to
   ~29.2.6 (last line without that requirement).

3. Several app modules have pre-existing cross-file type errors that aborted the
   whole run. Set ts-jest `diagnostics: { warnOnly: true }` so type errors are
   surfaced as warnings without killing the runner.

4. Native modules pulled in at import time crash under jest. Add manual mocks:
   react-native-fs, react-native-keychain, react-native-share,
   @breeztech/breez-sdk-spark-react-native, @breeztech/react-native-breez-sdk-liquid,
   and @env (+ moduleNameMapper). Rewrite the AsyncStorage mock, whose re-export
   resolved to undefined and broke redux-persist ("config.storage is required").

5. ESM-only packages (@reduxjs/toolkit v2, react-redux, uuid) resolve via the
   react-native export condition to ESM/source jest cannot parse. Add a custom
   jest.resolver.js that forces those through their CommonJS condition, add
   cjs/mjs to moduleFileExtensions, and extend transformIgnorePatterns.

Result: the suite goes from 0 runnable to ~119 passing locally. Remaining
failures are pre-existing and out of scope here: test/code assertion drift, the
Breez SDK Spark migration (#585) tests that were never updated for the native
SDK, and screen tests that still need redux store/persist bootstrapping plus a
longer ESM resolver allowlist.
islandbitcoin added a commit that referenced this pull request Jun 18, 2026
- tsconfig: module was 'Node16' while the extended @react-native config
  uses moduleResolution 'bundler', which requires an esnext-class module
  (TS5095). Set module=esnext + moduleResolution=bundler explicitly.
- typos: accept the earns quiz-ID misspellings (Aggrement/Governement) as
  bare words too — they're a backend contract and can't be renamed.

Addresses ENG-420. Does not cover Test (ttypescript — see #640) or the
i18n drift (needs `yarn update-translations` run locally).

Co-authored-by: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@islandbitcoin islandbitcoin changed the base branch from main to feat/fygaro June 18, 2026 16:20
@linear

linear Bot commented Jun 18, 2026

Copy link
Copy Markdown

ENG-421

@islandbitcoin islandbitcoin self-assigned this Jun 18, 2026
@islandbitcoin

Copy link
Copy Markdown
Contributor Author

Closing as superseded.

This PR fixes the jest-suite load failure via ts-patch (compiler: "typescript" + hack:ts-patch install). In the meantime, feat/fygaro solved the same problem a different way — ts-jest astTransformers with a ts-auto-mock wrapper and no ts-patch (commit a1c07eb, "run spec without ttypescript"). That approach is already on feat/fygaro and rides to main via #621, so merging this would re-introduce ts-patch and conflict with the astTransformers setup.

It's also stale — its merge-base with feat/fygaro is still the original branch point; it never caught up (still pins Node 18 in test.yml, predating the #638 Node-20 bump).

What's still valuable here are the native mocks this added and feat/fygaro still lacks (__mocks__/@breeztech/*, env, react-native-fs, react-native-keychain, react-native-share, jest.resolver.js). Salvaging those (re-validated against the astTransformers setup, not ts-patch) + greening the full suite is tracked in ENG-433. The remaining Check Code gate (the ~82 tsc errors) is ENG-425.

ENG-421 (the load-failure ticket this PR was opened for) is effectively resolved by the astTransformers approach on feat/fygaro.

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.

2 participants