Detox: Tests hanging on before_all hook

When I run detox test --configuration ios.sim.release --loglevel verbose --cleanup, the app is successfully installed and launched, but it won’t proceed to run my test cases because it’s stuck on the before() function in init.js. I tried running the sample project but I couldn’t reproduce the issue 😕 any ideas?

...
detox info 5: Launching com.myapp.myapp... 
detox info 5: com.myapp.myapp launched 
detox verb ws send: {"type":"isReady","params":{},"messageId":1}
  1) "before all" hook
  0 passing (2m)
  1 failing
  1)  "before all" hook:
     Error: Timeout of 120000ms exceeded. For async tests and hooks, ensure "done()" is called; if returning a Promise, ensure it resolves.

init.js:

require('babel-polyfill');
const detox = require('detox');
const config = require('../package.json').detox;

before(async () => {
  await detox.init(config); // it hangs here :(
});

after(async () => {
  await detox.cleanup();
});

configuration in package.json:

  "detox": {
    "specs": "e2e",
    "configurations": {
      "ios.sim.release": {
        "binaryPath": "ios/build/Build/Products/Release-iphonesimulator/myapp.app",
        "build": "export RCT_NO_LAUNCH_PACKAGER=true && xcodebuild -project ios/myapp.xcodeproj -scheme myapp -configuration Release -sdk iphonesimulator -derivedDataPath ios/build",
        "type": "ios.simulator",
        "name": "iPhone 5"
      },
      "ios.sim.debug": {
        "binaryPath": "ios/build/Build/Products/Debug-iphonesimulator/myapp.app",
        "build": "xcodebuild -project ios/myapp.xcodeproj -scheme myapp -configuration Debug -sdk iphonesimulator -derivedDataPath ios/build",
        "type": "ios.simulator",
        "name": "iPhone 5"
      }
    }
  }

About this issue

  • Original URL
  • State: closed
  • Created 7 years ago
  • Reactions: 5
  • Comments: 71 (20 by maintainers)

Most upvoted comments

An update on @timsawtell-sportsbet’s issue: we are running Detox in a hybrid React Native / Native app. Since no React Native components render on the home screen of our app, the RCTContentDidAppearNotification notification is never fired by React Native. As a result, Detox gets stuck waiting for React Native to “load”.

There’s a fundamental assumption in Detox that if your app has React Native symbols linked into it, then it will be a purely React Native app and you’re guaranteed to have RCTContentDidAppearNotification fire pretty soon after the app launches, which isn’t necessarily the case in a hybrid app that only uses React Native for a subsection of user journeys.

The solution in our case was simple, we manually fire an RCTContentDidAppearNotification after we’ve finished downloading our jsbundle:

[NSNotificationCenter.defaultCenter postNotificationName: @"RCTContentDidAppearNotification" object: nil];

Hello guys, I work with @vspedr and today I built detox (5.2.0) from scratch in our project and unfortunately the error persists. I used node 7.6.0, 7.8.0 and 8.1.3 with xcode 8.3.3 (Simulators: iPhone 5, iPhone 7, iPhone 7 Plus) using react-native 0.44.2.

@vspedr nope, no CodePush

Hey, I’m having the same issue.

Version:

Node: 7.10.0
Detox: 5.7.0 (and 5.6.0)
Release: Debug and Release

My config in package.json:

"detox": {
    "specs": "e2e",
    "configurations": {
      "ios.sim.debug": {
        "binaryPath": "ios/build/Build/Products/Debug-iphonesimulator/HaulerMobile.app",
        "build": "xcodebuild -project ios/HaulerMobile.xcodeproj -scheme HaulerMobile -configuration Debug -sdk iphonesimulator -derivedDataPath ios/build",
        "type": "ios.simulator",
        "name": "iPhone 7"
      }
    }
  },

I run detox test after building with react-native run-ios. It starts to run, and the app immediately crashes.

For me, it also hangs in init.js

before(async () => {
  console.log('before');
  await detox.init(config); // HERE
  console.log('after');
});

And the result in the terminal:

$ detox test --loglevel verbose
node_modules/.bin/mocha e2e --opts e2e/mocha.opts  --loglevel verbose


