DetoxRuntimeError: Detox instance has not been initialized

Created on 13 Mar 2020  ·  8Comments  ·  Source: wix/Detox

Problem Description:

When trying to run the Detox tests ,
the detox build is successful, but when trying to run the detox test
facing the following error of

DetoxRuntimeError:Detox instance has not been initialized
and also getting hint to use detox.init(), where Its already being present and initialized as per the logs

The Jest-init.js

const detox = require('detox');
const config = require('../package.json').detox;
const adapter = require('detox/runners/jest/adapter');
const specReporter = require('detox/runners/jest/specReporter');

// Set the default timeout
jest.setTimeout(120000);

jasmine.getEnv().addReporter(adapter);

// This takes care of generating status logs on a per-spec basis. By default, jest only reports at file-level.
// This is strictly optional.
jasmine.getEnv().addReporter(specReporter);

beforeAll(async () => {
console.log("*******************^^^^^^^^^^^^^^^^^^^^$$$$$$$$$$$$$$$$$$$$$$$$$%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%^^^^^^^^^^^^^")
await detox.init(config);
}, 300000);

beforeEach(async () => {
  await adapter.beforeEach();
});

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

The detox log:

╭─      ~/t/testDetox/rippling-mobile     master !8 ?2 ▓▒░········░▒▓ 1 ✘  10.17.0 ⬢   13:20:49   
╰─ detox test -l trace -d --debug-synchronization
detox[39904] INFO:  [test.js] configuration="ios.sim.debug" loglevel="trace" debugSynchronization=3000 reportSpecs=true useCustomLogger=true DETOX_START_TIMESTAMP=1584085894264 node_modules/.bin/jest --config e2e/config.json '--testNamePattern=^((?!:android:).)*$' --maxWorkers 1 "e2e"
detox[39905] INFO:  at e2e/init.js:21:19
 *******************^^^^^^^^^^^^^^^^^^^^$$$$$$$$$$$$$$$$$$$$$$$$$%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%^^^^^^^^^^^^^

detox[39905] TRACE: [Detox.js/DETOX_CREATE] created a Detox instance with config:
{"deviceConfig":{"binaryPath":"ios/build/Build/Products/Debug-iphonesimulator/rippling.app","build":"xcodebuild -project ios/rippling.xcodeproj -scheme rippling -configuration Debug -sdk iphonesimulator -derivedDataPath ios/build","type":"ios.simulator","device":{"type":"iPhone 11 Pro"}},"artifactsConfig":{"rootDir":"artifacts/ios.sim.debug.2020-03-13 07-51-34Z","plugins":{"log":{"enabled":false,"keepOnlyFailedTestsArtifacts":false},"screenshot":{"enabled":true,"shouldTakeAutomaticSnapshots":false,"keepOnlyFailedTestsArtifacts":false},"video":{"enabled":false,"keepOnlyFailedTestsArtifacts":false},"instruments":{"enabled":false,"keepOnlyFailedTestsArtifacts":false},"timeline":{"enabled":false}},"pathBuilder":{"_rootDir":"artifacts/ios.sim.debug.2020-03-13 07-51-34Z"}}}
detox[39905] INFO:  [DetoxServer.js] server listening on localhost:58967...
detox[39905] DEBUG: [AsyncWebSocket.js/WEBSOCKET_OPEN] opened web socket to: ws://localhost:58967
detox[39905] TRACE: [AsyncWebSocket.js/WEBSOCKET_SEND] {"type":"login","params":{"sessionId":"ceee7138-7532-bb7d-8f2d-fbad5b7aad73","role":"tester"},"messageId":0}
detox[39905] DEBUG: [DetoxServer.js/LOGIN] role=tester, sessionId=ceee7138-7532-bb7d-8f2d-fbad5b7aad73
detox[39905] DEBUG: [DetoxServer.js/LOGIN_SUCCESS] role=tester, sessionId=ceee7138-7532-bb7d-8f2d-fbad5b7aad73
detox[39905] TRACE: [AsyncWebSocket.js/WEBSOCKET_MESSAGE] {"type":"loginSuccess","params":{"sessionId":"ceee7138-7532-bb7d-8f2d-fbad5b7aad73","role":"tester"},"messageId":0}

