How is detox code inserted into the app bundle - react-native

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.

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 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

In react-native, run minified code with debugging

I have an odd issue where I get the desired behavior when running a dev build but not a release one. I want to debug the code, but as far as I know I can't do that when running --configuration Release. I want to check if the issue has to do with minifying the js or something else. Is there a way to run
react-native run-ios --minify
or something? (The above command doesn't work. error: unknown option '--minify')
I've seen that you can run react-native bundle --minify, but I don't know how to then get the bundle onto the iOS Simulator, nor if bundle is the correct way to do things in React Native v0.42, as all the bundle solutions I've seen online have been v0.15ish.

Automate Xcode Simulator: how to build and launch an app from terminal

Is there a way to build an application for the iPhone, and have it running in the simulator, but using just the console?
I am trying to test an app, that will launch; send some data and then quit; if I run it via Xcode, it works fine; the simulator launch and everything is good.
But using xcodebuild; the app build but won't launch the simulator.
Is there any command or flag to do what Xcode IDE does, but using xcodebuild?
I have found an undocumented flag for the simulator, which is called "SimulateApplication", but sadly the usage is not documented; which makes it a bit hard to use.
Tried with ios-sim but my project won't work with it.
One way is to use instruments. In a way, you'll run it under "UI automation", but you don't actually automate the UI at all. The steps are:
Compile the app:
xcodebuild -sdk iphonesimulator7.1
Create a dummy UI automation script that does nothing (myscript.js):
while(true) {
UIATarget.localTarget().delay(100);
}
Then run the app via instruments:
instruments -t /Applications/Xcode.app/Contents/Applications/Instruments.app/Contents/PlugIns/AutomationInstrument.bundle/Contents/Resources/Automation.tracetemplate "$(pwd)/$(find . -name '*.app' | grep iphonesimulator)" -e UIASCRIPT myscript.js
(The find | grep monster there just translates to the full path of the compiled version of the app. You are of course free to type it manually as well if you so prefer.)