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

Problems on Android using Jest test runner #362

Closed
SMJ93 opened this issue Oct 24, 2017 · 6 comments
Closed

Problems on Android using Jest test runner #362

SMJ93 opened this issue Oct 24, 2017 · 6 comments

Comments

@SMJ93
Copy link
Contributor

SMJ93 commented Oct 24, 2017

Description

We have switched test runners from Mocha to Jest using the instruction guide here, but there seem to be a few issues:

  1. Verbose is always enabled

With mocha we would add the flag for this to be enabled: --loglevel verbose

  1. When running android build and test the instrumentation is never created casing an error
detox build --configuration android.emu.debug && detox test --configuration android.emu.debug
mulator stdout:
 : /Users/user/Library/Android/sdk/platform-tools/adb  devices
 List of devices attached
 emulator-5554	device
 : stdout:
 : stdout:
3: /Users/user/Library/Android/sdk/platform-tools/adb -s emulator-5554 shell input  keyevent 82
4: /Users/user/Library/Android/sdk/platform-tools/adb -s emulator-5554 shell am force-stop com.appname.dev
adb -s emulator-5554 shell am instrument -w -r -e detoxServer ws://localhost:8099 -e detoxSessionId test -e debug false com.appname.dev.test/android.support.test.runner.AndroidJUnitRunner
 25344mentation spawned, childProcess.pid:
 send: {"type":"isReady","params":{},"messageId":-1000}
android.util.AndroidException: INSTRUMENTATION_FAILED: com.appname.dev.test/android.support.test.runner.AndroidJUnitRunner
nstrumentation stderr:
nstrumeat com.android.commands.am.Instrument.run(Instrument.java:410)
nstrumeat com.android.commands.am.Am.runInstrument(Am.java:232)
nstrumeat com.android.commands.am.Am.onRun(Am.java:125)
nstrumeat com.android.internal.os.BaseCommand.run(BaseCommand.java:54)
nstrumeat com.android.commands.am.Am.main(Am.java:95)
nstrumeat com.android.internal.os.RuntimeInit.nativeFinishInit(Native Method)
nstrumeat com.android.internal.os.RuntimeInit.main(RuntimeInit.java:284)
nstrumentation stderr:
nstrumentationProcess terminated due to receipt of signal null

When printing the instrumentation there is no bundle ID for the app we want to test - this used to show with mocha:

adb shell pm list instrumentation

instrumentation:com.android.emulator.smoketests/android.support.test.runner.AndroidJUnitRunner (target=com.android.emulator.smoketests)
instrumentation:com.android.smoketest.tests/com.android.smoketest.SmokeTestRunner (target=com.android.smoketest)
instrumentation:com.example.android.apis/.app.LocalSampleInstrumentation (target=com.example.android.apis)
instrumentation:org.chromium.webview_shell/.WebViewLayoutTestRunner (target=org.chromium.webview_shell)

Looking at the log in detox it doesn't seem to install the apk's onto the device before calling the .
There seems to be an issue installing both the Android app apk com.appname and the test apk com.appname.test when using Jest which then results in the following error:

Steps to Reproduce

Use Jest as the test runner instead of Mocha on Android by following this guide.

Detox, Node, Device, Xcode and macOS Versions

  • Detox: 5.9.1
  • Jest: 21.2.1
  • Node: 8.1.0
  • Device: Nexus_5_API_26
  • macOS: 10.12.6

Here is the detox and jest config in the package.json

"jest": {
    "preset": "react-native",
    "setupTestFrameworkScriptFile": "./e2e/init.js"
  },
"detox": {
    "specs": "e2e",
    "runner": "jest",
    "session": {
      "server": "ws://localhost:8099",
      "sessionId": "test"
    },
    "configurations": {
      "android.emu.debug": {
        "binaryPath": "android/app/build/outputs/apk/app-dev-debug.apk",
        "build": "export ENVFILE=.env.dev && pushd android && ./gradlew assembleDevDebug assembleDevDebugAndroidTest -DtestBuildType=debug && popd",
        "type": "android.emulator",
        "name": "Nexus_5_API_26"
      },
      "android.emu.release": {
        "binaryPath": "android/app/build/outputs/apk/app-dev-release.apk",
        "build": "export ENVFILE=.env.dev && pushd android && ./gradlew assembleDevRelease assembleDevReleaseAndroidTest -DtestBuildType=release && popd",
        "type": "android.emulator",
        "name": "Nexus_5_API_26"
      }
    }
  }
