Files
minibits_wallet/jest.config.js
T

49 lines
3.2 KiB
JavaScript

module.exports = {
preset: 'react-native',
// Only treat *.test/*.spec files as tests. The default preset glob also
// matches every .js file under __tests__, which would pull in the i18n
// scripts (missingTranslations.js etc.) that are run via `yarn test:i18n`.
testMatch: ['**/*.(test|spec).[jt]s?(x)'],
// The `(.*/)?` makes the allowlist apply at any depth: nostr-tools carries its
// own ESM-only @noble copies in a nested node_modules, and those need babel too.
transformIgnorePatterns: [
'node_modules/(?!(.*/)?((jest-)?react-native|@react-native|@react-native-community|@cashu|@noble|@scure|cborg|react-native-flash-message)/)',
],
// Several native or source-shipped packages are unusable under jest, and the
// MODEL layer reaches all of them at import time (Mint -> services barrel ->
// mmkvStorage / keyChain / db). That is what made MST stores impossible to
// instantiate in a test at all; these mappings are what make store tests possible.
moduleNameMapper: {
// cborg (via @gandlaf21/bc-ur) is ESM-only and its exports map has an "import"
// condition only, which jest's CJS resolver cannot satisfy. Point at the entry
// file directly and let babel transform it (see transformIgnorePatterns above).
'^cborg$': '<rootDir>/node_modules/cborg/cborg.js',
// Same shape as the @scure/bip39 mapping below: the package's exports map
// names only the suffixed path, so app code imports it that way. This accepts
// both spellings, for transitive dependencies still using the bare one.
'^@noble/hashes/utils(?:\\.js)?$': '@noble/hashes/utils.js',
// The package's exports map lists ONLY the explicit `.js` subpath, so app code
// imports it that way (moduleResolution is "bundler", which honours exports).
// This accepts both spellings, since a transitive dependency may still use the
// extensionless one, which no resolver can infer from that map.
'^@scure/bip39/wordlists/([^/.]+)(?:\\.js)?$': '@scure/bip39/wordlists/$1.js',
// quick-crypto's native module is unavailable under jest; route to a
// Node `crypto` shim so deps that import it at load time (e.g. bip32) work.
'^react-native-quick-crypto$': '<rootDir>/__mocks__/react-native-quick-crypto.js',
// MMKV and op-sqlite are native. MMKV is Map-backed and behaves; op-sqlite is
// only an import-time shim and throws if a statement is actually executed —
// use node:sqlite with the production SQL for real DB semantics (see the db
// suites).
'^react-native-mmkv$': '<rootDir>/__mocks__/react-native-mmkv.js',
'^@op-engineering/op-sqlite$': '<rootDir>/__mocks__/op-sqlite.js',
// Sentry ships untransformed ESM, so anything importing logService fails to
// parse. Mocking Sentry rather than logService lets the REAL logger load, so
// tests can cover code that logs instead of stubbing the logger away.
'^@sentry/react-native$': '<rootDir>/__mocks__/sentry-react-native.js',
// react-native-localize is a native TurboModule, and src/i18n calls getLocales()
// at module scope — so without this, importing `translate` anywhere makes the
// module unloadable under jest.
'^react-native-localize$': '<rootDir>/__mocks__/react-native-localize.js',
},
}