Detox icon indicating copy to clipboard operation
Detox copied to clipboard

Getting error - Detox worker instance has not been installed in this context (DetoxSecondaryContext) while running detox with updated globalSetup

Open jyotsna-hh opened this issue 1 year ago • 6 comments

What happened?

I have created a envSetup.ts file with following content -

import { device } from "detox";
module.exports = async () => {
  await require("detox/runners/jest/index").globalSetup();
  await device.launchApp();
};

And updated the jest.config.js file with- globalSetup: "<rootDir>/e2e/envSetup.ts"

Then I have executed the test - detox test -c android.emu.release -l verbose

Got the error -

12:01:32.379 detox[18527] i ws-server Detox server listening on localhost:56172...
12:01:32.385 detox[18527] B lifecycle jest --config e2e/jest.config.js
12:01:33.847 detox[18530] i user DetoxRuntimeError: Jest: Got error running globalSetup - /Users/jyotsananamdev/detox/detox-framework/e2e/envSetup.ts, reason: 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.
    at get [worker] (/Users/jyotsananamdev/detox/detox-framework/node_modules/detox/src/realms/DetoxContext.js:119:13)
    at /Users/jyotsananamdev/detox/detox-framework/node_modules/detox/src/realms/DetoxContext.js:72:36
    at getter (/Users/jyotsananamdev/detox/detox-framework/node_modules/funpermaproxy/lib/permaproxy.js:10:24)
    at Object.get (/Users/jyotsananamdev/detox/detox-framework/node_modules/funpermaproxy/lib/permaproxy.js:21:22)
    at module.exports (/Users/jyotsananamdev/detox/detox-framework/e2e/envSetup.ts:10:23)
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
    at async /Users/jyotsananamdev/detox/detox-framework/node_modules/@jest/core/build/runGlobalHook.js:109:13
    at async waitForPromiseWithCleanup (/Users/jyotsananamdev/detox/detox-framework/node_modules/@jest/transform/build/ScriptTransformer.js:160:5)
    at async ScriptTransformer.requireAndTranspileModule (/Users/jyotsananamdev/detox/detox-framework/node_modules/@jest/transform/build/ScriptTransformer.js:808:16)
    at async runGlobalHook (/Users/jyotsananamdev/detox/detox-framework/node_modules/@jest/core/build/runGlobalHook.js:101:9)
    at async runJest (/Users/jyotsananamdev/detox/detox-framework/node_modules/@jest/core/build/runJest.js:327:5)
    at async _run10000 (/Users/jyotsananamdev/detox/detox-framework/node_modules/@jest/core/build/cli/index.js:343:7)
    at async runCLI (/Users/jyotsananamdev/detox/detox-framework/node_modules/@jest/core/build/cli/index.js:198:3)
    at async Object.run (/Users/jyotsananamdev/detox/detox-framework/node_modules/jest-cli/build/run.js:130:37)
  origin: at node_modules/jest-cli/build/run.js:136:15
12:01:33.991 detox[18527] E lifecycle Command failed with exit code = 1:
jest --config e2e/jest.config.js
12:01:34.094 detox[18527] i ws-server Detox server has been closed gracefully

What was the expected behaviour?

This should launch app

Was it tested on latest Detox?

  • [X] I have tested this issue on the latest Detox release and it still reproduces.

Help us reproduce this issue!

No response

In what environment did this happen?

Detox version: 20.14.3 React Native version: 0.72.7 Has Fabric (React Native's new rendering system) enabled: (yes/no) Node version: v18.15.0 Test-runner (select one): jest / other -jest

Detox logs

Detox logs
paste logs here!

Device logs

Device logs
paste logs here!

More data, please!

No response

jyotsna-hh avatar Dec 22 '23 06:12 jyotsna-hh

Detox doesn't support creating devices in globalSetup. Please use the official setup guide on the website: https://wix.github.io/Detox

noomorph avatar Dec 22 '23 06:12 noomorph

@noomorph Can we create devices globally in detox ?

jyotsna-hh avatar Dec 22 '23 07:12 jyotsna-hh

What do you mean, @jyotsna-hh ?

noomorph avatar Dec 22 '23 09:12 noomorph

Right now I'm using await device.launchApp(); command in each script instead I wanted to run it once for all my test scripts. @noomorph

jyotsna-hh avatar Dec 22 '23 10:12 jyotsna-hh

You should use beforeAll() hook in a file under setupFilesAfterEnv. Please refer to Jest documentation

noomorph avatar Dec 22 '23 10:12 noomorph

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 repository, read this discussion.

stale[bot] avatar Mar 17 '24 08:03 stale[bot]