detox[39905] DEBUG: [exec.js/EXEC_CMD, #0] applesimutils --list --byType "iPhone 11 Pro"
detox[39905] TRACE: [exec.js/EXEC_SUCCESS, #0] [
  {
    "deviceType" : {
      "name" : "iPhone 11 Pro",
      "bundlePath" : "\/Applications\/Xcode.app\/Contents\/Developer\/Platforms\/iPhoneOS.platform\/Library\/Developer\/CoreSimulator\/Profiles\/DeviceTypes\/iPhone 11 Pro.simdevicetype",
      "identifier" : "com.apple.CoreSimulator.SimDeviceType.iPhone-11-Pro"
    },
    "state" : "Booted",
    "isAvailable" : true,
    "name" : "iPhone 11 Pro",
    "udid" : "9FD7C5EA-F3B7-4E26-A79E-0A848ADE1269",
    "os" : {
      "buildversion" : "17C45",
      "bundlePath" : "\/Applications\/Xcode.app\/Contents\/Developer\/Platforms\/iPhoneOS.platform\/Library\/Developer\/CoreSimulator\/Profiles\/Runtimes\/iOS.simruntime",
      "isAvailable" : true,
      "name" : "iOS 13.3",
      "identifier" : "com.apple.CoreSimulator.SimRuntime.iOS-13-3",
      "version" : "13.3"
    }
  },
  {
    "deviceType" : {
      "name" : "iPhone 11 Pro",
      "bundlePath" : "\/Applications\/Xcode.app\/Contents\/Developer\/Platforms\/iPhoneOS.platform\/Library\/Developer\/CoreSimulator\/Profiles\/DeviceTypes\/iPhone 11 Pro.simdevicetype",
      "identifier" : "com.apple.CoreSimulator.SimDeviceType.iPhone-11-Pro"
    },
    "state" : "Shutdown",
    "isAvailable" : true,
    "name" : "iPhone 11 Pro",
    "udid" : "92B978D1-86D6-4805-A548-77F9046DEF7C",
    "os" : {
      "buildversion" : "17B102",
      "bundlePath" : "\/Library\/Developer\/CoreSimulator\/Profiles\/Runtimes\/iOS 13.2.simruntime",
      "isAvailable" : true,
      "name" : "iOS 13.2",
      "identifier" : "com.apple.CoreSimulator.SimRuntime.iOS-13-2",
      "version" : "13.2.2"
    }
  },
  {
    "deviceType" : {
      "name" : "iPhone 11 Pro",
      "bundlePath" : "\/Applications\/Xcode.app\/Contents\/Developer\/Platforms\/iPhoneOS.platform\/Library\/Developer\/CoreSimulator\/Profiles\/DeviceTypes\/iPhone 11 Pro.simdevicetype",
      "identifier" : "com.apple.CoreSimulator.SimDeviceType.iPhone-11-Pro"
    },
    "state" : "Shutdown",
    "isAvailable" : true,
    "name" : "iPhone 11 Pro",
    "udid" : "3D34B603-D148-48C2-A3F1-0A5CEF1ECEAA",
    "os" : {
      "buildversion" : "17A844",
      "bundlePath" : "\/Library\/Developer\/CoreSimulator\/Profiles\/Runtimes\/iOS 13.1.simruntime",
      "isAvailable" : true,
      "name" : "iOS 13.1",
      "identifier" : "com.apple.CoreSimulator.SimRuntime.iOS-13-1",
      "version" : "13.1"
    }
  }
]

detox[39905] DEBUG: [exec.js/EXEC_CMD, #1] applesimutils --list --byId 9FD7C5EA-F3B7-4E26-A79E-0A848ADE1269 --maxResults 1
detox[39905] TRACE: [exec.js/EXEC_SUCCESS, #1] [
  {
    "deviceType" : {
      "name" : "iPhone 11 Pro",
      "bundlePath" : "\/Applications\/Xcode.app\/Contents\/Developer\/Platforms\/iPhoneOS.platform\/Library\/Developer\/CoreSimulator\/Profiles\/DeviceTypes\/iPhone 11 Pro.simdevicetype",
      "identifier" : "com.apple.CoreSimulator.SimDeviceType.iPhone-11-Pro"
    },
    "state" : "Booted",
    "isAvailable" : true,
    "name" : "iPhone 11 Pro",
    "udid" : "9FD7C5EA-F3B7-4E26-A79E-0A848ADE1269",
    "os" : {
      "buildversion" : "17C45",
      "bundlePath" : "\/Applications\/Xcode.app\/Contents\/Developer\/Platforms\/iPhoneOS.platform\/Library\/Developer\/CoreSimulator\/Profiles\/Runtimes\/iOS.simruntime",
      "isAvailable" : true,
      "name" : "iOS 13.3",
      "identifier" : "com.apple.CoreSimulator.SimRuntime.iOS-13-3",
      "version" : "13.3"
    }
  }
]

detox[39905] TRACE: [ArtifactsManager.js/LIFECYCLE] artifactsManager.onBootDevice({ coldBoot: false,
  deviceId: '9FD7C5EA-F3B7-4E26-A79E-0A848ADE1269',
  type: 'iPhone 11 Pro' })
detox[39905] TRACE: [ArtifactsManager.js/LIFECYCLE] artifactsManager.onBeforeUninstallApp({ deviceId: '9FD7C5EA-F3B7-4E26-A79E-0A848ADE1269',
  bundleId: 'com.people.rippling' })
detox[39905] DEBUG: [exec.js/EXEC_CMD, #2] /usr/bin/xcrun simctl uninstall 9FD7C5EA-F3B7-4E26-A79E-0A848ADE1269 com.people.rippling
detox[39905] DEBUG: [exec.js/EXEC_TRY, #2] Uninstalling com.people.rippling...
detox[39905] TRACE: [exec.js/EXEC_SUCCESS, #2]
detox[39905] DEBUG: [exec.js/EXEC_SUCCESS, #2] com.people.rippling uninstalled
detox[39905] DEBUG: [exec.js/EXEC_CMD, #3] /usr/bin/xcrun simctl install 9FD7C5EA-F3B7-4E26-A79E-0A848ADE1269 "/Users/vayu/testReactNative/testDetox/rippling-mobile/ios/build/Build/Products/Debug-iphonesimulator/rippling.app"
detox[39905] DEBUG: [exec.js/EXEC_TRY, #3] Installing /Users/vayu/testReactNative/testDetox/rippling-mobile/ios/build/Build/Products/Debug-iphonesimulator/rippling.app...
detox[39905] TRACE: [exec.js/EXEC_SUCCESS, #3]
detox[39905] DEBUG: [exec.js/EXEC_SUCCESS, #3] /Users/vayu/testReactNative/testDetox/rippling-mobile/ios/build/Build/Products/Debug-iphonesimulator/rippling.app installed
detox[39905] TRACE: [ArtifactsManager.js/LIFECYCLE] artifactsManager.onBeforeTerminateApp({ deviceId: '9FD7C5EA-F3B7-4E26-A79E-0A848ADE1269',
  bundleId: 'com.people.rippling' })
detox[39905] DEBUG: [exec.js/EXEC_CMD, #4] /usr/bin/xcrun simctl terminate 9FD7C5EA-F3B7-4E26-A79E-0A848ADE1269 com.people.rippling
detox[39905] DEBUG: [exec.js/EXEC_TRY, #4] Terminating com.people.rippling...
detox[39905] TRACE: [exec.js/EXEC_SUCCESS, #4]
detox[39905] DEBUG: [exec.js/EXEC_SUCCESS, #4] com.people.rippling terminated
detox[39905] TRACE: [ArtifactsManager.js/LIFECYCLE] artifactsManager.onTerminateApp({ deviceId: '9FD7C5EA-F3B7-4E26-A79E-0A848ADE1269',
  bundleId: 'com.people.rippling' })
detox[39905] TRACE: [ArtifactsManager.js/LIFECYCLE] artifactsManager.onBeforeLaunchApp({ bundleId: 'com.people.rippling',
  deviceId: '9FD7C5EA-F3B7-4E26-A79E-0A848ADE1269',
  launchArgs:
   { detoxServer: 'ws://localhost:58967',
     detoxSessionId: 'ceee7138-7532-bb7d-8f2d-fbad5b7aad73' } })
detox[39905] DEBUG: [exec.js/EXEC_CMD, #5] SIMCTL_CHILD_DYLD_INSERT_LIBRARIES="/Users/vayu/Library/Detox/ios/263d0887413cd8a47c05eaf4190d024307b129a1/Detox.framework/Detox" /usr/bin/xcrun simctl launch 9FD7C5EA-F3B7-4E26-A79E-0A848ADE1269 com.people.rippling --args -detoxServer "ws://localhost:58967" -detoxSessionId "ceee7138-7532-bb7d-8f2d-fbad5b7aad73"
detox[39905] DEBUG: [exec.js/EXEC_TRY, #5] Launching com.people.rippling...
detox[39905] TRACE: [exec.js/EXEC_SUCCESS, #5] com.people.rippling: 39945

detox[39905] DEBUG: [exec.js/EXEC_CMD, #6] /usr/bin/xcrun simctl get_app_container 9FD7C5EA-F3B7-4E26-A79E-0A848ADE1269 com.people.rippling
detox[39905] TRACE: [exec.js/EXEC_SUCCESS, #6] /Users/vayu/Library/Developer/CoreSimulator/Devices/9FD7C5EA-F3B7-4E26-A79E-0A848ADE1269/data/Containers/Bundle/Application/F3F545C6-F8E1-4D4D-A3BF-B34621B06F4F/rippling.app

detox[39905] INFO:  [AppleSimUtils.js] com.people.rippling launched. To watch simulator logs, run:
        /usr/bin/xcrun simctl spawn 9FD7C5EA-F3B7-4E26-A79E-0A848ADE1269 log stream --level debug --style compact --predicate 'process == "rippling"'
detox[39945] TRACE: [ArtifactsManager.js/LIFECYCLE] artifactsManager.onLaunchApp({ bundleId: 'com.people.rippling',
  deviceId: '9FD7C5EA-F3B7-4E26-A79E-0A848ADE1269',
  launchArgs:
   { detoxServer: 'ws://localhost:58967',
     detoxSessionId: 'ceee7138-7532-bb7d-8f2d-fbad5b7aad73' },
  pid: 39945 })
detox[39905] TRACE: [AsyncWebSocket.js/WEBSOCKET_SEND] {"type":"isReady","params":{},"messageId":-1000}
detox[39905] TRACE: [DetoxServer.js/MESSAGE] role=tester action=isReady (sessionId=ceee7138-7532-bb7d-8f2d-fbad5b7aad73)
detox[39905] DEBUG: [DetoxServer.js/CANNOT_FORWARD] role=testee not connected, cannot fw action (sessionId=ceee7138-7532-bb7d-8f2d-fbad5b7aad73)
detox[39905] DEBUG: [DetoxServer.js/LOGIN] role=testee, sessionId=ceee7138-7532-bb7d-8f2d-fbad5b7aad73
detox[39905] DEBUG: [DetoxServer.js/LOGIN_SUCCESS] role=testee, sessionId=ceee7138-7532-bb7d-8f2d-fbad5b7aad73
detox[39905] INFO:  Example: should have welcome screen
detox[39905] INFO:  Example: should have welcome screen [FAIL]
detox[39905] INFO:  Example: should show hello screen after tap
detox[39905] INFO:  Example: should show hello screen after tap [FAIL]
detox[39905] INFO:  Example: should show world screen after tap
detox[39905] INFO:  Example: should show world screen after tap [FAIL]

 FAIL  e2e/firstTest.spec.js (300.954s)
  Example
    ✕ should have welcome screen (4ms)
    ✕ should show hello screen after tap (1ms)
    ✕ should show world screen after tap (2ms)

  ● Example › should have welcome screen

    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)

  ● Example › should have welcome screen

    DetoxRuntimeError: Detox instance has not been initialized

    HINT: Make sure to call detox.init() before your test begins

      at MissingDetox.throwError (../node_modules/detox/src/utils/MissingDetox.js:67:11)
      at MissingDetox._defineRequiredProperty (../node_modules/detox/src/utils/MissingDetox.js:8:71)
      at DetoxExportWrapper.(anonymous function).args [as beforeEach] (../node_modules/detox/src/DetoxExportWrapper.js:53:32)
      at DetoxAdapterImpl.beforeEach (../node_modules/detox/runners/jest/DetoxAdapterImpl.js:17:22)

  ● Example › should have welcome screen

    DetoxRuntimeError: Detox instance has not been initialized

    HINT: Make sure to call detox.init() before your test begins

      1 | describe('Example', () => {
      2 |   beforeEach(async () => {
    > 3 |     await device.reloadReactNative();
        |           ^
      4 |   });
      5 |
      6 |   it('should have welcome screen', async () => {

      at MissingDetox.throwError (../node_modules/detox/src/utils/MissingDetox.js:67:11)
      at Object.device (../node_modules/detox/src/utils/MissingDetox.js:46:16)
      at Object._callee$ (firstTest.spec.js:3:11)
      at tryCatch (../node_modules/@babel/runtime/node_modules/regenerator-runtime/runtime.js:62:40)
      at Generator.invoke [as _invoke] (../node_modules/@babel/runtime/node_modules/regenerator-runtime/runtime.js:288:22)
      at Generator.prototype.(anonymous function) [as next] (../node_modules/@babel/runtime/node_modules/regenerator-runtime/runtime.js:114:21)
      at tryCatch (../node_modules/@babel/runtime/node_modules/regenerator-runtime/runtime.js:62:40)
      at invoke (../node_modules/@babel/runtime/node_modules/regenerator-runtime/runtime.js:152:20)
      at ../node_modules/@babel/runtime/node_modules/regenerator-runtime/runtime.js:187:11
      at callInvokeWithMethodAndArg (../node_modules/@babel/runtime/node_modules/regenerator-runtime/runtime.js:186:16)
      at AsyncIterator.enqueue (../node_modules/@babel/runtime/node_modules/regenerator-runtime/runtime.js:209:13)
      at AsyncIterator.prototype.(anonymous function) [as next] (../node_modules/@babel/runtime/node_modules/regenerator-runtime/runtime.js:114:21)
      at Object.<anonymous>.runtime.async (../node_modules/@babel/runtime/node_modules/regenerator-runtime/runtime.js:233:14)
      at Object._callee (firstTest.spec.js:2:14)

  ● Example › should have welcome screen

    DetoxRuntimeError: Detox instance has not been initialized

    HINT: Make sure to call detox.init() before your test begins

       5 |
       6 |   it('should have welcome screen', async () => {
    >  7 |     await expect(element(by.id('welcome'))).toBeVisible();
         |                          ^
       8 |   });
       9 |
      10 |   it('should show hello screen after tap', async () => {

      at MissingDetox.throwError (../node_modules/detox/src/utils/MissingDetox.js:67:11)
      at Object.by (../node_modules/detox/src/utils/MissingDetox.js:46:16)
      at Object._callee2$ (firstTest.spec.js:7:26)
      at tryCatch (../node_modules/@babel/runtime/node_modules/regenerator-runtime/runtime.js:62:40)
      at Generator.invoke [as _invoke] (../node_modules/@babel/runtime/node_modules/regenerator-runtime/runtime.js:288:22)
      at Generator.prototype.(anonymous function) [as next] (../node_modules/@babel/runtime/node_modules/regenerator-runtime/runtime.js:114:21)
      at tryCatch (../node_modules/@babel/runtime/node_modules/regenerator-runtime/runtime.js:62:40)
      at invoke (../node_modules/@babel/runtime/node_modules/regenerator-runtime/runtime.js:152:20)
      at ../node_modules/@babel/runtime/node_modules/regenerator-runtime/runtime.js:187:11
      at callInvokeWithMethodAndArg (../node_modules/@babel/runtime/node_modules/regenerator-runtime/runtime.js:186:16)
      at AsyncIterator.enqueue (../node_modules/@babel/runtime/node_modules/regenerator-runtime/runtime.js:209:13)
      at AsyncIterator.prototype.(anonymous function) [as next] (../node_modules/@babel/runtime/node_modules/regenerator-runtime/runtime.js:114:21)
      at Object.<anonymous>.runtime.async (../node_modules/@babel/runtime/node_modules/regenerator-runtime/runtime.js:233:14)
      at Object._callee2 (firstTest.spec.js:6:36)

  ● Example › should show hello screen after tap

    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)

  ● Example › should show hello screen after tap

    DetoxRuntimeError: Detox instance has not been initialized

    HINT: Make sure to call detox.init() before your test begins

      at MissingDetox.throwError (../node_modules/detox/src/utils/MissingDetox.js:67:11)
      at MissingDetox._defineRequiredProperty (../node_modules/detox/src/utils/MissingDetox.js:8:71)
      at DetoxExportWrapper.(anonymous function).args [as beforeEach] (../node_modules/detox/src/DetoxExportWrapper.js:53:32)
      at DetoxAdapterImpl.beforeEach (../node_modules/detox/runners/jest/DetoxAdapterImpl.js:17:22)

  ● Example › should show hello screen after tap

    DetoxRuntimeError: Detox instance has not been initialized

    HINT: Make sure to call detox.init() before your test begins

      1 | describe('Example', () => {
      2 |   beforeEach(async () => {
    > 3 |     await device.reloadReactNative();
        |           ^
      4 |   });
      5 |
      6 |   it('should have welcome screen', async () => {

      at MissingDetox.throwError (../node_modules/detox/src/utils/MissingDetox.js:67:11)
      at Object.device (../node_modules/detox/src/utils/MissingDetox.js:46:16)
      at Object._callee$ (firstTest.spec.js:3:11)
      at tryCatch (../node_modules/@babel/runtime/node_modules/regenerator-runtime/runtime.js:62:40)
      at Generator.invoke [as _invoke] (../node_modules/@babel/runtime/node_modules/regenerator-runtime/runtime.js:288:22)
      at Generator.prototype.(anonymous function) [as next] (../node_modules/@babel/runtime/node_modules/regenerator-runtime/runtime.js:114:21)
      at tryCatch (../node_modules/@babel/runtime/node_modules/regenerator-runtime/runtime.js:62:40)
      at invoke (../node_modules/@babel/runtime/node_modules/regenerator-runtime/runtime.js:152:20)
      at ../node_modules/@babel/runtime/node_modules/regenerator-runtime/runtime.js:187:11
      at callInvokeWithMethodAndArg (../node_modules/@babel/runtime/node_modules/regenerator-runtime/runtime.js:186:16)
      at AsyncIterator.enqueue (../node_modules/@babel/runtime/node_modules/regenerator-runtime/runtime.js:209:13)
      at AsyncIterator.prototype.(anonymous function) [as next] (../node_modules/@babel/runtime/node_modules/regenerator-runtime/runtime.js:114:21)
      at Object.<anonymous>.runtime.async (../node_modules/@babel/runtime/node_modules/regenerator-runtime/runtime.js:233:14)
      at Object._callee (firstTest.spec.js:2:14)

  ● Example › should show hello screen after tap

    DetoxRuntimeError: Detox instance has not been initialized

    HINT: Make sure to call detox.init() before your test begins

       9 |
      10 |   it('should show hello screen after tap', async () => {
    > 11 |     await element(by.id('hello_button')).tap();
         |                   ^
      12 |     await expect(element(by.text('Hello!!!'))).toBeVisible();
      13 |   });
      14 |

      at MissingDetox.throwError (../node_modules/detox/src/utils/MissingDetox.js:67:11)
      at Object.by (../node_modules/detox/src/utils/MissingDetox.js:46:16)
      at Object._callee3$ (firstTest.spec.js:11:19)
      at tryCatch (../node_modules/@babel/runtime/node_modules/regenerator-runtime/runtime.js:62:40)
      at Generator.invoke [as _invoke] (../node_modules/@babel/runtime/node_modules/regenerator-runtime/runtime.js:288:22)
      at Generator.prototype.(anonymous function) [as next] (../node_modules/@babel/runtime/node_modules/regenerator-runtime/runtime.js:114:21)
      at tryCatch (../node_modules/@babel/runtime/node_modules/regenerator-runtime/runtime.js:62:40)
      at invoke (../node_modules/@babel/runtime/node_modules/regenerator-runtime/runtime.js:152:20)
      at ../node_modules/@babel/runtime/node_modules/regenerator-runtime/runtime.js:187:11
      at callInvokeWithMethodAndArg (../node_modules/@babel/runtime/node_modules/regenerator-runtime/runtime.js:186:16)
      at AsyncIterator.enqueue (../node_modules/@babel/runtime/node_modules/regenerator-runtime/runtime.js:209:13)
      at AsyncIterator.prototype.(anonymous function) [as next] (../node_modules/@babel/runtime/node_modules/regenerator-runtime/runtime.js:114:21)
      at Object.<anonymous>.runtime.async (../node_modules/@babel/runtime/node_modules/regenerator-runtime/runtime.js:233:14)
      at Object._callee3 (firstTest.spec.js:10:44)

  ● Example › should show world screen after tap

    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)

  ● Example › should show world screen after tap

    DetoxRuntimeError: Detox instance has not been initialized

    HINT: Make sure to call detox.init() before your test begins

      at MissingDetox.throwError (../node_modules/detox/src/utils/MissingDetox.js:67:11)
      at MissingDetox._defineRequiredProperty (../node_modules/detox/src/utils/MissingDetox.js:8:71)
      at DetoxExportWrapper.(anonymous function).args [as beforeEach] (../node_modules/detox/src/DetoxExportWrapper.js:53:32)
      at DetoxAdapterImpl.beforeEach (../node_modules/detox/runners/jest/DetoxAdapterImpl.js:17:22)

  ● Example › should show world screen after tap

    DetoxRuntimeError: Detox instance has not been initialized

    HINT: Make sure to call detox.init() before your test begins

      1 | describe('Example', () => {
      2 |   beforeEach(async () => {
    > 3 |     await device.reloadReactNative();
        |           ^
      4 |   });
      5 |
      6 |   it('should have welcome screen', async () => {

      at MissingDetox.throwError (../node_modules/detox/src/utils/MissingDetox.js:67:11)
      at Object.device (../node_modules/detox/src/utils/MissingDetox.js:46:16)
      at Object._callee$ (firstTest.spec.js:3:11)
      at tryCatch (../node_modules/@babel/runtime/node_modules/regenerator-runtime/runtime.js:62:40)
      at Generator.invoke [as _invoke] (../node_modules/@babel/runtime/node_modules/regenerator-runtime/runtime.js:288:22)
      at Generator.prototype.(anonymous function) [as next] (../node_modules/@babel/runtime/node_modules/regenerator-runtime/runtime.js:114:21)
      at tryCatch (../node_modules/@babel/runtime/node_modules/regenerator-runtime/runtime.js:62:40)
      at invoke (../node_modules/@babel/runtime/node_modules/regenerator-runtime/runtime.js:152:20)
      at ../node_modules/@babel/runtime/node_modules/regenerator-runtime/runtime.js:187:11
      at callInvokeWithMethodAndArg (../node_modules/@babel/runtime/node_modules/regenerator-runtime/runtime.js:186:16)
      at AsyncIterator.enqueue (../node_modules/@babel/runtime/node_modules/regenerator-runtime/runtime.js:209:13)
      at AsyncIterator.prototype.(anonymous function) [as next] (../node_modules/@babel/runtime/node_modules/regenerator-runtime/runtime.js:114:21)
      at Object.<anonymous>.runtime.async (../node_modules/@babel/runtime/node_modules/regenerator-runtime/runtime.js:233:14)
      at Object._callee (firstTest.spec.js:2:14)

  ● Example › should show world screen after tap

    DetoxRuntimeError: Detox instance has not been initialized

    HINT: Make sure to call detox.init() before your test begins

      14 |
      15 |   it('should show world screen after tap', async () => {
    > 16 |     await element(by.id('world_button')).tap();
         |                   ^
      17 |     await expect(element(by.text('World!!!'))).toBeVisible();
      18 |   });
      19 | });

      at MissingDetox.throwError (../node_modules/detox/src/utils/MissingDetox.js:67:11)
      at Object.by (../node_modules/detox/src/utils/MissingDetox.js:46:16)
      at Object._callee4$ (firstTest.spec.js:16:19)
      at tryCatch (../node_modules/@babel/runtime/node_modules/regenerator-runtime/runtime.js:62:40)
      at Generator.invoke [as _invoke] (../node_modules/@babel/runtime/node_modules/regenerator-runtime/runtime.js:288:22)
      at Generator.prototype.(anonymous function) [as next] (../node_modules/@babel/runtime/node_modules/regenerator-runtime/runtime.js:114:21)
      at tryCatch (../node_modules/@babel/runtime/node_modules/regenerator-runtime/runtime.js:62:40)
      at invoke (../node_modules/@babel/runtime/node_modules/regenerator-runtime/runtime.js:152:20)
      at ../node_modules/@babel/runtime/node_modules/regenerator-runtime/runtime.js:187:11
      at callInvokeWithMethodAndArg (../node_modules/@babel/runtime/node_modules/regenerator-runtime/runtime.js:186:16)
      at AsyncIterator.enqueue (../node_modules/@babel/runtime/node_modules/regenerator-runtime/runtime.js:209:13)
      at AsyncIterator.prototype.(anonymous function) [as next] (../node_modules/@babel/runtime/node_modules/regenerator-runtime/runtime.js:114:21)
      at Object.<anonymous>.runtime.async (../node_modules/@babel/runtime/node_modules/regenerator-runtime/runtime.js:233:14)
      at Object._callee4 (firstTest.spec.js:15:4

My Detox Configurations:

"detox": {
    "test-runner": "jest",

    "configurations": {
      "ios.sim.debug": {
        "binaryPath": "ios/build/Build/Products/Debug-iphonesimulator/rippling.app",
        "build": "xcodebuild -project ios/rippling.xcodeproj -scheme rippling -configuration Debug -sdk iphonesimulator -derivedDataPath ios/build",
        "type": "ios.simulator",
        "device": {
          "type": "iPhone 11 Pro"
        }
      }
    }
  }

Environment:

Detox: 15.4.2
React Native: 0.59.10
Node: v10.17.0
Device: ios simulator, any model
Xcode: 11.3
iOS: 13.3

P.S:
I have even tried to run local detox server and pass the server details in config\

```detox run-server
detox[33506] INFO: [DetoxServer.js] server listening on localhost:8099...

with configuration

"detox": {
"test-runner": "jest",

"configurations": {
  "ios.sim.debug": {
    "binaryPath": "ios/build/Build/Products/Debug-iphonesimulator/rippling.app",
    "build": "xcodebuild -project ios/rippling.xcodeproj -scheme rippling -configuration Debug -sdk iphonesimulator -derivedDataPath ios/build",
    "type": "ios.simulator",
    "device": {
      "type": "iPhone 11 Pro"
    },
    "session": {
      "server": "ws://localhost:8099",
      "sessionId": "test"
    }
  }
}

}
```

questiostack overflow

Most helpful comment

Why is this issue labeled as a "questions for stackoverflow". I followed the docs on GitHub and ran into the exact same issue. The app builds fine but the tests do not run with Jest.

This is either a bug or should be addressed in the documentation.

All 8 comments

We use the issue tracker exclusively for bug reports and feature requests. This issue appears to be a general usage or support question. Instead, please ask a question on Stack Overflow with the detox tag.

Feel free to post your Stack Overflow question here for more visibility. We'll take a look at it.

For issues with Expo apps, it is most likely not an issue with Detox itself, but with the Expo runtime or with incorrect Detox setup. For support on how to use Detox with Expo, you should contact the Expo team or the Expo community.

For more information on bots in this repository, read this discussion.

Why is this issue labeled as a "questions for stackoverflow". I followed the docs on GitHub and ran into the exact same issue. The app builds fine but the tests do not run with Jest.

This is either a bug or should be addressed in the documentation.

the bot detected it as a question rather than a bug, also did the same for issue #1943.

please find the StackOverflow question for reference and follow up, as of today no correct solution for the issue.
https://stackoverflow.com/questions/60538614/detoxruntimeerrordetox-instance-has-not-been-initialized

@LeoNatan can you please help us on it, if possible

Thanks for the quick response! I have seen the question on StackOverflow. It is using mocha instead of Jest.

I am not trying to run the tests with mocha to see if I run into the same issue. The StackOverflow question changed the firstTest.spec.js code, I am using the scaffolding detox provides itself.

FYI mocha gives an error, with the default scaffolding as well.

detox[75855] INFO:  [test.js] node_modules/.bin/mocha --opts e2e/mocha.opts --configuration ios.sim.debug --grep :android: --invert --use-custom-logger "true" "e2e"
detox[75856] ERROR: at internal/process/warning.js:27:3 
 (node:75856) DeprecationWarning: Configuration via mocha.opts is DEPRECATED and will be removed from a future version of Mocha. Use RC files or package.json instead.


detox[75856] INFO:  [DetoxServer.js] server listening on localhost:62421...
detox[75856] INFO:  [AppleSimUtils.js] com.numuworld.Numu launched. To watch simulator logs, run:
        /usr/bin/xcrun simctl spawn F6C9D959-A42F-48AD-99EF-4382EB8FECDB log stream --level debug --style compact --predicate 'process == "numu"'
  1) "before all" hook in "{root}"

  0 passing (2m)
  1 failing

  1) "before all" hook in "{root}":
     Error: Timeout of 120000ms exceeded. For async tests and hooks, ensure "done()" is called; if returning a Promise, ensure it resolves.
      at listOnTimeout (internal/timers.js:531:17)
      at processTimers (internal/timers.js:475:7)

@AmarnathN @LeoNatan figured out my issue!

I am using react-native-splash-screen which was the cause of the issue! The same issue is also reported here and here.

Solution

In my AppDelegate.mfile, I amended the code - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions method;

#if RELEASE
    [RNSplashScreen show];  // show splash screen if config is RELEASE only for Detox E2E tests
#endif

Please note that Detox tests should normally be run in release mode.

The error here is unfortunate, but it's masking the actual underlying issue of launch not happening fast enough.

We are working on a fix that will remove these "instance not initialized" errors, and it will hopefully make it easier to find these issues in the future:
https://github.com/wix/Detox/pull/1929

Our own https://github.com/wix/react-native-navigation framework handles splashscreens much better, as well as offer proper native navigation solution. Consider using that.

Was this page helpful?
0 / 5 - 0 ratings