Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
1 task done
jyotsna-hh opened this issue Dec 22, 2023 · 6 comments

Comments

@jyotsna-hh
Copy link

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?

  • 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

@noomorph
Copy link
Collaborator

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

@jyotsna-hh
Copy link
Author

@noomorph Can we create devices globally in detox ?

@noomorph
Copy link
Collaborator

What do you mean, @jyotsna-hh ?

@jyotsna-hh
Copy link
Author

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

@noomorph
Copy link
Collaborator

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

Copy link

stale bot commented Mar 17, 2024

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 stale bot added the 🏚 stale label Mar 17, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants