Detox: Error: Detox version 0.57 android

Created on 26 Dec 2018  ·  7Comments  ·  Source: wix/Detox

I am getting "Couldn't find preset "module:metro-react-native-babel-preset" relative to directory" error. I am using react native version 0.57. And while testing I am getting this error.

IMPORTANT: And I have doubt how to run generated apk file using detox without running build command.

Description

detox test
Below error I am getting while excute detox test.

configuration="android.emu.debug" artifactsLocation="artifacts\android.emu.debug.2018-12-26 09-15-08Z" node_modules.binjest e2e --config=e2e/config.json --maxWorkers=1 "--testNamePattern=^((?!:ios:).)*$" FAIL e2efirstTest.spec.js

● Test suite failed to run
Couldn't find preset "module:metro-react-native-babel-preset" relative to directory "D:\project folder"

  at ../node_modules/babel-core/lib/transformation/file/options/option-manager.js:293:19
      at Array.map (<anonymous>)
  at OptionManager.resolvePresets (../node_modules/babel-core/lib/transformation/file/options/option-manager.js:275:20)
  at OptionManager.mergePresets (../node_modules/babel-core/lib/transformation/file/options/option-manager.js:264:10)
  at OptionManager.mergeOptions (../node_modules/babel-core/lib/transformation/file/options/option-manager.js:249:14)
  at OptionManager.init (../node_modules/babel-core/lib/transformation/file/options/option-manager.js:368:12)
  at File.initOptions (../node_modules/babel-core/lib/transformation/file/index.js:212:65)
  at new File (../node_modules/babel-core/lib/transformation/file/index.js:135:24)
  at Pipeline.transform (../node_modules/babel-core/lib/transformation/pipeline.js:46:16)

Test Suites: 1 failed, 1 total
Tests: 0 total
Snapshots: 0 total
Time: 7.751s
Ran all test suites matching /e2e/i with tests matching "^((?!:ios:).)*$".
child_process.js:644
throw err;
^

Error: Command failed: node_modules.binjest e2e --config=e2e/config.json --maxWorkers=1 "--testNamePattern=^((?!:ios:).)*$"
at checkExecSyncError (child_process.js:601:13)
at Object.execSync (child_process.js:641:13)
at runJest (D:project foldernode_modulesdetoxlocal-clidetox-test.js:154:6)
at run (D:project foldernode_modulesdetoxlocal-clidetox-test.js:85:7)
at Object. (D:project foldernode_modulesdetoxlocal-clidetox-test.js:217:1)
at Module._compile (module.js:652:30)
at Object.Module._extensions..js (module.js:663:10)
at Module.load (module.js:565:32)
at tryModuleLoad (module.js:505:12)
at Function.Module._load (module.js:497:3)

My "package.json" contains

"scripts": {
"test": "detox test -c android.emu.debug -l verbose"
},
"detox": {
"test-runner": "jest",
"specs": "e2e",
"runner-config": "e2e/config.json",
"configurations": {
"android.emu.debug": {
"binaryPath": "android/app/build/outputs/apk//debug/app-debug.apk",
"build": "cd android && .\gradlew assembleDebug assembleAndroidTest -DtestBuildType=debug && cd ..",
"type": "android.attached",
"name": "Pixel_2_XL_API_26"
}
}
}

Detox, Node, Device, Xcode and macOS Versions

  • Detox: 9.1.2
  • React Native: 0.57
  • Node: 8.11.1
  • Device: Genymotion
  • Windows: Microsoft 10
🏚 stale

Most helpful comment

I'm having the same issue.

Steps to reproduce:

  1. Create a new react native app with react-native init
  2. Run the app and see the welcome screen without any problems
  3. Add detox as described in the introduction and run detox build
  4. Running detox test will fail with the following output:
