Detox
Detox copied to clipboard
Local assets not loading and network requests fail on debug mode for iOS
What happened?
When I run e2e tests for iOS in debug mode with the detox test command, network requests are always failing and assets are not loading. As soon as I launch the app manually all network requests including assets will successfully load. It seems that running detox server is causing this issue, or maybe it's just my misconfiguration:
23:43:56.773 detox[81799] DEBUG: [EXEC_CMD, #9] SIMCTL_CHILD_GULGeneratedClassDisposeDisabled=YES SIMCTL_CHILD_DYLD_INSERT_LIBRARIES="/Users/matin/Library/Detox/ios/7d2282ec703c8a8f3b1d5ac65c2487fb18b82874/Detox.framework/Detox" /usr/bin/xcrun simctl launch A02E0117-2351-4BD1-BCCF-3B7E45FF89B6 com.dietdoctor.EatApp --args -detoxServer ws://localhost:52894 -detoxSessionId 51acd3ff-e0b6-95e0-8695-4fe74c0a66e4 -detoxDisableHierarchyDump YES
What was the expected behaviour?
Assets should work and network requests should be made.
Was it tested on latest Detox?
- [X] I have tested this issue on the latest Detox release and it still reproduces.
Did your test throw out a timeout?
- [ ] I have followed the instructions under Identifying which synchronization mechanism causes us to wait too much.
Help us reproduce this issue!
- Build iOS app in debug mode
- Run metro
- Try running tests on debug mode
In what environment did this happen?
Detox version: 19.7.0 React Native version: 0.67.2 Node version: 16.15.0 Device model: iPhone Xs and iPhone 13 iOS version: 15.4 macOS version: 12.3 (21E230) Xcode version: 13.3 (13E113) Test-runner (select one): jest-circus
brew tap wix/brew
brew install applesimutils
Running `brew update --preinstall`...
==> Auto-updated Homebrew!
Updated 2 taps (homebrew/core and homebrew/cask).
==> New Formulae
dtrx
==> Updated Formulae
Updated 34 formulae.
==> Updated Casks
Updated 10 casks.
Warning: wix/brew/applesimutils 0.9.5 is already installed and up-to-date.
To reinstall 0.9.5, run:
brew reinstall applesimutils
Detox logs
Detox logs
23:42:49.337 detox[81628] INFO: [test.js] DETOX_CONFIGURATION="ios.sim.prod.debug" DETOX_LOGLEVEL="verbose" DETOX_REPORT_SPECS=true DETOX_START_TIMESTAMP=1653687769331 DETOX_USE_CUSTOM_LOGGER=true jest --config e2e/config.json --testNamePattern '^((?!:android:).)*$' --maxWorkers 1 e2e
watchman warning: Recrawled this watch 1 times, most recently because:
MustScanSubDirs UserDroppedTo resolve, please review the information on
https://facebook.github.io/watchman/docs/troubleshooting.html#recrawl
To clear this warning, run:
`watchman watch-del '/Users/matin/w/dietdoctor/rnapp' ; watchman watch-project '/Users/matin/w/dietdoctor/rnapp'`
23:42:51.823 detox[81629] DEBUG: [WSS_CREATE] Detox server listening on localhost:52429...
23:42:51.839 detox[81629] DEBUG: [WSS_CONNECTION, #52430] registered a new connection.
23:42:52.090 detox[81629] DEBUG: [EXEC_CMD, #0] applesimutils --list --byType "iPhone Xs"
23:42:52.307 detox[81629] DEBUG: [EXEC_CMD, #1] applesimutils --list --byId A02E0117-2351-4BD1-BCCF-3B7E45FF89B6 --maxResults 1
23:42:52.486 detox[81629] DEBUG: [EXEC_CMD, #2] /usr/bin/xcrun simctl terminate A02E0117-2351-4BD1-BCCF-3B7E45FF89B6 com.dietdoctor.EatApp
23:42:52.487 detox[81629] DEBUG: [EXEC_TRY, #2] Terminating com.dietdoctor.EatApp...
23:42:52.695 detox[81629] DEBUG: [EXEC_SUCCESS, #2] com.dietdoctor.EatApp terminated
23:42:52.698 detox[81629] DEBUG: [EXEC_CMD, #3] /usr/bin/xcrun simctl uninstall A02E0117-2351-4BD1-BCCF-3B7E45FF89B6 com.dietdoctor.EatApp
23:42:52.698 detox[81629] DEBUG: [EXEC_TRY, #3] Uninstalling com.dietdoctor.EatApp...
23:42:52.880 detox[81629] DEBUG: [EXEC_SUCCESS, #3] com.dietdoctor.EatApp uninstalled
23:42:52.881 detox[81629] DEBUG: [EXEC_CMD, #4] /usr/bin/xcrun simctl install A02E0117-2351-4BD1-BCCF-3B7E45FF89B6 "/Users/matin/Library/Developer/Xcode/DerivedData/DietDoctorRN-butynagublacmweexkbnmuykolnk/Build/Products/Debug-prod-iphonesimulator/DietDoctor.app"
23:42:52.881 detox[81629] DEBUG: [EXEC_TRY, #4] Installing /Users/matin/Library/Developer/Xcode/DerivedData/DietDoctorRN-butynagublacmweexkbnmuykolnk/Build/Products/Debug-prod-iphonesimulator/DietDoctor.app...
23:42:54.711 detox[81629] DEBUG: [EXEC_SUCCESS, #4] /Users/matin/Library/Developer/Xcode/DerivedData/DietDoctorRN-butynagublacmweexkbnmuykolnk/Build/Products/Debug-prod-iphonesimulator/DietDoctor.app installed
23:42:54.730 detox[81629] INFO: Free version auth is assigned to A02E0117-2351-4BD1-BCCF-3B7E45FF89B6 (iPhone Xs)
Device logs
More data, please!
Video attached here:
https://user-images.githubusercontent.com/24797481/170793805-239b14c7-ed46-456f-becd-9cf1853346ce.mp4
same
Any updates? I'm facing the exact same issue.
I am facing the same issue. I tried updating to the last detox version but the same.
Facing the same issue
I have been chasing around trying to figure out the cause of this bug, and, the research of the last two days implicates Detox (although I wish it wasn't so, because, then I could be in a position to implement a fix).
Here's how I reproduce the bug:
Build using detox with the following build command set in config
"build": "cd ../my-app/ios && xcodebuild -workspace MyApp.xcworkspace -scheme MySheme -configuration Debug -sdk iphonesimulator -destination 'platform=iOS Simulator,name=iPhone 13' clean build",
"binaryPath": "../my-app/ios/build/Build/Products/Debug-iphonesimulator/MyApp.app"
The build succeeds.
Then launch the test suite using Detox cli.
The test suite runs fine until it causes the app to do a network request. Where is fails with this error, and the reason for this error is unpicked below...
I relaunch the app, manually to try both requests to: a localhost cleartext mock server, and, a legit https API endpoint manually and they work fine, thus, we can rule out iOS ATS, or, certificate signing as the culprit.
The network request fails in a very strange way, with the help of some debugging using Charles proxy, I can see that the request has been made, but, the result always has an empty payload. That is to say, content in the network result is always empty, but, if I call the same endpoint with postman, it returns the result fine. Ergo, we can rule out the http(s) server as the culprit.
Some more detail about the network request being empty: I put some debugging in where the app calls fetch
and looked at what was being returned, at it looks something like this:
const result = await fetch(
`${process.env.REACT_APP_QUERY_API_URL}/app/myendpoint`,
{
headers:
accessToken !== undefined
? {
Authorization: `Bearer ${accessToken}`,
}
: undefined,
}
then used console.error to get the value of result
after the promise had resolved.
But when I call either await result.json()
or await result.text()
there is either a error because the JSON is empty, or, it returns an empty string. Irrespective of what is being claimed in the content-length
header.
If I then manually launch MyApp in the simulator, the network code works flawlessly, leading me to suspect there is something about the way that the app is launched from Detox that is introducing a change in the app that is preventing the network code from executing correctly in iOS. This also rules out something about the build being the culprit.
I'm very enthusiastic about getting to the bottom of this bug, because, it is (of course) a blocker. If there is any additional information I can provide, of steps I can take to facilitate resolving this issue, please, do not hesitate to ask.
Update, thanks to this comment: https://github.com/wix/Detox/issues/3341#issuecomment-1115846128
Changing the version of Flipper (defined in the Podfile) to 0.128.0
resolved the issue for me. It would seem that higher versions of flipperkit conflict with Detox in a way that I am happy not to understand for now.
Thanks for the report 👍🏼 Please try to upgrade your Detox version to 19.8.1 (latest version ATM), then you can upgrade your Flipper version to the latest.
It works, thanks a lot 🥳
Great @wass08! @matinzd can you please check if your issue is also resolved?
Great @wass08! @matinzd can you please check if your issue is also resolved?
I am going to try this today. I will close the issue if it is resolved.
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. If you believe the issue is still relevant, please test on the latest Detox and report back.
Thank you for your contributions!
For more information on bots in this reporsitory, read this discussion.
The issue has been closed for inactivity.