From eb701e865c0d649e12e097c4926090570230c41c Mon Sep 17 00:00:00 2001 From: Kant Date: Mon, 4 Nov 2024 20:47:46 +0100 Subject: [PATCH] chore: fix mobile jest tests with solana libs --- apps/ledger-live-mobile/jest.config.js | 1 + apps/ledger-live-mobile/scripts/resolver.js | 27 +++++++++++++++++++++ 2 files changed, 28 insertions(+) create mode 100644 apps/ledger-live-mobile/scripts/resolver.js diff --git a/apps/ledger-live-mobile/jest.config.js b/apps/ledger-live-mobile/jest.config.js index 8d8171ac34f4..933968e94a6d 100644 --- a/apps/ledger-live-mobile/jest.config.js +++ b/apps/ledger-live-mobile/jest.config.js @@ -62,6 +62,7 @@ module.exports = { { outputName: "llm-sonar-executionTests-report.xml", reportedFilePath: "absolute" }, ], ], + resolver: "/scripts/resolver.js", moduleNameMapper: { ...pathsToModuleNameMapper(compilerOptions.paths), "^react$": "/node_modules/react", diff --git a/apps/ledger-live-mobile/scripts/resolver.js b/apps/ledger-live-mobile/scripts/resolver.js new file mode 100644 index 000000000000..086c1886b28d --- /dev/null +++ b/apps/ledger-live-mobile/scripts/resolver.js @@ -0,0 +1,27 @@ +module.exports = (path, options) => { + // Call the defaultResolver, so we leverage its cache, error handling, etc. + return options.defaultResolver(path, { + ...options, + // Use packageFilter to process parsed `package.json` before the resolution (see https://www.npmjs.com/package/resolve#resolveid-opts-cb) + packageFilter: pkg => { + const pkgNamesToTarget = new Set([ + "rpc-websockets", + "@solana/codecs", + "@solana/codecs-core", + "@solana/errors", + "@solana/codecs-data-structures", + "@solana/codecs-numbers", + "@solana/codecs-strings", + "@solana/options", + ]); + + if (pkgNamesToTarget.has(pkg.name)) { + // console.log('>>>', pkg.name) + delete pkg["exports"]; + delete pkg["module"]; + } + + return pkg; + }, + }); +};