before
detox info 13:32:23: server listening on localhost:51955...
detox verb ws onOpen [object Object]
detox verb ws send: {"type":"login","params":{"sessionId":"46f28899-07f2-c244-f894-28a85435648a","role":"tester"},"messageId":0}
detox verb ws onMessage: {"type":"loginSuccess","params":{"sessionId":"46f28899-07f2-c244-f894-28a85435648a","role":"tester"},"messageId":0}
detox verb ws
detox verb 1: fbsimctl --json "iPhone 7" --first 1 --simulators list
detox info 1: Listing devices...
detox verb 2: fbsimctl --json F0C11864-91E1-4323-AD01-BF9867279CEB list
detox info Device F0C11864-91E1-4323-AD01-BF9867279CEB is already booted
detox verb 3: fbsimctl --json F0C11864-91E1-4323-AD01-BF9867279CEB uninstall org.reactjs.native.example.HaulerMobile
detox info 3: Uninstalling org.reactjs.native.example.HaulerMobile...
detox info 3: org.reactjs.native.example.HaulerMobile uninstalled
detox verb 4: fbsimctl --json F0C11864-91E1-4323-AD01-BF9867279CEB install /Users/jaredramirez/dev/src/github.com/replenysh/Hauler-Mobile/ios/build/Build/Products/Debug-iphonesimulator/HaulerMobile.app
detox info 4: Installing /Users/jaredramirez/dev/src/github.com/replenysh/Hauler-Mobile/ios/build/Build/Products/Debug-iphonesimulator/HaulerMobile.app...
detox info 4: /Users/jaredramirez/dev/src/github.com/replenysh/Hauler-Mobile/ios/build/Build/Products/Debug-iphonesimulator/HaulerMobile.app installed
detox verb 5: /usr/bin/xcrun simctl terminate F0C11864-91E1-4323-AD01-BF9867279CEB org.reactjs.native.example.HaulerMobile
detox info 5: Terminating org.reactjs.native.example.HaulerMobile...
detox info 5: org.reactjs.native.example.HaulerMobile terminated
detox verb 6: /bin/cat /dev/null >$HOME/Library/Developer/CoreSimulator/Devices/F0C11864-91E1-4323-AD01-BF9867279CEB/data/tmp/detox.last_launch_app_log.out 2>$HOME/Library/Developer/CoreSimulator/Devices/F0C11864-91E1-4323-AD01-BF9867279CEB/data/tmp/detox.last_launch_app_log.err && SIMCTL_CHILD_DYLD_INSERT_LIBRARIES="/Users/jaredramirez/dev/src/github.com/replenysh/Hauler-Mobile/node_modules/detox/Detox.framework/Detox" /usr/bin/xcrun simctl launch --stdout=/tmp/detox.last_launch_app_log.out --stderr=/tmp/detox.last_launch_app_log.err F0C11864-91E1-4323-AD01-BF9867279CEB org.reactjs.native.example.HaulerMobile --args -detoxServer ws://localhost:51955 -detoxSessionId 46f28899-07f2-c244-f894-28a85435648a
detox info 6: Launching org.reactjs.native.example.HaulerMobile...
detox info 6: org.reactjs.native.example.HaulerMobile launched. The stdout and stderr logs were recreated, you can watch them with:
        tail -F $HOME/Library/Developer/CoreSimulator/Devices/F0C11864-91E1-4323-AD01-BF9867279CEB/data/tmp/detox.last_launch_app_log.{out,err}
detox verb ws send: {"type":"isReady","params":{},"messageId":-1000}
  1) "before all" hook

  0 passing (2m)
  1 failing

  1)  "before all" hook:
     Error: Timeout of 120000ms exceeded. For async tests and hooks, ensure "done()" is called; if returning a Promise, ensure it resolves.




child_process.js:524
    throw err;
    ^

Error: Command failed: node_modules/.bin/mocha e2e --opts e2e/mocha.opts  --loglevel verbose
    at checkExecSyncError (child_process.js:481:13)
    at Object.execSync (child_process.js:521:13)
    at Object.<anonymous> (/Users/jaredramirez/dev/src/github.com/replenysh/Hauler-Mobile/node_modules/detox/local-cli/detox-test.js:46:4)
    at Module._compile (module.js:571:32)
    at Object.Module._extensions..js (module.js:580:10)
    at Module.load (module.js:488:32)
    at tryModuleLoad (module.js:447:12)
    at Function.Module._load (module.js:439:3)
    at Module.runMain (module.js:605:10)
    at run (bootstrap_node.js:427:7)

