Detox on Android - can't run tests in parallel - react-native

I'm trying to speed up my detox e2e tests on Android so I thought I'll try to run them on multiple devices. I was able to easily do the same on iOS using the --workers flag but that doesn't seem to work at all on Android.
Here is my relevant detox config piece:
"android.sim.debug": {
"binaryPath": "...",
"build": "...",
"type": "android.attached",
"name": ".*"
},
Then I'm using this command to run the tests:
detox test --configuration android.sim.debug --workers 2
What I tried to do:
I fired up 2 emulators
I run detox tests with the command above
But the tests are only running on one of the emulators, the other one is being ignored
Any suggestions how can I run these tests on multiple emulators?

Related

Detox successfully builds but does not install app on Android emulator

I'm getting a successful detox build, and the emulator starts up, but the app is just never installed.
react-native run-android (without Detox) works fine.
The only error I'm seeing (including in verbose mode) is: "No instrumentation runner found", but I'm guessing that just means Detox can't find the app (which was never installed).
How can I get Detox to actually install the app onto the emulator? The only clue I see is that the package name has .test appended in this case which may be an issue, but I'm not at all sure of that.
(I tried to adb install the test app but that doesn't fix the issue, and also nothing shows up in the emulator when I run the command: adb -e install android/app/build/outputs/apk/androidTest/debug/app-debug-androidTest.apk. This installation command works fine for our standard debug apk.)
Log:
BUILD SUCCESSFUL in 25s
1029 actionable tasks: 1 executed, 1028 up-to-date
detox[66003] INFO: [test.js] configuration="android.emu.debug" reportSpecs=true readOnlyEmu=false useCustomLogger=true forceAdbInstall=false DETOX_START_TIMESTAMP=1597412615185 node_modules/.bin/jest --config e2e/config.json '--testNamePattern=^((?!:ios:).)*$' --maxWorkers 1 e2e
detox[66004] INFO: [DetoxServer.js] server listening on localhost:55217...
detox[66004] ERROR: Error: No instrumentation runner found on device emulator-11448 for package com.myco.myapp.test
detox[66004] INFO: Example is assigned to undefined
detox[66004] INFO: Example: should have welcome screen
detox[66004] INFO: Example: should have welcome screen [SKIPPED]
detox[66003] ERROR: [cli.js] Error: Command failed: node_modules/.bin/jest --config e2e/config.json '--testNamePattern=^((?!:ios:).)*$' --maxWorkers 1 e2e
detoxrc entry:
"android.emu.debug": {
"binaryPath": "android/app/build/outputs/apk/androidTest/debug/app-debug-androidTest.apk",
"testBinaryPath": "android/app/build/outputs/apk/androidTest/debug/app-debug-androidTest.apk",
"build": "cd android && ./gradlew assembleDebug assembleAndroidTest -DtestBuildType=debug && cd ..",
"type": "android.emulator",
"device": {
"avdName": "Pixel_API_28_AOSP"
}
},
This had to do with APK paths. Detox tries to compute a debug APK path, and if it's wrong it will come up with these errors. (If you build multiple versions of your APKs for different architectures, Detox doesn't appear to be able to handle that.)
The solution is to point to both of your APKs - the debug app ("binary"), and the instrumentation APK ("test binary"):
"binaryPath": "android/app/build/outputs/apk/debug/app-x86_64-debug.apk",
"testBinaryPath": "android/app/build/outputs/apk/androidTest/debug/app-debug-androidTest.apk",

Running Eslint and Nextjs development server at the same time

I want to integrate Eslint in my Nextjs application and prefer to run Eslint simultaneously with the development server. I have two scripts, namely server and lint and want to run them at the same time. I tried to implement it via dev script, but the development server seems not to be reloading on file changes in this implementation. Is there any way to run the two simultaneously?
"scripts": {
"dev": "npm run server && npm run lint",
"server": "next -p 7777"
"lint": "esw --fix components/**/*.js lib/**/*.js pages/**/*js"
}

detox app could not be found, did you run './gradlew assembleAndroidTest'?

I am doing detox test for react native android version 0.57. I am getting this error.
Error is
Error: 'D:\folder\android\app\build\outputs\apk\androidTest\dev\debug\app-dev-debug-androidTest.apk' could not be found, did you run './gradlew assembleAndroidTest' ?
Package.json
"android.emu.debug": {
"binaryPath": "android/app/build/outputs/apk/dev/debug/app-dev-debug.apk",
"build": "cd android && .\\gradlew assembleDebug assembleAndroidTest -DtestBuildType=debug && cd ..",
"type": "android.attached",
"name": "192.168.83.101:5555"
}
Error picture
Detox has strange behavior where it mutates your path to your apk, if you specify it using binaryPath.
To specify the exact path to your apk, add an entry for testBinaryPath that points to the APK you want Detox to use.
This error is usually caused but not having built the test apk. It can usually be resolved by running
detox build -c android.emu.debug
If you make changes to your application you should always run the above script before running any test.
I usually run the following script to make sure that the build is uptodate before testing.
detox build -c android.emu.debug && detox test -c android.emu.debug
change path android/app/build/outputs/apk/dev/debug/app-dev-debug.apk to android/app/build/outputs/apk/debug/app-debug.apk
and detox automatically will create apk to path android/app/build/outputs/apk/AndroidTest/debug/app-debug-androidTest.apk

Jest tests broken after implementing detox

I'd like to be able to run my detox tests and my Jest unit tests separately. For example, run detox tests with detox build && detox test, and my Jest unit tests with npm test.
After implementing detox (using mocha as the test runner), running npm test results in immediate error, and looks like its trying to run my detox tests (not what I'd expect)! Here's the first error I get.
FAIL e2e/auth.spec.js
Not sure why its trying to run detox tests, when my package.json is pointing the test script to Jest.
"scripts": {
"start": "node node_modules/react-native/local-cli/cli.js start",
"test": "jest"
}
How do I run my jest tests now?
By default jest runs all files in your project directory, that have the .test. or .spec. extension to them. That's why it picks up your detox test files and fails to execute them.
https://facebook.github.io/jest/docs/en/configuration.html#testmatch-array-string
You have to override this default behavior in order for the two not to clash. Here's what we use in our package.json just for reference, you might want to change it:
"jest": {
"testMatch": [
"<rootDir>/__tests__/**/*.test.js?(x)",
"<rootDir>/src/**/*.test.js"
]
}
If you dont keep you files in on folder like tests just add this to package.json
"jest": {
"testMatch": ["**/*+(.test.js)"]
}

How can I get the full test output from mocha with spec?

I've just installed mocha and am using fairly basic settings to run 2 tests, but it won't output all the results.
I am expecting to see:
foo
bar
√ does thing
baz
√ does other thing
but I am only seeing the first 2-4 lines (varies with no discernible pattern). It seems there's some sort of time-dependent element here, but I have no idea how to approach fixing it.
The environment is cygwin under Windows 8.
I am running mocha by running npm test.
My test command in package.json is mocha test/*.js -R spec.
Any luck finding an answer?
I'm on a different OS and your config looks good.
Works in my package.json:
"scripts": {
"test": "mocha -R spec"
}