mirror of
https://github.com/status-im/status-mobile.git
synced 2025-02-11 08:07:07 +00:00
Fix all component tests after the latest RN upgrade. Fixes https://github.com/status-im/status-mobile/issues/18157 Closes https://github.com/status-im/status-mobile/pull/18235 Dependency changes - Upgraded Jest: from 26.6.3 to latest 29.7.0. - Upgraded @testing-library/jest-native: from 5.3.0 to latest 5.4.3 - Upgraded @testing-library/react-native: from 11.5.4 to 12.4.2 - Removed explicit dependency on jest-circus, this is now the default test runner. - Removed explicit dependency on jest-environment-node. This is handled by the package manager. - Added jest-silent-reporter at version 0.5.0. ### Why component tests were failing? Many tests were failing because we were using RN Testing Library (RNTL) in an unreliable fashion. With the recent library upgrades, the unreliability was excerbated. Other times, the tests were incorrectly arranging data. ### with-redefs does not work with async code Generally speaking, with-redefs should not be used with async code, assume the worst. The scope of the macro will cease to exist by the time the async code runs. In many tests we were using with-redefs, then calling render, but for some components that use use-effect, JS timers, animations, etc it's unreliable and were the reason for failures. It's easy to reproduce too: ```clojure (defn foo [] :foo) (foo) ;; => :foo (with-redefs [foo (constantly :bar)] (foo)) ;; => :bar (js/setTimeout (fn [] (tap> [:calling-foo (foo)])) 100) ;; Taps [:calling-foo :foo] ;; As you would expect, when running without with-redefs, it prints :foo. ;; So far so good, but whatch what happens with async code: (with-redefs [foo (constantly :bar)] (js/setTimeout (fn [] (tap> [:calling-foo (foo)])) 100)) ;; Taps [:calling-foo :foo] ;; ====> PROBLEM: Taps :foo, not :bar as one might expect ``` ### Not waiting on wait-for When test-helpers.component/wait-for is used, subsequent assertions/etc should be done after the promise returned by wait-for is resolved. But remember to not perform side-effects inside the wait-for callback (check out the docs https://callstack.github.io/react-native-testing-library/docs/api#waitfor). Most, if not all of our usages of wait-for were not waiting. #### Improvement 1 - Silence Jest on demand If you need to re-run component tests frequently, you may want to reduce the output verbosity. By passing JEST_USE_SILENT_REPORTER=true to make component-test or make component-test-watch you will see a lot less noise and be able to focus on what really matters to you. #### Improvement 2 - Selectively focus/disable tests Because of our need to first compile CLJS to JS before running tests via Jest, we couldn't easily skip or focus on specific tests. From this commit onwards, we should never again have to change the list of requires in files core_spec.cljs. Commenting out required namespaces gives a bad DX because it causes constant rebasing issues. #### Improvement 3 - Translations now work as in prod code (but only English) Translations performed by *-by-translation-text can be done now without any workaround under the hood. The query functions are now linted just like i18n/label, which means static translation keywords must be qualified with :t/, which is good for consistency.
168 lines
8.7 KiB
Clojure
168 lines
8.7 KiB
Clojure
;; shadow-cljs configuration
|
|
{:source-paths ["src" "test/cljs"]
|
|
|
|
:dependencies [[reagent "1.2.0"]
|
|
[re-frame "1.3.0"]
|
|
[binaryage/oops "0.7.2"]
|
|
[com.andrewmcveigh/cljs-time "0.5.2"]
|
|
[com.taoensso/timbre "6.3.1"]
|
|
[cljs-bean "1.9.0"]
|
|
[com.cognitect/transit-cljs "0.8.280"]
|
|
[camel-snake-kebab "0.4.3"]
|
|
[metosin/malli "0.13.0"]
|
|
|
|
;; Dev dependencies
|
|
[refactor-nrepl "3.9.1"]
|
|
[cider/cider-nrepl "0.31.0"]
|
|
[cider/piggieback "0.4.1"]
|
|
[org.slf4j/slf4j-nop "2.0.9"]
|
|
[re-frisk-remote "1.6.0"]
|
|
[nubank/matcher-combinators "3.8.8"]
|
|
|
|
;; Use the same version specified in the Nix dependency.
|
|
[clj-kondo/clj-kondo "2023.09.07"]
|
|
|
|
;; Routing
|
|
[bidi "2.1.6"]
|
|
;; Test dependencies
|
|
[day8.re-frame/test "0.1.5"]
|
|
[com.taoensso/tufte "2.6.3"]]
|
|
|
|
;; port and middleware for repl in development
|
|
:nrepl {:port 7888
|
|
:middleware [cider.piggieback/wrap-cljs-repl
|
|
refactor-nrepl.middleware/wrap-refactor]}
|
|
|
|
;; shadow-cljs web interface
|
|
:http {:port 3449
|
|
:host "0.0.0.0"}
|
|
|
|
:cache-blockers #{legacy.status-im.utils.js-resources legacy.status-im.ui.components.icons.icons}
|
|
|
|
:builds
|
|
{:mobile
|
|
{:target :react-native
|
|
;; To match the folder created by Nix build of JSBundle.
|
|
:output-dir "result"
|
|
:init-fn status-im.core/init
|
|
;; When false, the Shadow-CLJS watcher won't automatically refresh
|
|
;; the target files (a.k.a hot reload). When false, you can manually
|
|
;; reload by calling `shadow.cljs.devtools.api/watch-compile-all!`.
|
|
:devtools {:autobuild #shadow/env ["SHADOW_AUTOBUILD_ENABLED" :default true :as :bool]}
|
|
:dev {:devtools {:before-load-async status-im.setup.hot-reload/before-reload
|
|
:after-load-async status-im.setup.hot-reload/reload
|
|
:build-notify status-im.setup.hot-reload/build-notify
|
|
:preloads [re-frisk-remote.preload
|
|
status-im.setup.schema-preload
|
|
;; In order to use component test helpers in the REPL we
|
|
;; need to preload namespaces that are not normally required
|
|
;; by production code, such as
|
|
;; @testing-library/react-native.
|
|
test-helpers.component]}
|
|
:closure-defines
|
|
{status-im.config/POKT_TOKEN #shadow/env "POKT_TOKEN"
|
|
status-im.config/INFURA_TOKEN #shadow/env "INFURA_TOKEN"
|
|
status-im.config/OPENSEA_API_KEY #shadow/env "OPENSEA_API_KEY"
|
|
status-im.config/ALCHEMY_ARBITRUM_GOERLI_TOKEN #shadow/env "ALCHEMY_ARBITRUM_GOERLI_TOKEN"
|
|
status-im.config/ALCHEMY_OPTIMISM_GOERLI_TOKEN #shadow/env "ALCHEMY_OPTIMISM_GOERLI_TOKEN"
|
|
status-im.config/ALCHEMY_OPTIMISM_MAINNET_TOKEN #shadow/env "ALCHEMY_OPTIMISM_MAINNET_TOKEN"
|
|
status-im.config/ALCHEMY_ARBITRUM_MAINNET_TOKEN #shadow/env "ALCHEMY_ARBITRUM_MAINNET_TOKEN"}
|
|
:compiler-options {:output-feature-set :es5
|
|
;; We disable `:fn-deprecated` warnings because we
|
|
;; are managing deprecation via clj-kondo and we
|
|
;; don't want the terminal output to be littered
|
|
;; with warnings on every code reload.
|
|
:warnings {:fn-deprecated false}
|
|
:closure-defines {re-frame.trace/trace-enabled? true}
|
|
:source-map false
|
|
;; This seems to be necessary while using the REPL,
|
|
;; otherwise sometimes you'll get weird errors when
|
|
;; instrumenting functions.
|
|
:static-fns false
|
|
:infer-externs true}
|
|
;; if you want to use a real device, set your local ip
|
|
;; in the SHADOW_HOST env variable to make sure that
|
|
;; it will use the right interface
|
|
:local-ip #shadow/env "SHADOW_HOST"}
|
|
:chunks {:fleets legacy.status-im.fleet.default-fleet/default-fleets}
|
|
:release
|
|
{:closure-defines
|
|
{status-im.config/POKT_TOKEN #shadow/env "POKT_TOKEN"
|
|
status-im.config/INFURA_TOKEN #shadow/env "INFURA_TOKEN"
|
|
status-im.config/OPENSEA_API_KEY #shadow/env "OPENSEA_API_KEY"
|
|
status-im.config/ALCHEMY_ARBITRUM_GOERLI_TOKEN #shadow/env "ALCHEMY_ARBITRUM_GOERLI_TOKEN"
|
|
status-im.config/ALCHEMY_OPTIMISM_GOERLI_TOKEN #shadow/env "ALCHEMY_OPTIMISM_GOERLI_TOKEN"
|
|
status-im.config/ALCHEMY_OPTIMISM_MAINNET_TOKEN #shadow/env "ALCHEMY_OPTIMISM_MAINNET_TOKEN"
|
|
status-im.config/ALCHEMY_ARBITRUM_MAINNET_TOKEN #shadow/env "ALCHEMY_ARBITRUM_MAINNET_TOKEN"}
|
|
:compiler-options {:output-feature-set :es6
|
|
;;disable for android build as there
|
|
;;is an intermittent warning with deftype
|
|
:warnings-as-errors false
|
|
:infer-externs :auto
|
|
:static-fns true
|
|
:fn-invoke-direct true
|
|
:optimizations :advanced
|
|
:js-options {:js-provider :closure}}}}
|
|
;; the tests are ran with node, react-native dependencies are mocked
|
|
;; by using node --require override.js, which uses the node-library
|
|
;; produced by the target :mocks below and redefines node require
|
|
;; function to use the mocks instead of the rn libraries
|
|
:test
|
|
{:output-to "target/test/test.js"
|
|
:output-dir "target/test"
|
|
:optimizations :simple
|
|
:target :node-test
|
|
:dev {:devtools {:preloads [status-im.setup.schema-preload]}}
|
|
;; Uncomment line below to `make test-watch` a specific file
|
|
;; :ns-regexp "status-im.subs.messages-test$"
|
|
:main legacy.status-im.test-runner/main
|
|
;; set :ui-driven to true to let shadow-cljs inject node-repl
|
|
:ui-driven true
|
|
:closure-defines
|
|
{schema.core/throw-on-error? true
|
|
status-im.config/POKT_TOKEN #shadow/env "POKT_TOKEN"
|
|
status-im.config/INFURA_TOKEN #shadow/env "INFURA_TOKEN"
|
|
status-im.config/OPENSEA_API_KEY #shadow/env "OPENSEA_API_KEY"
|
|
status-im.config/ALCHEMY_ARBITRUM_GOERLI_TOKEN #shadow/env "ALCHEMY_ARBITRUM_GOERLI_TOKEN"
|
|
status-im.config/ALCHEMY_OPTIMISM_GOERLI_TOKEN #shadow/env "ALCHEMY_OPTIMISM_GOERLI_TOKEN"
|
|
status-im.config/ALCHEMY_OPTIMISM_MAINNET_TOKEN #shadow/env "ALCHEMY_OPTIMISM_MAINNET_TOKEN"
|
|
status-im.config/ALCHEMY_ARBITRUM_MAINNET_TOKEN #shadow/env "ALCHEMY_ARBITRUM_MAINNET_TOKEN"}
|
|
:compiler-options
|
|
{;; needed because we override require and it
|
|
;; messes with source-map which reports callstack
|
|
;; exceeded exceptions instead of real issues
|
|
:source-map false
|
|
;; needed because we use deref in tests
|
|
:static-fns false
|
|
:optimizations :simple
|
|
:warnings {:fn-deprecated false}
|
|
:infer-externs true}}
|
|
|
|
;; mock.js-dependencies is mocking the react-native libraries
|
|
;; we build it as a node library so that it can be required by
|
|
;; override.js
|
|
:mocks
|
|
{:target :node-library
|
|
:exports {:mocks mocks.js-dependencies/mock}
|
|
:output-to "target/mocks/mocks.js"
|
|
:output-dir "target/mocks"
|
|
:compiler-options {:optimizations :simple
|
|
:source-map false}}
|
|
:component-test {:target :npm-module
|
|
:entries [;; We need to tell shadow-cljs to compile
|
|
;; the preloads namespaces because they
|
|
;; will be used directly by Jest in the
|
|
;; option setupFilesAfterEnv.
|
|
test-helpers.component-tests-preload
|
|
status-im.setup.schema-preload
|
|
|
|
quo.core-spec
|
|
status-im.core-spec]
|
|
:ns-regexp "component-spec$"
|
|
:output-dir "component-spec"
|
|
:closure-defines {schema.core/throw-on-error? true}
|
|
:compiler-options {:warnings-as-errors false
|
|
:warnings {:fn-deprecated false}
|
|
:static-fns false
|
|
:infer-externs true}}}}
|