The output from my system log is

Sep 21 13:32:23 jared-macbook CoreSimulatorBridge[32672]: Pasteboard change listener callback port <NSMachPort: 0x7faae9726400> registered
Sep 21 13:32:24 jared-macbook CoreSimulatorBridge[32672]: Pasteboard change listener callback port <NSMachPort: 0x7faae941bea0> registered
Sep 21 13:32:24 jared-macbook CoreSimulatorBridge[32672]: Pasteboard change listener callback port <NSMachPort: 0x7faae9725c20> registered
Sep 21 13:32:24 jared-macbook installd[32661]: 0x700006ae2000 -[MIClientConnection uninstallIdentifiers:withOptions:completion:]: Uninstall requested by lsd (pid 32681) for identifier org.reactjs.native.example.HaulerMobile with options: {
	    SimulatorRootPath = "/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator.sdk";
	    SimulatorUserPath = "/Users/jaredramirez/Library/Developer/CoreSimulator/Devices/F0C11864-91E1-4323-AD01-BF9867279CEB/data";
	}
Sep 21 13:32:24 jared-macbook diagnosticd[32678]: unsupported XPC object: OS_xpc_dictionary
Sep 21 13:32:24 jared-macbook installd[32661]: 0x700006ae2000 -[MIUninstaller _uninstallBundleWithIdentifier:error:]: Uninstalling identifier org.reactjs.native.example.HaulerMobile
Sep 21 13:32:24 jared-macbook installd[32661]: 0x700006ae2000 -[MIKeychainAccessGroupTracker _onQueue_removeReferencesForBundle:error:]: Removing reference in org.reactjs.native.example.HaulerMobile for Q233EUCZ3X.org.reactjs.native.example.HaulerMobile
Sep 21 13:32:24 jared-macbook installd[32661]: 0x700006ae2000 -[MIKeychainAccessGroupTracker _removeGroupsWithError:error:]: Removing keychain access groups: (
	    "Q233EUCZ3X.org.reactjs.native.example.HaulerMobile"
	)
Sep 21 13:32:24 jared-macbook installd[32661]: 0x700006ae2000 -[MIUninstallNotifier performRemovalWithCompletionBlock:]: Destroying container with identifier org.reactjs.native.example.HaulerMobile at /Users/jaredramirez/Library/Developer/CoreSimulator/Devices/F0C11864-91E1-4323-AD01-BF9867279CEB/data/Containers/Bundle/Application/3DF0A425-9BF4-4AA9-8D05-FB9672FE5742
Sep 21 13:32:24 jared-macbook installd[32661]: 0x700006ae2000 -[MIUninstallNotifier performRemovalWithCompletionBlock:]: Destroying container with identifier org.reactjs.native.example.HaulerMobile at /Users/jaredramirez/Library/Developer/CoreSimulator/Devices/F0C11864-91E1-4323-AD01-BF9867279CEB/data/Containers/Data/Application/ACC0FE31-6D6F-4946-850C-843CD6D00E10
Sep 21 13:32:24 jared-macbook diagnosticd[32678]: unsupported XPC object: OS_xpc_dictionary
Sep 21 13:32:24 --- last message repeated 3 times ---
Sep 21 13:32:24 jared-macbook SpringBoard[32666]: [Common] could not find icon for representation -> org.reactjs.native.example.HaulerMobile
Sep 21 13:32:24 jared-macbook apsd[32693]: 2017-09-21 13:32:24 -0500 apsd[32693]: SecItemDelete() failed: -25300 - setTokenForDomain
Sep 21 13:32:24 jared-macbook diagnosticd[32678]: unsupported XPC object: OS_xpc_dictionary
Sep 21 13:32:24 jared-macbook apsd[32693]: 2017-09-21 13:32:24 -0500 apsd[32693]: SecItemDelete() failed: -25300 - setTokenForDomain
Sep 21 13:32:24 jared-macbook diagnosticd[32678]: unsupported XPC object: OS_xpc_dictionary
Sep 21 13:32:24 --- last message repeated 1 time ---
Sep 21 13:32:24 jared-macbook videosubscriptionsd[33167]: Entering main() for videosubscriptionsd.
Sep 21 13:32:24 jared-macbook diagnosticd[32678]: unsupported XPC object: OS_xpc_dictionary
Sep 21 13:32:24 jared-macbook videosubscriptionsd[33167]: Unable to find framework using path: /System/Library/Frameworks/VideoSubscriberAccount.framework
Sep 21 13:32:24 jared-macbook com.apple.CoreSimulator.SimDevice.F0C11864-91E1-4323-AD01-BF9867279CEB.launchd_sim[32648] (com.apple.videosubscriptionsd[33167]): Service exited with abnormal code: 1
Sep 21 13:32:24 jared-macbook diagnosticd[32678]: unsupported XPC object: OS_xpc_dictionary
Sep 21 13:32:24 jared-macbook CoreSimulatorBridge[32672]: Pasteboard change listener callback port <NSMachPort: 0x7faae941e870> registered
Sep 21 13:32:25 jared-macbook CoreSimulatorBridge[32672]: Requesting installation of file:///Users/jaredramirez/dev/src/github.com/replenysh/Hauler-Mobile/ios/build/Build/Products/Debug-iphonesimulator/HaulerMobile.app/ with options: {
	    CFBundleIdentifier = "org.reactjs.native.example.HaulerMobile";
	    PackageType = Developer;
	    SimulatorRootPath = "/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator.sdk";
	    SimulatorUserPath = "/Users/jaredramirez/Library/Developer/CoreSimulator/Devices/F0C11864-91E1-4323-AD01-BF9867279CEB/data";
	}
