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

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

Closed
stellae13 opened this issue Jan 28, 2024 · 13 comments

Comments

@stellae13
Copy link

Description

Hi everyone! I am working on my first React Native Project and have wanted to start doing some behavioral testing. I am getting the following issue when trying to run Detox.

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.

   6 |     //await detox.init();
   7 |     //detox.installWorker();
>  8 |     await device.launchApp();
     |                  ^
   9 |   });
  10 |
  11 |   beforeEach(async () => {

  at DetoxSecondaryContext.get [worker] (node_modules/detox/src/realms/DetoxContext.js:119:13)    
  at node_modules/detox/src/realms/DetoxContext.js:72:36
  at _next (node_modules/@babel/runtime/helpers/asyncToGenerator.js:22:9)
  at node_modules/@babel/runtime/helpers/asyncToGenerator.js:27:7
  at Object.<anonymous> (node_modules/@babel/runtime/helpers/asyncToGenerator.js:19:12)

I have seen other people post about having the same error, but the solutions they have found don't seem to work for me. This is my current .detoxrc.cjs file. I haven't changed anything from the default besides removing unnecessary IOS configurations since I am using Andriod.

 /** @type {Detox.DetoxConfig} */
module.exports = {
testRunner: {
args: {
  '$0': 'jest',
   config: 'e2e/jest.config.js'
 },
jest: {
  setupTimeout: 120000
}
},
apps: {
'android.debug': {
  type: 'android.apk',
  binaryPath: 'android/app/build/outputs/apk/debug/app-debug.apk',
  build: 'cd android && ./gradlew assembleDebug assembleAndroidTest -DtestBuildType=debug',
  reversePorts: [
    8081
  ]
},
'android.release': {
  type: 'android.apk',
  binaryPath: 'android/app/build/outputs/apk/release/app-release.apk',
  build: 'cd android && ./gradlew assembleRelease assembleAndroidTest -DtestBuildType=release'
}
},
devices: {
emulator: {
  type: 'android.emulator',
  device: {
    avdName: 'Nexus_5X_API_34'
  }
 }
},
configurations: {
'android.att.debug': {
  device: 'emulator',
  app: 'android.debug'
},
'android.att.release': {
  device: 'emulator',
  app: 'android.release'
},
'android.emu.debug': {
  device: 'emulator',
  app: 'android.debug'
},
'android.emu.release': {
  device: 'emulator',
  app: 'android.release'
}
}};

When I run detox test ... --record-logs all:

  [
{"ph":"M","args":{"name":"primary"},"ts":1706424705017000,"tid":0,"pid":12504,"name":"process_name"},
{"ph":"M","args":{"sort_index":0},"ts":1706424705017000,"tid":0,"pid":12504,"name":"process_sort_index"},
{"ph":"M","args":{"name":"lifecycle"},"ts":1706424705017000,"tid":0,"pid":12504,"name":"thread_name"},
{"ph":"M","args":{"sort_index":0},"ts":1706424705017000,"tid":0,"pid":12504,"name":"thread_sort_index"},
{"ph":"B","name":"node_modules\\detox\\local-cli\\cli.js test ... --record-logs 
   all","pid":12504,"tid":0,"cat":"lifecycle","ts":1706424705017000,"args": 
 {"level":10,"cwd":"C:\\Users\\stell\\OneDrive\\Desktop\\Capstone\\Testing\\NeedANameBro\\Palate","data":{"id":"adf220c9- 
6136-191e-3e98-d743e8fdfaf5","detoxConfig":{"configurationName":"android.emu.debug","apps":{"default":{"type":"android.apk","binaryPath":"android/app/build/outputs/apk/debug/app-debug.apk"}},"artifacts":{"rootDir":"artifacts\\android.emu.debug.2024-01-28 06-51-45Z","plugins":{"log":{"enabled":true,"keepOnlyFailedTestsArtifacts":false},"screenshot":{"enabled":true,"shouldTakeAutomaticSnapshots":false,"keepOnlyFailedTestsArtifacts":false},"video":{"enabled":false,"keepOnlyFailedTestsArtifacts":false},"instruments":{"enabled":false,"keepOnlyFailedTestsArtifacts":false},"uiHierarchy":{"enabled":false,"keepOnlyFailedTestsArtifacts":false}}},"behavior":{"init":{"keepLockFile":false,"reinstallApp":true,"exposeGlobals":true},"cleanup":{"shutdownDevice":false},"launchApp":"auto"},"cli":{"recordLogs":"all","start":true},"device":{"type":"android.emulator","device":{"avdName":"undefined"}},"logger":{"level":"info","overrideConsole":true,"options":{"showLoggerName":true,"showPid":true,"showLevel":false,"showMetadata":false,"basepath":"C:\\Users\\stell\\OneDrive\\Desktop\\Capstone\\Testing\\NeedANameBro\\Palate\\node_modules\\detox\\src","prefixers":{},"stringifiers":{}}},"testRunner":{"retries":0,"forwardEnv":false,"detached":false,"bail":false,"jest":{"setupTimeout":300000,"teardownTimeout":30000,"retryAfterCircusRetries":false,"reportWorkerAssign":true},"args":{"$0":"jest","_":["..."],"--":[]}},"session":{"autoStart":true,"debugSynchronization":10000}},"detoxIPCServer":"primary-12504","testResults":[],"testSessionIndex":0,"workersCount":0},"v":0}},
{"ph":"M","args":{"name":"ipc"},"ts":1706424705068000,"tid":1,"pid":12504,"name":"thread_name"},
{"ph":"M","args":{"sort_index":1},"ts":1706424705068000,"tid":1,"pid":12504,"name":"thread_sort_index"},
{"ph":"i","name":"Server path not specified, so defaulting to ipc.config.socketRoot + ipc.config.appspace + ipc.config.id /tmp/detox.primary-12504","pid":12504,"tid":1,"cat":"ipc,ipc-server","ts":1706424705068000,"args":{"level":10,"v":0}},
{"ph":"i","name":"starting server on  /tmp/detox.primary-12504 ","pid":12504,"tid":1,"cat":"ipc,ipc-server","ts":1706424705073000,"args":{"level":10,"v":0}},
{"ph":"i","name":"starting TLS server false","pid":12504,"tid":1,"cat":"ipc,ipc-server","ts":1706424705073000,"args":{"level":10,"v":0}},
{"ph":"i","name":"starting server as Unix || Windows Socket","pid":12504,"tid":1,"cat":"ipc,ipc-server","ts":1706424705073000,"args":{"level":10,"v":0}},
{"ph":"M","args":{"name":"ws-server"},"ts":1706424705079000,"tid":2,"pid":12504,"name":"thread_name"},
{"ph":"M","args":{"sort_index":2},"ts":1706424705079000,"tid":2,"pid":12504,"name":"thread_sort_index"},
{"ph":"i","name":"Detox server listening on localhost:61639...","pid":12504,"tid":2,"cat":"ws-server,ws","ts":1706424705079000,"args":{"level":20,"v":0}},
{"ph":"i","name":"Serialized the session state at: C:\\Users\\stell\\AppData\\Local\\Temp\\adf220c9-6136-191e-3e98-d743e8fdfaf5.detox.json","pid":12504,"tid":0,"cat":"lifecycle","ts":1706424705091000,"args":{"level":10,"v":0}},
{"ph":"B","name":"jest ...","pid":12504,"tid":0,"cat":"lifecycle,cli","ts":1706424705093000,"args":{"level":30,"env":{},"v":0}},
{"ph":"M","args":{"name":"secondary"},"ts":1706424708885000,"tid":0,"pid":15376,"name":"process_name"},
{"ph":"M","args":{"sort_index":1},"ts":1706424708885000,"tid":0,"pid":15376,"name":"process_sort_index"},
{"ph":"M","args":{"name":"user"},"ts":1706424708885000,"tid":3,"pid":15376,"name":"thread_name"},
{"ph":"M","args":{"sort_index":3},"ts":1706424708885000,"tid":3,"pid":15376,"name":"thread_sort_index"},
{"ph":"i","name":"undefined","pid":15376,"tid":3,"cat":"user","ts":1706424708885000,"args":{"level":30,"origin":"at e2e\\starter.test.js:9:9","v":0}},
{"ph":"E","pid":12504,"tid":0,"cat":"lifecycle,cli","ts":1706424709079000,"args":{"level":50,"success":false,"code":1,"signal":null,"v":0}},
{"ph":"i","name":"Detox server has been closed gracefully","pid":12504,"tid":2,"cat":"ws-server,ws","ts":1706424709081000,"args":{"level":20,"v":0}},
{"ph":"E","pid":12504,"tid":0,"cat":"lifecycle","ts":1706424709084000,"args":{"level":10,"v":0}}

]

Thanks in advance for anyone who takes the time to look!

Your environment

Detox version: 20.17.0
React Native version: 0.72.6
Node version: 18.18.0
Device model: Andriod
OS: Windows
Test-runner (select one): jest

@noomorph
Copy link
Collaborator

noomorph commented Jan 28, 2024

Could you re-run your tests, but with appending --showConfig? This will make Jest show your resolved config.

@stellae13
Copy link
Author

Here ya go! @noomorph

{
"configs": [
{
"automock": false,
"cache": true,
"cacheDirectory": "C:\Users\stell\AppData\Local\Temp\jest",
"clearMocks": false,
"collectCoverageFrom": [],
"coverageDirectory": "C:\Users\stell\OneDrive\Desktop\Capstone\Testing\NeedANameBro\Palate\coverage",
"coveragePathIgnorePatterns": [
"\\node_modules\\"
],
"cwd": "C:\Users\stell\OneDrive\Desktop\Capstone\Testing\NeedANameBro\Palate",
"detectLeaks": false,
"detectOpenHandles": false,
"errorOnDeprecated": false,
"extensionsToTreatAsEsm": [],
"fakeTimers": {
"enableGlobally": false
},
"forceCoverageMatch": [],
"globals": {},
"haste": {
"defaultPlatform": "ios",
"platforms": [
"android",
"ios",
"native"
]
},
"id": "2135485d8190a14f399f16a6c7191711",
"injectGlobals": true,
"moduleDirectories": [
"node_modules"
],
"moduleFileExtensions": [
"js",
"mjs",
"cjs",
"jsx",
"ts",
"tsx",
"json",
"node"
],
"moduleNameMapper": [],
"modulePathIgnorePatterns": [],
"openHandlesTimeout": 1000,
"prettierPath": "prettier",
"resetMocks": false,
"resetModules": false,
"restoreMocks": false,
"rootDir": "C:\Users\stell\OneDrive\Desktop\Capstone\Testing\NeedANameBro\Palate",
"roots": [
"C:\Users\stell\OneDrive\Desktop\Capstone\Testing\NeedANameBro\Palate"
],
"runner": "C:\Users\stell\OneDrive\Desktop\Capstone\Testing\NeedANameBro\Palate\node_modules\jest-runner\build\index.js",
"sandboxInjectedGlobals": [],
"setupFiles": [
"C:\Users\stell\OneDrive\Desktop\Capstone\Testing\NeedANameBro\Palate\node_modules\react-native\jest\setup.js"
],
"setupFilesAfterEnv": [
"C:\Users\stell\OneDrive\Desktop\Capstone\Testing\NeedANameBro\Palate\node_modules\react-native\jest\setup.js"
],
"skipFilter": false,
"slowTestThreshold": 5,
"snapshotFormat": {
"escapeString": false,
"printBasicPrototype": false
},
"snapshotSerializers": [],
"testEnvironment": "C:\Users\stell\OneDrive\Desktop\Capstone\Testing\NeedANameBro\Palate\node_modules\react-native\jest\react-native-env.js",
"testEnvironmentOptions": {},
"testLocationInResults": false,
"testMatch": [
"C:/Users/stell/OneDrive/Desktop/Capstone/Testing/NeedANameBro/Palate/e2e/**/*.test.js"
],
"testPathIgnorePatterns": [
".\\node_modules\\"
],
"testRegex": [],
"testRunner": "C:\Users\stell\OneDrive\Desktop\Capstone\Testing\NeedANameBro\Palate\node_modules\jest-circus\runner.js",
"transform": [
[
"^.+\.(js|ts|tsx)$",
"C:\Users\stell\OneDrive\Desktop\Capstone\Testing\NeedANameBro\Palate\node_modules\babel-jest\build\index.js",
{}
],
[
"^.+\.(bmp|gif|jpg|jpeg|mp4|png|psd|svg|webp)$",
"C:\Users\stell\OneDrive\Desktop\Capstone\Testing\NeedANameBro\Palate\node_modules\react-native\jest\assetFileTransformer.js",
{}
]
],
"transformIgnorePatterns": [
"node_modules\\(?!((jest-)?react-native|@react-native(-community)?)\\)"
],
"watchPathIgnorePatterns": []
}
],
"globalConfig": {
"bail": 0,
"changedFilesWithAncestor": false,
"ci": false,
"collectCoverage": false,
"collectCoverageFrom": [],
"coverageDirectory": "C:\Users\stell\OneDrive\Desktop\Capstone\Testing\NeedANameBro\Palate\coverage",
"coverageProvider": "babel",
"coverageReporters": [
"json",
"text",
"lcov",
"clover"
],
"detectLeaks": false,
"detectOpenHandles": false,
"errorOnDeprecated": false,
"expand": false,
"findRelatedTests": false,
"forceExit": false,
"json": false,
"lastCommit": false,
"listTests": false,
"logHeapUsage": false,
"maxConcurrency": 5,
"maxWorkers": 7,
"noStackTrace": false,
"nonFlagArgs": [
"..."
],
"notify": false,
"notifyMode": "failure-change",
"onlyChanged": false,
"onlyFailures": false,
"openHandlesTimeout": 1000,
"passWithNoTests": false,
"projects": [],
"rootDir": "C:\Users\stell\OneDrive\Desktop\Capstone\Testing\NeedANameBro\Palate",
"runTestsByPath": false,
"seed": -312102663,
"skipFilter": false,
"snapshotFormat": {
"escapeString": false,
"printBasicPrototype": false
},
"testFailureExitCode": 1,
"testPathPattern": "...",
"testSequencer": "C:\Users\stell\OneDrive\Desktop\Capstone\Testing\NeedANameBro\Palate\node_modules\@jest\test-sequencer\build\index.js",
"updateSnapshot": "new",
"useStderr": false,
"watch": false,
"watchAll": false,
"watchman": true,
"workerThreads": false
},
"version": "29.7.0"
}

@devartwa
Copy link

devartwa commented Feb 6, 2024

I'm facing the same error, here's my config:

{ "configs": [ { "automock": false, "cache": true, "cacheDirectory": "/private/var/folders/z3/rplvj9fj7llgzt9l8gv5sb1w0000gn/T/jest_dx", "clearMocks": false, "collectCoverageFrom": [ "**/*.{ts,tsx,js,jsx}", "!**/android/**/*.{ts,tsx,js,jsx}", "!**/ios/**/*.{ts,tsx,js,jsx}", "!**/screens/**/*.{ts,tsx,js,jsx}", "!**/store/**/*.{ts,tsx,js,jsx}", "!**/context/**/*.{ts,tsx,js,jsx}", "!**/coverage/**/*.{ts,tsx,js,jsx}", "!/mocks/**/*.{ts,tsx,js,jsx}", "!index.js", "!App.tsx" ], "coverageDirectory": "/Users/arthur/Dev/getahead-frontend/coverage", "coveragePathIgnorePatterns": [ "/node_modules/", "/assets/", "babel.config.js", "__mocks__/", "metro.config.js", "react-native.config.js" ], "cwd": "/Users/arthur/Dev/getahead-frontend", "detectLeaks": false, "detectOpenHandles": false, "errorOnDeprecated": false, "extensionsToTreatAsEsm": [], "fakeTimers": { "enableGlobally": false }, "forceCoverageMatch": [], "globals": {}, "haste": { "defaultPlatform": "ios", "platforms": [ "android", "ios", "native" ] }, "id": "7bb5f0da00ff28614d61284990dc39c4", "injectGlobals": true, "moduleDirectories": [ "node_modules" ], "moduleFileExtensions": [ "ts", "tsx", "js", "jsx", "json", "node" ], "moduleNameMapper": [ [ "\\.(jpg|jpeg|png|gif|eot|otf|webp|svg|ttf|woff|woff2|mp4|webm|wav|mp3|m4a|aac|oga)$", "/Users/arthur/Dev/getahead-frontend/__mocks__/fileMock.js" ], [ "\\.(css|less)$", "/Users/arthur/Dev/getahead-frontend/__mocks__/styleMock.js" ] ], "modulePathIgnorePatterns": [], "openHandlesTimeout": 1000, "prettierPath": "prettier", "resetMocks": false, "resetModules": false, "restoreMocks": false, "rootDir": "/Users/arthur/Dev/getahead-frontend", "roots": [ "/Users/arthur/Dev/getahead-frontend" ], "runner": "/Users/arthur/Dev/getahead-frontend/node_modules/jest-runner/build/index.js", "sandboxInjectedGlobals": [], "setupFiles": [ "/Users/arthur/Dev/getahead-frontend/node_modules/react-native/jest/setup.js", "/Users/arthur/Dev/getahead-frontend/jest/setup.js", "/Users/arthur/Dev/getahead-frontend/node_modules/@react-native-google-signin/google-signin/jest/build/setup.js" ], "setupFilesAfterEnv": [], "skipFilter": false, "slowTestThreshold": 5, "snapshotFormat": { "escapeString": false, "printBasicPrototype": false }, "snapshotSerializers": [ "/Users/arthur/Dev/getahead-frontend/node_modules/jest-snapshot-serializer-ansi/lib/index.js" ], "testEnvironment": "/Users/arthur/Dev/getahead-frontend/node_modules/jest-environment-node/build/index.js", "testEnvironmentOptions": {}, "testLocationInResults": false, "testMatch": [ "**/__tests__/**/*.[jt]s?(x)", "**/?(*.)+(spec|test).[tj]s?(x)" ], "testPathIgnorePatterns": [ "/node_modules/", "/assets/", "babel.config.js", "__mocks__/", "metro.config.js", "react-native.config.js" ], "testRegex": [], "testRunner": "/Users/arthur/Dev/getahead-frontend/node_modules/jest-circus/runner.js", "transform": [ [ "^.+\\.(js|ts|tsx)$", "/Users/arthur/Dev/getahead-frontend/node_modules/@jest/core/node_modules/babel-jest/build/index.js", {} ], [ "^.+\\.(bmp|gif|jpg|jpeg|mp4|png|psd|svg|webp)$", "/Users/arthur/Dev/getahead-frontend/node_modules/react-native/jest/assetFileTransformer.js", {} ] ], "transformIgnorePatterns": [ "node_modules/(?!(jest-)?react-native|@react-native|react-native-reanimated|@gorhom|react-navigation|@invertase/react-native-apple-authentication|@react-navigation/.*|.*)" ], "watchPathIgnorePatterns": [] } ], "globalConfig": { "bail": 0, "changedFilesWithAncestor": false, "ci": false, "collectCoverage": true, "collectCoverageFrom": [ "**/*.{ts,tsx,js,jsx}", "!**/android/**/*.{ts,tsx,js,jsx}", "!**/ios/**/*.{ts,tsx,js,jsx}", "!**/screens/**/*.{ts,tsx,js,jsx}", "!**/store/**/*.{ts,tsx,js,jsx}", "!**/context/**/*.{ts,tsx,js,jsx}", "!**/coverage/**/*.{ts,tsx,js,jsx}", "!/mocks/**/*.{ts,tsx,js,jsx}", "!index.js", "!App.tsx" ], "coverageDirectory": "/Users/arthur/Dev/getahead-frontend/coverage", "coverageProvider": "babel", "coverageReporters": [ "lcov", "text", "html" ], "detectLeaks": false, "detectOpenHandles": false, "errorOnDeprecated": false, "expand": false, "findRelatedTests": false, "forceExit": false, "json": false, "lastCommit": false, "listTests": false, "logHeapUsage": false, "maxConcurrency": 5, "maxWorkers": 11, "noStackTrace": false, "nonFlagArgs": [], "notify": false, "notifyMode": "failure-change", "onlyChanged": false, "onlyFailures": false, "openHandlesTimeout": 1000, "passWithNoTests": false, "projects": [], "reporters": [ [ "default", {} ], [ "/Users/arthur/Dev/getahead-frontend/node_modules/jest-sonar/index.js", { "outputDirectory": "coverage", "outputName": "jest-report.xml", "reportedFilePath": "absolute" } ] ], "rootDir": "/Users/arthur/Dev/getahead-frontend", "runTestsByPath": false, "seed": -825779784, "skipFilter": false, "snapshotFormat": { "escapeString": false, "printBasicPrototype": false }, "testFailureExitCode": 1, "testPathPattern": "", "testSequencer": "/Users/arthur/Dev/getahead-frontend/node_modules/@jest/test-sequencer/build/index.js", "updateSnapshot": "new", "useStderr": false, "watch": false, "watchAll": false, "watchman": true, "workerThreads": false }, "version": "29.7.0" }

@noomorph
Copy link
Collaborator

noomorph commented Feb 6, 2024

I hope I located your issue correctly.

#4358

UPD: the PR was merged, we'll release a version soon.

@noomorph
Copy link
Collaborator

noomorph commented Feb 7, 2024

@stellae13, please update your Detox version to 20.17.1 (latest), and let me know if it already can see your .detoxrc.cjs

@devartwa
Copy link

devartwa commented Feb 7, 2024

@noomorph I'm facing the same issue, I've updated the version, still the same.

@noomorph
Copy link
Collaborator

noomorph commented Feb 8, 2024

@devartwa, well, I was fixing the original issue, not your issue. Do you have .detoxrc.cjs (CJS)? If not, then you have a different issue.

@devartwa
Copy link

devartwa commented Feb 8, 2024

@devartwa, well, I was fixing the original issue, not your issue. Do you have .detoxrc.cjs (CJS)? If not, then you have a different issue.

my bad.
no, I don't.
should it be .cjs? because I got the .detoxrc.js

@noomorph
Copy link
Collaborator

noomorph commented Feb 8, 2024

So you piggybacked on a non-related issue, @devartwa . Please create your own one with more details.

@devartwa
Copy link

devartwa commented Feb 8, 2024

@noomorph alright, but I got the same error, that's why I'm reporting here.
anyway, I'll open an issue.

@devartwa
Copy link

devartwa commented Feb 8, 2024

@noomorph #4362

@stellae13
Copy link
Author

@noomorph Sorry for the late response! I have updated to the 20.17.1 and restarted everything to make sure the update took effect. When I run npm test or npx jest I still get the same error but if I run detox test --configuration android.emu.debug it works fine now

@noomorph
Copy link
Collaborator

noomorph commented Feb 8, 2024

@stellae13 it is not possible to run npx jest as-is. The detox test command passes a few essential parameters and environment variables in order to make it work. Vanilla jest command is usually meant to run unit tests.

@noomorph noomorph closed this as completed Feb 8, 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

3 participants