Milan Smolík
Milan Smolík

Reputation: 432

DetoxRuntimeError: Detox worker instance has not been installed in this context (DetoxSecondaryContext). when running Expo-Detox-Typescript

I want to test an Expo app with Detox v20.1.1 in Typescript. I have been following multiple guides, but they all seem kind of outdated. Right now, I have managed to get the test to start, but I get this error:

    DetoxRuntimeError: Detox worker instance has not been installed in this context (DetoxSecondaryContext).

    HINT: If you are using Detox with Jest according to the latest guide, please report this issue on our GitHub tracker:
    https://github.com/wix/Detox/issues
    Otherwise, make sure you call detox.installWorker() beforehand.

      3 | describe('Example', () => {
      4 |   beforeAll(async () => {
    > 5 |     await device.launchApp()
        |                  ^
      6 |   })
      7 |
      8 |   beforeEach(async () => {

Do you know what's that all about? I wanted to use detox.init(), but that is no longer defined. Shouldn't this be covered in globalSetup that I define in jest.config.js?

detoxrc:

/** @type {Detox.DetoxConfig} */
module.exports = {
  testRunner: {
    args: {
      $0: 'jest',
      args: {
        config: 'test/e2e/jest.config.js',
      },
    },
    jest: {
      setupTimeout: 120000,
    },
  },
  apps: {
    ios: {
      type: 'ios.app',
      binaryPath: 'bin/Exponent.app',
      build: 'npm run ios',
    },
  },
  devices: {
    simulator: {
      type: 'ios.simulator',
      device: {
        type: 'iPhone SE (3rd generation)',
      },
    },
  },
  configurations: {
    'ios.sim': {
      device: 'simulator',
      app: 'ios',
    },
  },
}

test/e2e/jest.config.js

module.exports = {
  preset: 'ts-jest',
  testEnvironment: 'node',
  rootDir: '..',
  testMatch: ['<rootDir>/**/*.test.ts'],
  testTimeout: 120000,
  maxWorkers: 1,
  reporters: ['detox/runners/jest/reporter'],
  globalSetup: 'detox/runners/jest/globalSetup',
  globalTeardown: 'detox/runners/jest/globalTeardown',
  verbose: true,
}

Please help :(

Upvotes: 0

Views: 562

Answers (2)

Mateus S.
Mateus S.

Reputation: 1

remove the nested args in testRunner:

args: {
  $0: 'jest',
  config: 'test/e2e/jest.config.js',
},

Upvotes: 0

Nam Ho&#224;ng
Nam Ho&#224;ng

Reputation: 1

i think .detoxrc file is wrong. make sure you config correctly here: docs here.

picture of my .detoxrc.js here:

enter image description here and make sure you run the command correct: detox test --configuration ios.sim.debug

Upvotes: 0

Related Questions