Sep 21 13:32:25 jared-macbook installd[32661]: 0x700006b65000 -[MIClientConnection _doInstallationForURL:withOptions:completion:]: Install of "/Users/jaredramirez/dev/src/github.com/replenysh/Hauler-Mobile/ios/build/Build/Products/Debug-iphonesimulator/HaulerMobile.app" type Developer (LSInstallType = (null)) requested by lsd (pid 32681)
Sep 21 13:32:25 jared-macbook installd[32661]: 0x700006b65000 -[MIInstaller _extractPackageWithError:]: Did not construct delta; doing full copy for installation.
Sep 21 13:32:25 jared-macbook installd[32661]: 0x700006b65000 -[MIInstaller performInstallationWithError:]: Installing <MIInstallableBundle ID=org.reactjs.native.example.HaulerMobile; Version=1, ShortVersion=1.0>
Sep 21 13:32:25 jared-macbook installd[32661]: 0x700006b65000 -[MIContainer makeContainerLiveReplacingContainer:reason:withError:]: Made container live for org.reactjs.native.example.HaulerMobile at /Users/jaredramirez/Library/Developer/CoreSimulator/Devices/F0C11864-91E1-4323-AD01-BF9867279CEB/data/Containers/Data/Application/642363F7-6520-4FA7-A580-5C1F3EF4BB11
Sep 21 13:32:25 jared-macbook installd[32661]: 0x700006b65000 -[MIContainer makeContainerLiveReplacingContainer:reason:withError:]: Made container live for org.reactjs.native.example.HaulerMobile at /Users/jaredramirez/Library/Developer/CoreSimulator/Devices/F0C11864-91E1-4323-AD01-BF9867279CEB/data/Containers/Bundle/Application/A15460D7-5152-460F-A41B-D25C2E92713A
Sep 21 13:32:25 jared-macbook installd[32661]: 0x700006b65000 -[MIInstaller performInstallationWithError:]: Install Successful; Staging: 0.11s; Waiting: 0.00s; Preflight/Patch: 0.00s, Verifying: 0.01s; Overall: 0.15s
Sep 21 13:32:25 jared-macbook com.apple.CoreSimulator.SimDevice.F0C11864-91E1-4323-AD01-BF9867279CEB.launchd_sim[32648] (com.apple.videosubscriptionsd): Service only ran for 1 seconds. Pushing respawn out by 9 seconds.
Sep 21 13:32:30 jared-macbook CoreSimulatorBridge[32672]: Pasteboard change listener callback port <NSMachPort: 0x7faae9607c10> registered
Sep 21 13:32:30 jared-macbook CoreSimulatorBridge[32672]: Pasteboard change listener callback port <NSMachPort: 0x7faae9417b90> registered
Sep 21 13:32:30 jared-macbook CoreSimulatorBridge[32672]: Requesting launch of org.reactjs.native.example.HaulerMobile with options: {
	    arguments =     (
	        "--args",
	        "-detoxServer",
	        "ws://localhost:51955",
	        "-detoxSessionId",
	        "46f28899-07f2-c244-f894-28a85435648a"
	    );
	    environment =     {
	        "DYLD_INSERT_LIBRARIES" = "/Users/jaredramirez/dev/src/github.com/replenysh/Hauler-Mobile/node_modules/detox/Detox.framework/Detox";
	    };
	    stderr = "/tmp/detox.last_launch_app_log.err";
	    stdout = "/tmp/detox.last_launch_app_log.out";
	}
