iOS simulator app doesn’t launch when ‘detox test’ command executed

Description

iOS simulator app doesn’t launch when ‘detox test’ command executed

Detox --loglevel verbose output shows [DetoxServer.js/CANNOT_FORWARD]

  • I have tested this issue on the latest Detox release and it still reproduces

Reproduction

Detox tests were last running in April with the following setup

{
  "main": "node_modules/expo/AppEntry.js",
  "scripts": {
    "start": "expo start",
    "android": "expo start --android",
    "ios": "expo start --ios",
    "eject": "expo eject",
    "test": "jest"
  },
  "dependencies": {
    "expo": "^37.0.0",
    "react-native": "https://github.com/expo/react-native/archive/sdk-37.0.0.tar.gz",
  },
  "devDependencies": {
    "detox": "^15.3.0",
    "detox-expo-helpers": "^0.6.0",
    "expo-detox-hook": "^1.0.10",
    "jest-expo": "^37.0.0",
    "metro-react-native-babel-preset": "^0.53.1",
    "react-native-testing-library": "^1.12.0",
    "react-test-renderer": "^16.12.0",
  },
  "jest": {
    "preset": "jest-expo",
    "transformIgnorePatterns": [
      "node_modules/(?!(jest-)?react-native|react-clone-referenced-element|@react-native-community|expo(nent)?|@expo(nent)?/.*|react-navigation|@react-navigation/.*|@unimodules/.*|unimodules|@sentry/.*|sentry-expo|native-base|react-native-multi-slider|@ptomasroos/.*)"
    ],
    "setupFilesAfterEnv": [
      "<rootDir>/unit_tests/setupTests.js"
    ],
    "testMatch": [
      "<rootDir>/unit_tests/**/*.test.js?(x)"
    ]
  },
  "detox": {
    "test-runner": "jest",
    "configurations": {
      "ios.sim": {
        "binaryPath": "<app_name>.app",
        "type": "ios.simulator",
        "name": "iPhone 11 Pro Max"
      }
    }
  }
}

They are now failing as described above with the following package.json

{
  "main": "node_modules/expo/AppEntry.js",
  "scripts": {
    "start": "expo start",
    "android": "expo start --android",
    "ios": "expo start --ios",
    "eject": "expo eject",
    "test": "jest"
  },
  "dependencies": {
    "expo": "^37.0.0",
    "react-native": "https://github.com/expo/react-native/archive/sdk-37.0.0.tar.gz",
  },
  "devDependencies": {
    "detox": "^17.4.5",
    "detox-expo-helpers": "^0.6.0",
    "expo-detox-hook": "^1.0.10",
    "jest-expo": "^37.0.0",
"metro-react-native-babel-preset": "^0.53.1",
    "react-native-testing-library": "^1.12.0",
    "react-test-renderer": "^16.12.0",
  },
  "jest": {
    "preset": "jest-expo",
    "transformIgnorePatterns": [
      "node_modules/(?!(jest-)?react-native|react-clone-referenced-element|@react-native-community/async-storage/.*|expo(nent)?|@expo(nent)?/.*|react-navigation|@react-navigation/.*|@unimodules/.*|unimodules|@sentry/.*|sentry-expo|native-base|react-native-multi-slider|@ptomasroos/.*)"
    ],
    "setupFilesAfterEnv": [
      "<rootDir>/unit_tests/setupTests.js"
    ],
    "testMatch": [
      "<rootDir>/unit_tests/**/*.test.js?(x)"
    ]
  },
  "detox": {
    "test-runner": "jest",
    "configurations": {
      "ios.sim": {
        "binaryPath": "<app_name>.app",
        "type": "ios.simulator",
        "name": "iPhone 11 Pro Max"
      }
    }
  }
}

Expected behavior

Running detox test should open the app in the simulator and execute tests.

Environment (please complete the following information):

  • Detox: 17.4.5
  • React Native: 0.61
  • Node: v14.5.0
  • Device: iOS simulator iPhone 11 pro max
  • Xcode: 11.3.1 (Using expo for development)
  • iOS: 13.3
  • macOS: 10.14.4

Logs

If you are experiencing a timeout in your test

Tried running detox test --debug-synchronization 200

the terminal hangs with the following output

detox[16107] INFO:  [test.js] debugSynchronization=200 reportSpecs=true useCustomLogger=true forceAdbInstall=false DETOX_START_TIMESTAMP=1599257790958 node_modules/.bin/jest --config e2e/config.json '--testNamePattern=^((?!:android:).)*$' --maxWorkers 1 e2e
detox[16109] INFO:  at e2e/tests/Auth/login.spec.js:11:11 
 describe(Auth)
