How to avoid multiple builds with AppCenter and Detox? - react-native

I have a question about integrating app center with Detox. Currently I have to run the following commands to build the app and then run the tests:
detox build --configuration ios.sim.release
detox test --configuration ios.sim.release --cleanup
This happens in the appcenter-pre-build.sh section. However this means that the app will be built twice, once by detox and then again by the AppCenter build process. Is there a way to stop the AppCenter process as soon as the detox tests pass? I'm thinking something along the lines of Clone -> Detox build -> run unit tests -> run detox tests -> finish.
I assume that if the detox build fails then the entire build would be invalid as it is so there is no reason to build again, right?

Related

Detox build command fails in Github jobs

Running build test for ios release locally is working fine, however it fails on Github actions enter image description here
It seems like your app build command (that you have provided in Detox config) is faulty and that is why your app is failing build. Unrelated to Detox.

Build command in detox

Looking at this doc: https://github.com/wix/Detox/blob/master/docs/APIRef.Configuration.md
It says that the
Build command (either xcodebuild, react-native run-ios, etc...), will
be later available through detox CLI tool.
I'm trying to setup the build command to work with Android. Am I supposed to add react-native run-android to the build command? What do they mean by Detox CLI tool?
The build field is optional, and should contain whichever execution logic needed in order to have the .apk file set and ready in the path specified in binaryPath. You are more than welcome to refer to the Detox example project, which was set up as a reference exactly for these type of questions.
In any case, from the react-native CLI tool's help: react-native run-android = builds your app and starts it on a connected Android emulator or device. That makes it not very suitable, as we typically want to build the app, and have detox launch the emulator (optional) and install the app on the device(s), as needed.

How is detox code inserted into the app bundle

I use detox to run e2e tests on react native.
This artcile written by one of the people working on detox says
Gray box essentially uses a piece of code that is planted in the app, it can help us see what’s going on inside.
My question is, how does that happen? Looking at the docs the command used for detox build is
xcodebuild -project ios/YourProject.xcodeproj -scheme YourProject -sdk iphonesimulator -derivedDataPath ios/build
No detox-specific mention to be seen there.
Also, the docs state here that the build command is optional and that
You can also choose not to use it and provide a compiled app by yourself.
Well, how do I do that? How do I inject detox / make sure detox is not injected into my app? If I download compiled app from my CI server it does not work with detox (not surprisingly since the detox code is not planted into the app). But if I use the detox build command (which seem to just run whatever the build command in the config specifies), the tests work. There seems to be some "magic" happening which is not understandable for a newcomer.
Thanks.
It's magic!
Well, actually it isn't. The build step is completely optional, and as stated in the documentation, Detox works with any valid app.
In order to load Detox, we tell the dynamic linker to load it using the DYLD_INSERT_LIBRARIES environment variable. So it only loads Detox when you run detox test from the command line.
This is easy on the simulator as it has access to your Mac's file system. Once we implement support for testing on actual hardware devices, we will still use that environment variable, but we will have to inject it inside your IPA file directly.

Generate build without launching simulator in React Native

I am using the following command to generate an iOS build in a CI environment:
react-native run-ios --configuration Release --no-packager
The problem is, this will launch the simulator. I am trying to avoid that as it is a CI machine. Is there a way to generate a build without launching the simulator?

How to run Expo test suite

I generated sample expo app, pull the latest https://github.com/expo/test-suite. I run test-suite in the simulator, it shows a spinner which never disappears.
Can you provide me an instruction how to run the tests?
I see some warnings as well while running test-suite.
Warning
Warning: Using unversioned Expo SDK. Do not publish until you set sdkVersion in exp.json
Warning
Warning: 'react' peer depencency missing. Run `npm ls` in /project/test-suite to see full warning.
If there is an issue running your project, please run `npm install` in /project/test-suite and restart.
Thanks
the repository that you linked is not a "test" suit as you understand it. It is not for testing your app. It exist for the developers of Expo as a tool, to test Expo before new releases of it.
Check out more about unit testing and test driven development;
https://en.wikipedia.org/wiki/Unit_testing
https://en.wikipedia.org/wiki/Development_testing
If your goal is to test your own app in you will need a simulator or a development device;
https://docs.expo.io/versions/v18.0.0/guides/up-and-running.html