$ detox test
configuration="android.emu.debug" artifactsLocation="artifacts/android.emu.debug.2018-12-28 14-54-31Z" node_modules/.bin/jest e2e --config=e2e/config.json --maxWorkers=1 '--testNamePattern=^((?!:ios:).)*$'
 FAIL  e2e/firstTest.spec.js
  ● Test suite failed to run

    Couldn't find preset "module:metro-react-native-babel-preset" relative to directory "/Users/daniel/Projects/javascript/react-native-sensors/tests"

      at ../node_modules/babel-core/lib/transformation/file/options/option-manager.js:293:19
          at Array.map (<anonymous>)
      at OptionManager.resolvePresets (../node_modules/babel-core/lib/transformation/file/options/option-manager.js:275:20)
      at OptionManager.mergePresets (../node_modules/babel-core/lib/transformation/file/options/option-manager.js:264:10)
      at OptionManager.mergeOptions (../node_modules/babel-core/lib/transformation/file/options/option-manager.js:249:14)
      at OptionManager.init (../node_modules/babel-core/lib/transformation/file/options/option-manager.js:368:12)
      at File.initOptions (../node_modules/babel-core/lib/transformation/file/index.js:212:65)
      at new File (../node_modules/babel-core/lib/transformation/file/index.js:135:24)
      at Pipeline.transform (../node_modules/babel-core/lib/transformation/pipeline.js:46:16)

Test Suites: 1 failed, 1 total
Tests:       0 total
Snapshots:   0 total
Time:        0.729s, estimated 3s
Ran all test suites matching /e2e/i with tests matching "^((?!:ios:).)*$".
child_process.js:651
    throw err;
    ^
Error: Command failed: node_modules/.bin/jest e2e --config=e2e/config.json --maxWorkers=1 '--testNamePattern=^((?!:ios:).)*$'
    at checkExecSyncError (child_process.js:611:11)
    at Object.execSync (child_process.js:648:13)
    at runJest (/Users/daniel/Projects/javascript/react-native-sensors/tests/node_modules/detox/local-cli/detox-test.js:154:6)
    at run (/Users/daniel/Projects/javascript/react-native-sensors/tests/node_modules/detox/local-cli/detox-test.js:85:7)
    at Object.<anonymous> (/Users/daniel/Projects/javascript/react-native-sensors/tests/node_modules/detox/local-cli/detox-test.js:217:1)
    at Module._compile (internal/modules/cjs/loader.js:688:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:699:10)
    at Module.load (internal/modules/cjs/loader.js:598:32)
    at tryModuleLoad (internal/modules/cjs/loader.js:537:12)
    at Function.Module._load (internal/modules/cjs/loader.js:529:3)

Now, while keeping the RN packager running, remove the following line from the .babelrc:

  "presets": ["module:metro-react-native-babel-preset"]

When I now run detox test the tests are working and passing.

If I make any changes to the JS code, I need to re-add the line to the .babelrc since the RN package can't recompile the code without it.

Edit 1
Might be related to https://github.com/facebook/metro/issues/242 and https://github.com/facebook/react-native/issues/21241

Edit 2
Updating the e2e/config.json with the following content works for now:

{
    "setupTestFrameworkScriptFile": "./init.js",
    "testEnvironment": "node",
    "transform": {
        "^.+\\.js$": "<rootDir>/../node_modules/react-native/jest/preprocessor.js"
    }
}

All 7 comments

Detox is for iOS only. No support for future Android versions https://github.com/wix/detox/issues/608

Detox is not for iOS only. It is supported on Android, we use it in multiple projects internally, and alos on other open source projects.
React native Navigation: https://jenkins-oss.wixpress.com/job/rnn-android-master/100/console
Detox's CI: https://jenkins-oss.wixpress.com/job/detox-android-56-master/

Official supported versions are here: https://github.com/wix/detox/blob/master/README.md#supported-react-native-versions

There is no issue we know about in RN57 on iOS, the e2e suite passes.
on Android, there's an issue with scroll actions on RN57, a fix is pending, and basically, that's the reason why the readme still states otherwise.

If you don't know an answer to a question, please do not give false information.