Sep 21 13:32:30 jared-macbook CoreSimulatorBridge[32672]: Beginning launch sequence for bundle 'org.reactjs.native.example.HaulerMobile'
		retryTimeout: 120.000000 (default write com.apple.CoreSimulatorBridge LaunchRetryTimeout <value>)
		bootTimeout: 300.000000 (default write com.apple.CoreSimulatorBridge BootRetryTimeout <value>)
		bootLeeway: 120.000000 (default write com.apple.CoreSimulatorBridge BootLeeway <value>)
		Note: Use 'xcrun simctl spawn booted defaults write <domain> <key> <value>' to modify defaults in the booted Simulator device.
	Simulator booted at: 2017-09-21 18:00:11 +0000
	Current time: 2017-09-21 18:32:30 +0000
	Within boot leeway: NO
Sep 21 13:32:30 jared-macbook CoreSimulatorBridge[32672]: Launch attempt #0 for bundle 'org.reactjs.native.example.HaulerMobile', have been trying to launch for 0 seconds. Modern launch services = YES
Sep 21 13:32:30 jared-macbook CoreSimulatorBridge[32672]: Got LSBundleProxy for 'org.reactjs.native.example.HaulerMobile', sequenceNumber 260, cacheGUID 071680E1-C239-43EF-A511-91F96955DD19
Sep 21 13:32:30 jared-macbook CoreSimulatorBridge[32672]: [Common] [FBSSystemService][0x9577] Sending request to open "org.reactjs.native.example.HaulerMobile"
Sep 21 13:32:30 jared-macbook assertiond[32671]: Submitted job with label: UIKitApplication:org.reactjs.native.example.HaulerMobile[0x62ec][32671]
Sep 21 13:32:30 jared-macbook SpringBoard[32666]: [org.reactjs.native.example.HaulerMobile] Bootstrap complete with label: UIKitApplication:org.reactjs.native.example.HaulerMobile[0x62ec][32671]
Sep 21 13:32:30 jared-macbook CoreSimulatorBridge[32672]: [Common] [FBSSystemService][0x9577] Request successful: <BSProcessHandle: 0x7faae9725330; HaulerMobile:33180; valid: YES>
Sep 21 13:32:30 jared-macbook CoreSimulatorBridge[32672]: Launch successful for 'org.reactjs.native.example.HaulerMobile'
Sep 21 13:32:30 jared-macbook HaulerMobile[33180]: Crash handler setup started.
Sep 21 13:32:30 jared-macbook HaulerMobile[33180]: Crash handler setup completed.
Sep 21 13:32:30 jared-macbook HaulerMobile[33180]: Enabling accessibility for automation on Simulator.
Sep 21 13:32:30 jared-macbook HaulerMobile[33180]: assertion failed: 16G29 14E8301: libxpc.dylib + 64131 [624BAF4F-2E03-34F8-ACBA-970B04637786]: 0x7d
Sep 21 13:32:31 jared-macbook HaulerMobile[33180]: Initializing <RCTCxxBridge: 0x6000001bb040> (parent: <RCTBridge: 0x6080000a2760>, executor: (null))
Sep 21 13:32:31 jared-macbook HaulerMobile[33180]: Class RCTCxxModule was not exported. Did you forget to use RCT_EXPORT_MODULE()?
Sep 21 13:32:31 jared-macbook SpringBoard[32666]: [KeyboardArbiter] HW kbd: Failed to set (null) as keyboard focus
Sep 21 13:32:31 jared-macbook com.apple.CoreSimulator.SimDevice.F0C11864-91E1-4323-AD01-BF9867279CEB.launchd_sim[32648] (UIKitApplication:org.reactjs.native.example.HaulerMobile[0x62ec][32671][33180]): Service exited due to Abort trap: 6
Sep 21 13:32:31 jared-macbook assertiond[32671]: Deleted job with label: UIKitApplication:org.reactjs.native.example.HaulerMobile[0x62ec][32671]
Sep 21 13:32:34 jared-macbook videosubscriptionsd[33182]: Entering main() for videosubscriptionsd.
Sep 21 13:32:34 jared-macbook videosubscriptionsd[33182]: Unable to find framework using path: /System/Library/Frameworks/VideoSubscriberAccount.framework
Sep 21 13:32:34 jared-macbook com.apple.CoreSimulator.SimDevice.F0C11864-91E1-4323-AD01-BF9867279CEB.launchd_sim[32648] (com.apple.videosubscriptionsd[33182]): Service exited with abnormal code: 1

