chore(test): revive jest suite (ttypescript→ts-patch, ts-jest pin, native mocks)#640
chore(test): revive jest suite (ttypescript→ts-patch, ts-jest pin, native mocks)#640islandbitcoin wants to merge 1 commit into
Conversation
…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.
- 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>
|
Closing as superseded. This PR fixes the jest-suite load failure via ts-patch ( It's also stale — its merge-base with What's still valuable here are the native mocks this added and ENG-421 (the load-failure ticket this PR was opened for) is effectively resolved by the astTransformers approach on |
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
ttypescriptis unmaintained & incompatible with TS 5.x (Cannot set property createProgram).ts-patch(the maintained successor thatts-auto-mockitself uses).ts-patchdep + ahack:ts-patchscript wired into the existingpreparehook.ts-jestcompiler to the standard"typescript", whichts-patchpatches in place to enable thets-auto-mocktransformer declared intsconfig.jest.json.ts-jestfloated to 29.4.x, which requirests.JSDocParsingMode.ParseAll(TS 5.3+) and crashes on the pinnedtypescript@5.0.4(Cannot read properties of undefined (reading 'ParseAll')).ts-jestto~29.2.6(last line without that requirement).Pre-existing cross-file type errors aborted the whole run.
diagnostics: { warnOnly: true }so type errors are surfaced as warnings without killing the runner.Native modules crash at import time under jest.
react-native-fs,react-native-keychain,react-native-share,@breeztech/breez-sdk-spark-react-native,@breeztech/react-native-breez-sdk-liquid, and@env(+moduleNameMapper).undefinedand brokeredux-persist(config.storage is required).ESM-only packages (
@reduxjs/toolkitv2,react-redux,uuid) resolve via thereact-nativeexport condition to ESM/source jest can't parse.jest.resolver.jsthat forces those through their CommonJS condition, addedcjs/mjstomoduleFileExtensions, and extendedtransformIgnorePatterns.Result
The remaining failures are pre-existing and out of scope for this PR:
Breez SDK not initialized).Test plan
yarn install # runs ts-patch install via prepare hook yarn jest --runInBandExpect the suite to run (no compile error) with ~119 passing.