@coderjonny
Copy link

coderjonny commented Dec 21, 2017

Any new updates on this issue?
I'm having a similar issue trying to use Detox + Jest for Android. Seems like it just gets stuck.. Any hints in the source code where it might cause the problem ?

  • node v8.9.3
  • detox@6.0.4
  • jest@22.0.3
  • Android Emulator nexus_5x_api_27_x86
  • macOS 10.13.2
  • Gradle 4.1 (which seems like its causing a separate flavorDimensions issue)

Thanks

@anupamsmaurya
Copy link

@coderjonny I am trying with exact same config. Were you able to setup ReactNative+Detox+Jest for Android?

@prasanth95
Copy link

@anupamsmaurya @coderjonny @SMJ93 Any update on this issue?

@SMJ93
Copy link
Contributor Author

SMJ93 commented Jan 8, 2018

@anupamsmaurya @prasanth95 yes, I was able to get it up and running on both iOS and Android with detox 6.0.2 and Jest 21.2.1.

@anupamsmaurya
Copy link

@SMJ93 For me detox is unable to create app-debug-androidTest.apk can you suggest anything on this stacloverflow post https://stackoverflow.com/questions/48148064/referenceerror-device-is-not-defined-when-using-detoxjest-in-react-native-fo

@SMJ93
Copy link
Contributor Author

SMJ93 commented Jan 8, 2018

@anupamsmaurya Looks like your config may be incorrect. Do the example detox examples work for you?

This is what we have in our package.json:

     "e2e-test-android": "detox build --configuration android.emu.release && detox test --configuration android.emu.release",
    "e2e-test-android-debug": "detox build --configuration android.emu.debug && detox test --configuration android.emu.debug",
    "e2e-test-ios": "detox build --configuration ios.sim.release && detox test --configuration ios.sim.release --cleanup",
    "e2e-test-ios-debug": "detox build --configuration ios.sim.debug && detox test --configuration ios.sim.debug --cleanup"

And the following Detox config:

"detox": {
    "specs": "e2e",
    "test-runner": "jest",
    "runner-config": "./e2e/config.json",
    "session": {
      "server": "ws://localhost:8099",
      "sessionId": "devTest"
    },
    "configurations": {
      "ios.sim.debug": {
        "binaryPath": "ios/build/Build/Products/Debug-iphonesimulator/Dev.app",
        "build": "xcodebuild -workspace ios/productMobile.xcworkspace -scheme Dev -configuration Debug -sdk iphonesimulator -derivedDataPath ios/build",
        "type": "ios.simulator",
        "name": "iPhone 7 10.3"
      },
      "ios.sim.release": {
        "binaryPath": "ios/build/Build/Products/Release-iphonesimulator/Dev.app",
        "build": "xcodebuild -workspace ios/productMobile.xcworkspace -scheme Dev -configuration Release -sdk iphonesimulator -derivedDataPath ios/build",
        "type": "ios.simulator",
        "name": "iPhone 7"
      },
      "android.emu.debug": {
        "binaryPath": "android/app/build/outputs/apk/app-dev-debug.apk",
        "build": "export ENVFILE=.env.dev && pushd android && ./gradlew assembleDevDebug assembleDevDebugAndroidTest -DtestBuildType=debug && popd",
        "type": "android.emulator",
        "name": "Nexus_5X_API_26"
      },
      "android.emu.release": {
        "binaryPath": "android/app/build/outputs/apk/app-dev-release.apk",
        "build": "export ENVFILE=.env.dev && pushd android && ./gradlew assembleDevRelease assembleDevReleaseAndroidTest -DtestBuildType=release && popd",
        "type": "android.emulator",
        "name": "Nexus_5X_API_26"
      }
    }
  }

Hope this helps!

@SMJ93 SMJ93 closed this as completed Jan 8, 2018
@wix wix locked and limited conversation to collaborators Jul 23, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants