From e41e78e88a5ee8ce07c5f8e23d13a6a3e8f7d6de Mon Sep 17 00:00:00 2001 From: tboba Date: Thu, 21 Sep 2023 15:41:09 +0200 Subject: [PATCH] Fix buggy Events e2e test on Android --- Example/e2e/jest.setup.ts | 6 +++++- Example/package.json | 3 ++- Example/src/shared/Toast.tsx | 16 ++++++++++++---- Example/yarn.lock | 5 +++++ 4 files changed, 24 insertions(+), 6 deletions(-) diff --git a/Example/e2e/jest.setup.ts b/Example/e2e/jest.setup.ts index b7d849b9b1..1ef3e16d95 100644 --- a/Example/e2e/jest.setup.ts +++ b/Example/e2e/jest.setup.ts @@ -1,7 +1,11 @@ import { device } from 'detox'; beforeAll(async () => { - await device.launchApp(); + await device.launchApp({ + launchArgs: { + isDetox: true, + }, + }); }); afterAll(async () => { diff --git a/Example/package.json b/Example/package.json index 354897baa3..5fde3eed81 100644 --- a/Example/package.json +++ b/Example/package.json @@ -24,6 +24,7 @@ "react": "18.2.0", "react-native": "0.72.4", "react-native-gesture-handler": "^2.12.1", + "react-native-launch-arguments": "^4.0.1", "react-native-restart": "^0.0.27", "react-native-safe-area-context": "^4.7.1", "react-native-screens": "link:../", @@ -36,9 +37,9 @@ "@react-native/eslint-config": "^0.72.2", "@react-native/metro-config": "^0.72.11", "@tsconfig/react-native": "^3.0.0", + "@types/jest": "^29.2.5", "@types/react": "^18.0.24", "@types/react-native": "0.72.2", - "@types/jest": "^29.2.5", "@types/react-native-restart": "^0.0.0", "@types/react-test-renderer": "^18.0.0", "babel-jest": "^29.3.1", diff --git a/Example/src/shared/Toast.tsx b/Example/src/shared/Toast.tsx index b025bea038..982586b8ad 100644 --- a/Example/src/shared/Toast.tsx +++ b/Example/src/shared/Toast.tsx @@ -8,6 +8,7 @@ import { ViewStyle, } from 'react-native'; import { nanoid } from 'nanoid/non-secure'; +import { LaunchArguments } from 'react-native-launch-arguments'; interface ToastProps { index: number; @@ -28,11 +29,18 @@ const Toast = ({ style = {}, remove, }: ToastProps): JSX.Element => { + const launchArgs = LaunchArguments?.value(); + useEffect(() => { - const timer = setTimeout(() => { - remove(id); - }, DISAPPEAR_AFTER); - return () => clearTimeout(timer); + // Unfortunately, sometimes Detox tests are failing because the specific toast + // has been removed too suddenly. On detox tests, we're disabling + // removing the toasts. + if (!launchArgs.isDetox) { + const timer = setTimeout(() => { + remove(id); + }, DISAPPEAR_AFTER); + return () => clearTimeout(timer); + } }, []); return ( diff --git a/Example/yarn.lock b/Example/yarn.lock index e003a4fccc..cffe4b6706 100644 --- a/Example/yarn.lock +++ b/Example/yarn.lock @@ -6705,6 +6705,11 @@ react-native-iphone-x-helper@^1.3.0: resolved "https://registry.yarnpkg.com/react-native-iphone-x-helper/-/react-native-iphone-x-helper-1.3.1.tgz#20c603e9a0e765fd6f97396638bdeb0e5a60b010" integrity sha512-HOf0jzRnq2/aFUcdCJ9w9JGzN3gdEg0zFE4FyYlp4jtidqU03D5X7ZegGKfT1EWteR0gPBGp9ye5T5FvSWi9Yg== +react-native-launch-arguments@^4.0.1: + version "4.0.1" + resolved "https://registry.yarnpkg.com/react-native-launch-arguments/-/react-native-launch-arguments-4.0.1.tgz#6d83c05c8de948db5eed8e75fbf76c28431b0c2d" + integrity sha512-sP2Vd+IEtApGiSDboyx8Dqnjj6IlPRA/M8KEoip4r5gidOvGcF/JGVJh9kIlgAchXheH7SWXvtmgvP0dJopikg== + react-native-restart@^0.0.27: version "0.0.27" resolved "https://registry.yarnpkg.com/react-native-restart/-/react-native-restart-0.0.27.tgz#43aa8210312c9dfa5ec7bd4b2f35238ad7972b19"