Regarding the original question, it seems to be a compilation issue, and I think it's quite popular with projects who upgraded to RN57. Are you running Detox with Jest? Your configuration might be broken. I would also guess that if you'd run the same test with no Detox code in your tests, you will get the same error.

I'm having the same issue.

Steps to reproduce:

  1. Create a new react native app with react-native init
  2. Run the app and see the welcome screen without any problems
  3. Add detox as described in the introduction and run detox build
  4. Running detox test will fail with the following output:
$ detox test
configuration="android.emu.debug" artifactsLocation="artifacts/android.emu.debug.2018-12-28 14-54-31Z" node_modules/.bin/jest e2e --config=e2e/config.json --maxWorkers=1 '--testNamePattern=^((?!:ios:).)*$'
 FAIL  e2e/firstTest.spec.js
  ● Test suite failed to run

    Couldn't find preset "module:metro-react-native-babel-preset" relative to directory "/Users/daniel/Projects/javascript/react-native-sensors/tests"

      at ../node_modules/babel-core/lib/transformation/file/options/option-manager.js:293:19
          at Array.map (<anonymous>)
      at OptionManager.resolvePresets (../node_modules/babel-core/lib/transformation/file/options/option-manager.js:275:20)
      at OptionManager.mergePresets (../node_modules/babel-core/lib/transformation/file/options/option-manager.js:264:10)
      at OptionManager.mergeOptions (../node_modules/babel-core/lib/transformation/file/options/option-manager.js:249:14)
      at OptionManager.init (../node_modules/babel-core/lib/transformation/file/options/option-manager.js:368:12)
      at File.initOptions (../node_modules/babel-core/lib/transformation/file/index.js:212:65)
      at new File (../node_modules/babel-core/lib/transformation/file/index.js:135:24)
      at Pipeline.transform (../node_modules/babel-core/lib/transformation/pipeline.js:46:16)

Test Suites: 1 failed, 1 total
Tests:       0 total
Snapshots:   0 total
Time:        0.729s, estimated 3s
Ran all test suites matching /e2e/i with tests matching "^((?!:ios:).)*$".
child_process.js:651
    throw err;
    ^
Error: Command failed: node_modules/.bin/jest e2e --config=e2e/config.json --maxWorkers=1 '--testNamePattern=^((?!:ios:).)*$'
    at checkExecSyncError (child_process.js:611:11)
    at Object.execSync (child_process.js:648:13)
    at runJest (/Users/daniel/Projects/javascript/react-native-sensors/tests/node_modules/detox/local-cli/detox-test.js:154:6)
    at run (/Users/daniel/Projects/javascript/react-native-sensors/tests/node_modules/detox/local-cli/detox-test.js:85:7)
    at Object.<anonymous> (/Users/daniel/Projects/javascript/react-native-sensors/tests/node_modules/detox/local-cli/detox-test.js:217:1)
    at Module._compile (internal/modules/cjs/loader.js:688:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:699:10)
    at Module.load (internal/modules/cjs/loader.js:598:32)
    at tryModuleLoad (internal/modules/cjs/loader.js:537:12)
    at Function.Module._load (internal/modules/cjs/loader.js:529:3)

Now, while keeping the RN packager running, remove the following line from the .babelrc:

  "presets": ["module:metro-react-native-babel-preset"]

When I now run detox test the tests are working and passing.

If I make any changes to the JS code, I need to re-add the line to the .babelrc since the RN package can't recompile the code without it.

Edit 1
Might be related to https://github.com/facebook/metro/issues/242 and https://github.com/facebook/react-native/issues/21241

Edit 2
Updating the e2e/config.json with the following content works for now:

{
    "setupTestFrameworkScriptFile": "./init.js",
    "testEnvironment": "node",
    "transform": {
        "^.+\\.js$": "<rootDir>/../node_modules/react-native/jest/preprocessor.js"
    }
}

@dbanck's solution works, god bless you!

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.

The issue has been closed for inactivity.

Was this page helpful?
0 / 5 - 0 ratings