Detox Testing a React Native (Expo) + PouchDB App - react-native

We are currently working on a React Native app using Expo and are trying to get Detox (E2E Testing) working in our environment. We have spent a lot of time pinpointing where the issue is. The most likely contender seems to be that pouchDB is set up to be live syncing with our database:
LocalDB.sync(RemoteDB, {live: true, retry: true})
.on('change', onChange)
and because of this, detox is waiting for certain network requests to finish that we really don't want detox to wait for:
Sync App State: Waiting for network requests to finish.:
Our tests are running fine without syncing. In our detox tests we've tried blocking that url in our beforeAll & beforeEach blocks with the following:
await device.setURLBlacklist(['.*(OUR_IP_THAT_COUCH_IS_SYNCING_WITH).*'])
But this on top of the fact that detox doesn't officially support Expo, requiring multiple restarts to open the app, makes it hard to debug.
If anyone has any ideas about this, any help is greatly appreciated!

Related

My react native app with expo takes a long time to load

I developed an application in react native using expo and I have a problem, the app takes a long time on the splash screen before starting, I didn't use any method to make the splash visible for a longer time. The issue occurs in both the development version and the production version.
Another point is that I read in an article that IIFE functions should be avoided inside useEffect, and so I removed the ones I used but I still have the performance problem, does anyone have any ideas on how to improve?
If the connection is made but bundle building is very slow - Try disconnecting from the network both devices, and reconnect your system . Also, don't forget to clear the 'recently in development' projects, terminals and start the project again. It will increase the speed of building , especially for windows it works very well.

Are unit tests only manually executed or auto executed when building out a project?

I have a few questions when it comes to unit testing using Jest in React Native.
I run my tests now with npm test, is this the only way to run it or are the tests also being executed when building out the project? If so, can I disable auto testing?
If a test fails, will that prevent the app from building or executing?
Is there any difference in behaviour if a test fails or succeeds on iOS and Android?
Example
Below code just tests if AsyncStorage works as expected. If the following test fails - sure AsyncStorage will not work if I am using it within the app, but will it prevent the app from being used entirely?
beforeEach(() => {
AsyncStorage.clear();
});
it('Test - Read AsyncStorage', async () => {
await AsyncStorage.setItem('username', 'testUser')
let usernameValue = await AsyncStorage.getItem('username')
expect(usernameValue).toBe('testUser')
});
I am happy to get any further tips - I just can't find specific answers to the above so thanks in advance, and I haven't really been doing much unit testing so quite new to this.
Your tests are not executed when you build your project. If you are using a CICD platform, it may run npm commands to build your project and then run the tests after the build has successfully completed. However you may need to configure this yourself as building and testing are done exclusively by default.
A failing test will not prevent your app from building and executing. It is just an indication that some logic may not behave the way you want it. If you are using a CICD platform and your tests fail, typically jestjs emits an error code of 1 upon encountering a failure which will then cause your pipeline to fail.
The whole point of react-native is to be platform agnostic - as much as possible. So a failing jestjs test will have the same effect for all of the platforms.

Is there any way to keep state between restarting detox

i have the authorization in the app and i need to check the screens after sign in. Is there any way to do it?
Every detox runs, it will reinstall the app. So if you want to continue testing the app without reinstall every runs, you can add --reuse flag on detox command. It will reuse installed app on your test device/simulator. You can read more about this on Detox documentation here.

Detox Hung on Splash Screen for React Native App

Trying to set up Detox for my react native app. It seems to hang on the splash screen. I've managed to run tests on a seperate app with no splash screen. On the splash screen app it simply hangs and it outputs :
detox[34248] ERROR: Error: Exceeded timeout of 30000ms while handling jest-circus "setup" event
detox[34248] INFO: Scratch Test is assigned to undefined
I recognize that a showing of 'undefined' is incorrect.
I see reference for the 'waitFor' function but the links to the documentation all seem to be broken and I can't find a reference to it in the docs.
I'm trying to understand how to go about debugging this or if the splash screen is at all responsible for the hanging / error.
Do you use the "react-native-splash-screen" library? That apparently has some issue working with Detox and once I removed that, I did not have the timeout error.
Another potential source of the hanging is an animation that runs in the background. Detox tries to synchronize correctly, but isn't always able to, per their docs: https://github.com/wix/Detox/blob/master/docs/Troubleshooting.Synchronization.md.
I found that by adding
// to allow for less flaky detox tests
console.disableYellowBox = true;
to my app.tsx I was able to remove some warnings that were interfering with Detox.

How can I test latency or networking failures with Detox, can I simulate this with code?

I'm trying to do a e2e test when there is no network connection. Is this possible with Detox even if it's simulated, if so, how?
I'm running e2e testing on my react native app for some libraries written in native code, the API calls are on the native library I just need to expect a networking error window to appear from the library.
I was thinking I could emulate latency somehow but I haven't managed to do it so far.