0b4a1545ae
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. |
||
---|---|---|
.. | ||
deps | ||
lib | ||
mobile | ||
pkgs | ||
scripts | ||
status-go | ||
DETAILS.md | ||
KNOWN_ISSUES.md | ||
README.md | ||
default.nix | ||
nix.conf | ||
overlay.nix | ||
pkgs.nix | ||
shell.nix | ||
shells.nix | ||
targets.nix |
README.md
Description
This folder contains configuration for Nix, a purely functional package manager used by the Status app for its build process.
Configuration
The main config file is nix/nix.conf
and its main purpose is defining the binary caches which allow download of packages to avoid having to compile them yourself locally.
Build arguments
We leverage the environment variables for parameterization of the builds (e.g. to pass a build number or build type).
Here is the list of variables you can use to override defaults:
# Build type (influences which .env file gets used for feature flags)
export BUILD_TYPE="pr"
# Used for versionCode and CFBundleVersion in Android and iOS respectively
export BUILD_NUMBER=9999
# Gradle options passed for Android builds
export ANDROID_GRADLE_OPTS=""
# If APKs should be split based on architectures
export ANDROID_ABI_SPLIT=false
# Android architectures to build for
export ANDROID_ABI_INCLUDE="x86"
# Local source override, see below
export STATUS_GO_SRC_OVERRIDE="$HOME/my/source/status-go"
export STATUS_GO_IPFS_GATEWAY_URL="https://ipfs.status.im/"
You can see the defaults in code:
Shell
In order to access an interactive Nix shell a user should run make shell
.
The Nix shell is started in this repo via the nix/scripts/shell.sh
script, which is a wrapper around the nix-shell
command and is intended for use with our main Makefile
. This allows for an implicit use of nix-shell
as the default shell in the Makefile
.
Normally the shell starts without any specific target platform, if you want to change that you should export the TARGET
env variable with appropriate value:
make shell TARGET=android
This way your shell and all other nix commands should run in a setup that is tailored towards Android development.
For valid values you can check the nix/shells.nix
file.
⚠️ WARNING: To have Nix pick up all changes a new nix-shell
needs to be spawned.
Using a local status-go repository
If you need to use a locally checked-out status-go repository, you can achieve that by defining the STATUS_GO_SRC_OVERRIDE
environment variable:
export STATUS_GO_SRC_OVERRIDE=$GOPATH/src/github.com/status-im/status-go
make release-android
Resources
You can learn more about Nix by watching these presentations:
- Nix Fundamentals (PDF, src)
- Nix in Status (PDF, src)
And you can read nix/DETAILS.md
for more information.
Known Issues
See KNOWN_ISSUES.md
.