Skip to content

Commit

Permalink
Fix buggy Events e2e test on Android
Browse files Browse the repository at this point in the history
  • Loading branch information
tboba committed Sep 21, 2023
1 parent 53c1c92 commit e41e78e
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 6 deletions.
6 changes: 5 additions & 1 deletion Example/e2e/jest.setup.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
import { device } from 'detox';

beforeAll(async () => {
await device.launchApp();
await device.launchApp({
launchArgs: {
isDetox: true,
},
});
});

afterAll(async () => {
Expand Down
3 changes: 2 additions & 1 deletion Example/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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:../",
Expand All @@ -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",
Expand Down
16 changes: 12 additions & 4 deletions Example/src/shared/Toast.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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 (
Expand Down
5 changes: 5 additions & 0 deletions Example/yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down

0 comments on commit e41e78e

Please sign in to comment.