status-react/scripts
Icaro Motta 0b4a1545ae
Fix component tests, upgrade Jest & friends, and a few other goodies (#18276)
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.
2023-12-26 11:58:23 -03:00
..
hooks hooks: fix newline injection on MacOS 2022-09-05 14:57:25 +02:00
lint Fix component tests, upgrade Jest & friends, and a few other goodies (#18276) 2023-12-26 11:58:23 -03:00
version ci: use full timestamp for iOS CFBundleVersion 2020-01-23 19:42:19 +01:00
adb_devices_abis.sh run-android: set build abis depending on connected devices abis 2023-08-31 13:01:24 +02:00
build-android.sh nix: switch status-im config to env vars, cleanup 2023-08-07 14:50:36 +02:00
check-metro-shadow-process.sh improve make component-test robustness (#17743) 2023-10-26 23:24:23 +05:30
check-nix-shell.sh fix shebang for NixOS usage in scheck-nix-shell.sh 2023-10-18 22:17:25 +02:00
colors.sh fdroid: add script that automates submissions 2021-10-13 12:13:38 +02:00
cut-release.sh Make cut release executable 2021-04-20 11:07:48 +02:00
diawi-upload.mjs ios: replace Diawi Fastlane plugin that disappered 2023-05-24 10:55:38 +02:00
encrypt-keychain.sh Add code-signing scripts and encrypted keychain 2018-09-11 12:10:33 +03:00
fdroid-pr.sh scripts/fdroid-pr.sh: fix version name log message 2022-09-29 12:54:48 +02:00
gen-random-passphrase.sh Add code-signing scripts and encrypted keychain 2018-09-11 12:10:33 +03:00
generate-keystore.sh generate-keystore: fix Permission denied error 2022-08-10 02:21:13 +02:00
inotify_fix.sh cleanup of shell scripts 2020-02-24 19:31:55 +01:00
list-pull-requests.sh rename status-react to status-mobile 2022-07-17 14:46:16 +02:00
merge-pr.sh rename status-react to status-mobile 2022-07-17 14:46:16 +02:00
pr-statistics.sh rename status-react to status-mobile 2022-07-17 14:46:16 +02:00
sign-android.sh nix: quote path uses to avoid issues with spaces 2022-07-27 16:11:28 +02:00
start-react-native.sh upgrade react-native to 0.72.5 (#17241) 2023-12-11 21:22:23 +05:30
update-status-go.sh scripts: disable pipefail when greping for SHA 2023-06-24 15:55:58 +02:00
wait-for.sh narrow match with UID, print persistent matching processes 2019-11-30 14:47:06 +01:00