detox[16109] INFO:  at e2e/init.js:21:19 
 beforeAll
detox[16109] INFO:  [DetoxServer.js] server listening on localhost:62081...
detox[16109] INFO:  at e2e/init.js:28:19 
 initialized

 RUNS  e2e/tests/Auth/login.spec.js

Tried adding ‘detoxPrintBusyIdleResources’

terminal hangs with output ‘Filtering the log data using “category == “EarlGreyStatistics””’

Try adding ‘disableSynchroniztion’.

After running detox test, the test code seems to stall at ‘await device.disableSynchronization’ (a console log is never called on the next line of code)

Device and verbose Detox logs

  • I have run my tests using the --loglevel trace argument and am providing the verbose log below:
detox[15678] INFO:  [test.js] configuration="ios.sim" loglevel="verbose" cleanup=true reportSpecs=true useCustomLogger=true forceAdbInstall=false DETOX_START_TIMESTAMP=1599256657224 node_modules/.bin/jest --config e2e/config.json '--testNamePattern=^((?!:android:).)*$' --maxWorkers 1 e2e
detox[15680] INFO:  at e2e/tests/Auth/login.spec.js:11:11 
 describe(Auth)
detox[15680] INFO:  at e2e/init.js:21:19 
 beforeAll
detox[15680] INFO:  [DetoxServer.js] server listening on localhost:61596...
detox[15680] DEBUG: [AsyncWebSocket.js/WEBSOCKET_OPEN] opened web socket to: ws://localhost:61596
detox[15680] DEBUG: [DetoxServer.js/LOGIN] role=tester, sessionId=25a0b4f5-f767-48a9-1a95-ca18b51c4773
detox[15680] DEBUG: [DetoxServer.js/LOGIN_SUCCESS] role=tester, sessionId=25a0b4f5-f767-48a9-1a95-ca18b51c4773
detox[15680] DEBUG: [exec.js/EXEC_CMD, #0] applesimutils --list --byType "iPhone 11 Pro Max"
detox[15680] DEBUG: [exec.js/EXEC_CMD, #1] applesimutils --list --byId 0BABC374-4903-4E95-A1CB-C265C656F1D6 --maxResults 1
detox[15680] DEBUG: [exec.js/EXEC_CMD, #2] /usr/bin/xcrun simctl uninstall 0BABC374-4903-4E95-A1CB-C265C656F1D6 [BUNDLE_ID]
detox[15680] DEBUG: [exec.js/EXEC_TRY, #2] Uninstalling [BUNDLE_ID]...
detox[15680] DEBUG: [exec.js/EXEC_SUCCESS, #2] [BUNDLE_ID] uninstalled
detox[15680] DEBUG: [exec.js/EXEC_CMD, #3] /usr/bin/xcrun simctl install 0BABC374-4903-4E95-A1CB-C265C656F1D6 "/Users/bryanboyko/XCode/<app_name>.app"
detox[15680] DEBUG: [exec.js/EXEC_TRY, #3] Installing /Users/bryanboyko/XCode/<app_name>.app...
detox[15680] DEBUG: [exec.js/EXEC_SUCCESS, #3] /Users/bryanboyko/XCode/<app_name>.app installed
detox[15680] INFO:  at e2e/init.js:28:19 
 initialized
detox[15680] DEBUG: [DetoxServer.js/CANNOT_FORWARD] role=testee not connected, cannot fw action (sessionId=25a0b4f5-f767-48a9-1a95-ca18b51c4773)
detox[15680] INFO:  Auth: should show main feed after manual login
detox[15680] INFO:  at e2e/init.js:57:19 
 before each
detox[15680] DEBUG: [exec.js/EXEC_CMD, #4] /usr/bin/xcrun simctl terminate 0BABC374-4903-4E95-A1CB-C265C656F1D6 [BUNDLE_ID]
detox[15680] DEBUG: [exec.js/EXEC_TRY, #4] Terminating [BUNDLE_ID]...
detox[15680] DEBUG: [exec.js/EXEC_SUCCESS, #4] [BUNDLE_ID] terminated
detox[15680] DEBUG: [exec.js/EXEC_CMD, #5] applesimutils --byId 0BABC374-4903-4E95-A1CB-C265C656F1D6 --bundle [BUNDLE_ID] --restartSB --setPermissions location=inuse,notifications=YES
detox[15680] DEBUG: [exec.js/EXEC_TRY, #5] Trying to set permissions...
detox[15680] DEBUG: [exec.js/EXEC_SUCCESS, #5] Permissions are set
detox[15680] DEBUG: [exec.js/EXEC_CMD, #6] SIMCTL_CHILD_DYLD_INSERT_LIBRARIES="/Users/bryanboyko/Library/ExpoDetoxHook/ios/58b2f26a0f87b2136ea15b6c467bcf04a21fd6e7/ExpoDetoxHook.framework/ExpoDetoxHook:/Users/bryanboyko/Library/Detox/ios/26afbf8d93760131ef9f1ae830bc7169ba83b8b0/Detox.framework/Detox" /usr/bin/xcrun simctl launch 0BABC374-4903-4E95-A1CB-C265C656F1D6 [BUNDLE_ID] --args -detoxServer "ws://localhost:61596" -detoxSessionId "25a0b4f5-f767-48a9-1a95-ca18b51c4773" -EXKernelDisableNuxDefaultsKey "true" -detoxURLBlacklistRegex "\("http://192.168.1.19:19001/onchange","https://e.crashlytics.com/spi/v2/events"\)" -detoxURLOverride "exp://192.168.1.19:19000" -detoxSourceAppOverride "host.exp.exponent"
detox[15680] DEBUG: [exec.js/EXEC_TRY, #6] Launching [BUNDLE_ID]...
detox[15680] DEBUG: [exec.js/EXEC_CMD, #7] /usr/bin/xcrun simctl get_app_container 0BABC374-4903-4E95-A1CB-C265C656F1D6 [BUNDLE_ID]
detox[15680] INFO:  [AppleSimUtils.js] [BUNDLE_ID] launched. To watch simulator logs, run:
        /usr/bin/xcrun simctl spawn 0BABC374-4903-4E95-A1CB-C265C656F1D6 log stream --level debug --style compact --predicate 'process == "[BUNDLE_ID]"'
detox[15680] DEBUG: [DetoxServer.js/CANNOT_FORWARD] role=testee not connected, cannot fw action (sessionId=25a0b4f5-f767-48a9-1a95-ca18b51c4773)
detox[15680] DEBUG: [DetoxServer.js/LOGIN] role=testee, sessionId=25a0b4f5-f767-48a9-1a95-ca18b51c4773
detox[15680] DEBUG: [DetoxServer.js/LOGIN_SUCCESS] role=testee, sessionId=25a0b4f5-f767-48a9-1a95-ca18b51c4773
detox[15680] INFO:  at e2e/tests/Auth/login.spec.js:37:21 
 1st test
detox[15680] INFO:  Auth: should show main feed after manual login [FAIL]

detox[15680] INFO:  at e2e/init.js:73:19 
 after all
detox[15680] WARN:  [Client.js/PENDING_REQUESTS] App has not responded to the network requests below:
  (id = 1) setSyncSettings: {"enabled":false}
  (id = 2) invoke: {"type":"expectation","predicate":{"type":"id","value":"LOGIN_VIEW"},"expectation":"toBeVisible"}
  (id = -1000) isReady: {}

That might be the reason why the test "Auth should show main feed after manual login" has timed out.

detox[15680] DEBUG: [exec.js/EXEC_CMD, #8] /usr/bin/xcrun simctl shutdown 0BABC374-4903-4E95-A1CB-C265C656F1D6
detox[15680] DEBUG: [exec.js/EXEC_TRY, #8] Shutting down 0BABC374-4903-4E95-A1CB-C265C656F1D6...
detox[15680] DEBUG: [DetoxServer.js/DISCONNECT] role=tester, sessionId=25a0b4f5-f767-48a9-1a95-ca18b51c4773
detox[15680] DEBUG: [DetoxServer.js/DISCONNECT] role=testee, sessionId=25a0b4f5-f767-48a9-1a95-ca18b51c4773
detox[15680] DEBUG: [DetoxServer.js/CANNOT_FORWARD] role=tester not connected, cannot fw action (sessionId=25a0b4f5-f767-48a9-1a95-ca18b51c4773)
detox[15680] DEBUG: [exec.js/EXEC_SUCCESS, #8] 0BABC374-4903-4E95-A1CB-C265C656F1D6 shut down
detox[15680] DEBUG: [DetoxServer.js/WS_CLOSE] Detox server connections terminated gracefully
 FAIL  e2e/tests/Auth/login.spec.js (547.778s)
  Auth
    ✕ should show main feed after manual login (240426ms)

  ● Auth › should show main feed after manual login

    Timeout - Async callback was not invoked within the 300000ms timeout specified by jest.setTimeout.Error: Timeout - Async callback was not invoked within the 300000ms timeout specified by jest.setTimeout.

      at mapper (../node_modules/jest-jasmine2/build/queueRunner.js:25:45)

  ● Auth › should show main feed after manual login

    Timeout - Async callback was not invoked within the 120000ms timeout specified by jest.setTimeout.Error: Timeout - Async callback was not invoked within the 120000ms timeout specified by jest.setTimeout.

      at mapper (../node_modules/jest-jasmine2/build/queueRunner.js:25:45)

  ● Auth › should show main feed after manual login

    : Timeout - Async callback was not invoked within the 120000ms timeout specified by jest.setTimeout.Timeout - Async callback was not invoked within the 120000ms timeout specified by jest.setTimeout.

      30 | 
[private login info]
      34 | 
      35 |     // DOUBLE TAP LOGIN BUTTON

      at new Spec (../node_modules/jest-jasmine2/build/jasmine/Spec.js:116:22)
      at Suite.<anonymous> (tests/Auth/login.spec.js:32:3)
      at Object.<anonymous> (tests/Auth/login.spec.js:10:1)

detox[15680] INFO:  at e2e/init.js:21:19 
 beforeAll
detox[15680] INFO:  [DetoxServer.js] server listening on localhost:61703...
detox[15680] DEBUG: [AsyncWebSocket.js/WEBSOCKET_OPEN] opened web socket to: ws://localhost:61703
detox[15680] DEBUG: [DetoxServer.js/LOGIN] role=tester, sessionId=d7d6ad2d-d095-81b0-7955-6b83885362a3
detox[15680] DEBUG: [DetoxServer.js/LOGIN_SUCCESS] role=tester, sessionId=d7d6ad2d-d095-81b0-7955-6b83885362a3
detox[15680] DEBUG: [exec.js/EXEC_CMD, #0] applesimutils --list --byType "iPhone 11 Pro Max"
detox[15680] DEBUG: [exec.js/EXEC_CMD, #1] applesimutils --list --byId 0BABC374-4903-4E95-A1CB-C265C656F1D6 --maxResults 1
detox[15680] DEBUG: [exec.js/EXEC_CMD, #2] /usr/bin/xcrun simctl boot 0BABC374-4903-4E95-A1CB-C265C656F1D6 
detox[15680] DEBUG: [exec.js/EXEC_TRY, #2] Booting device 0BABC374-4903-4E95-A1CB-C265C656F1D6...
detox[15680] DEBUG: [exec.js/EXEC_CMD, #3] /usr/bin/xcrun simctl bootstatus 0BABC374-4903-4E95-A1CB-C265C656F1D6
detox[15680] DEBUG: [exec.js/EXEC_CMD, #4] /usr/bin/xcrun simctl io 0BABC374-4903-4E95-A1CB-C265C656F1D6 screenshot "/dev/null"
detox[15680] DEBUG: [exec.js/EXEC_CMD, #5] /usr/bin/xcrun simctl uninstall 0BABC374-4903-4E95-A1CB-C265C656F1D6 [BUNDLE_ID]
detox[15680] DEBUG: [exec.js/EXEC_TRY, #5] Uninstalling [BUNDLE_ID]...
detox[15680] DEBUG: [exec.js/EXEC_SUCCESS, #5] [BUNDLE_ID] uninstalled
detox[15680] DEBUG: [exec.js/EXEC_CMD, #6] /usr/bin/xcrun simctl install 0BABC374-4903-4E95-A1CB-C265C656F1D6 "/Users/bryanboyko/XCode/<app_name>.app"
detox[15680] DEBUG: [exec.js/EXEC_TRY, #6] Installing /Users/bryanboyko/XCode/<app_name>.app...
detox[15680] DEBUG: [exec.js/EXEC_SUCCESS, #6] /Users/bryanboyko/XCode/<app_name>.app installed
detox[15680] INFO:  at e2e/init.js:28:19 
 initialized
detox[15680] DEBUG: [DetoxServer.js/CANNOT_FORWARD] role=testee not connected, cannot fw action (sessionId=d7d6ad2d-d095-81b0-7955-6b83885362a3)

 RUNS  e2e/tests/Auth/registration.spec.js

1 possible answer(s) on “iOS simulator app doesn’t launch when ‘detox test’ command executed

  1. I had the same issue in iOS release build event it was working in debug build
    my current react native version "react-native": "0.61.5"

    i fix it by add in info.plist file

    <key>NSAllowsArbitraryLoads</key>
    <true/>
    

    which is added by default since react-native version 0.64