It seems to me that the issue is at Class RCTCxxModule was not exported. Did you forget to use RCT_EXPORT_MODULE()? in the system log, but I’m not sure.

Anyone have any ideas?

@rotemmiz 8.2.1

I’ve checked out the repo and am currently taking a look. It gets stuck in ./detox/src/client/Client.js inside the sendAction fn on this line:

const response = await this.ws.send(action, messageId)

It never resolves. I’ve noticed the AsyncWebSocket has changed, and doesn’t resolve if there is no pendingPromise. Not sure if that might have something to do with it. Still trying to make sense of how Detox works

@fighterpoul @adamski Guys, why are you building with the ARCHS=i386 in the first place?

Detox is 64-bit only—only x86-64 and arm64 slices are provided. i386 is 32-bit architecture and I would like to understand why you are building in 32-bit only. This is not something you should do—standard architectures in Xcode normally include 32-bit and 64-bit.

Hi guys. I had exactly this same issue. I don’t remember why but I needed to build my app for tests with ARCHS=i386 flag. I had seen error log like this dyld: warning: could not load inserted library '/path/to/app/node_modules/detox/Detox.framework/Detox' because no suitable image found. Did find: /path/to/app/node_modules/detox/Detox.framework/Detox: no matching architecture in universal wrapper when I was running the build. I solved the issue by making sure that dependencies (fbsimctl etc.) are installed well by reinstalling them ( 😃 ) and by removing the flag. I was inspired by example demo application in examples folder. I hope it’ll help you all.

No CodePush here either. I’m using RN via CocoaPods, if that might make a difference?

On 20 Jul 2017, at 23:13, timsawtell-sportsbet notifications@github.com wrote:

@vspedr https://github.com/vspedr nope, no CodePush

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/wix/detox/issues/155#issuecomment-316845051, or mute the thread https://github.com/notifications/unsubscribe-auth/AAA6hP2xdttD_r2qvt9Y3F4qSzHSor5dks5sP9D4gaJpZM4Nyr1Q.

Yep, the device never connects to the websocket server. If you want , we can debug the device code and see why it doesn’t connect to the server. Here sre the basic steps of setting a debuggeble env with Xcode. https://github.com/wix/detox/blob/master/docs/Guide.DebuggingInXcode.md

I think Detox tries to throw an error inside mocha’s beforeAll hook , but for some reason mocha catches all errors thrown inside beforeAll. As a workaround, try surrounding detox.init() with a try/catch clause, and print the exception. What does it say ?

@vspedr do you see the app loading on simulator screen ?

Can’t get a full understanding of what’s happening yet, but this is what I understand form the logs:

  1. The Detox verbose log states that the simulator never reported that it is ready (it should report that when the app gets loaded and react native finishes parsing the bundle and loading the UI to screen)
  2. The system.log shows some sort of issue with the websocket connection to the packager

By the way, I’m using react native version 0.44.2