From b2daaa2159ca2f9f2d1a7e792d07322de300a195 Mon Sep 17 00:00:00 2001 From: Julien Eluard Date: Wed, 29 Nov 2017 16:31:15 +0100 Subject: [PATCH] Hook require to prevent tests failures when loading images --- project.clj | 1 + resources/js/hook-require.js | 14 ++++++++++++++ test/cljs/status_im/utils/ethereum/tokens.cljs | 5 ----- 3 files changed, 15 insertions(+), 5 deletions(-) create mode 100644 resources/js/hook-require.js delete mode 100644 test/cljs/status_im/utils/ethereum/tokens.cljs diff --git a/project.clj b/project.clj index 3c12ce8560..674e4c432d 100644 --- a/project.clj +++ b/project.clj @@ -55,6 +55,7 @@ :output-to "target/test/test.js" :output-dir "target/test" :optimizations :none + :preamble ["js/hook-require.js"] :target :nodejs}} {:id "protocol" :source-paths ["src" "test/cljs"] diff --git a/resources/js/hook-require.js b/resources/js/hook-require.js new file mode 100644 index 0000000000..162d1340da --- /dev/null +++ b/resources/js/hook-require.js @@ -0,0 +1,14 @@ +const m = require('module'); +const originalLoader = m._load; + +/* + Hook `require` so that RN abuse of require does not break when running tests in nodejs. +*/ + +m._load = function hookedLoader(request, parent, isMain) { + if (request.match(/.jpeg|.jpg|.png$/)) { + return { uri: request }; + } + + return originalLoader(request, parent, isMain); +}; diff --git a/test/cljs/status_im/utils/ethereum/tokens.cljs b/test/cljs/status_im/utils/ethereum/tokens.cljs deleted file mode 100644 index adf37ccf50..0000000000 --- a/test/cljs/status_im/utils/ethereum/tokens.cljs +++ /dev/null @@ -1,5 +0,0 @@ -(ns status-im.utils.ethereum.tokens) - -(def ethereum {}) - -(def all {}) \ No newline at end of file