Cannot read property 'type' of undefined while running detox test command - detox

I am trying to run the detox test using the package.json confugation
detox test --configuration -l verbose android.emu.release
got this error
(config.configurations[program.configuration].type).split('.')[0]; ^ TypeError: Cannot read property 'type' of undefined
script under package.json
"script":{
"e2e:test-release": "detox test --configuration android.device.release.debug"
}
configuration in package.json
"android.emu.releaseTest":{
"binaryPath": "android/app/build/outputs/apk/release/app-release.apk",
"build": "cd android && ./gradlew assembleRelease assembleAndroidTest -DtestBuildType=release && cd ..",
"type": "android.emulator",
"name": "Nexus_5X_API_27"
}

doing a mistake in the command while passing the -l verbose option
detox test --configuration -l verbose android.emu.release
changed that to
detox test --confituration android.emu.release -l verbose

Related

Yarn can't run any script

When I run yarn start or any other following scripts:
"scripts": {
"start": "webpack-dev-server --config scripts/webpack.dev.js",
"clean": "rimraf build",
"build": "yarn run clean && yarn run compile",
"compile": "webpack --config scripts/webpack.prod.js",
"compile-for-test": "webpack --config scripts/webpack.test.prod.js",
"build-for-test": "yarn run clean && yarn run compile-for-test",
"test": "jest -c scripts/jest.config.js --testPathIgnorePatterns=\"services/contract-tests\"",
"test-ci": "node scripts/test-shell-commands.js unitTestCI",
"test-contract": "node scripts/test-shell-commands.js testLocal",
"test-contract-ci": "node scripts/test-shell-commands.js testCI",
"coverage": "node scripts/test-shell-commands.js unitTestCoverage",
"lint": "./node_modules/.bin/eslint --max-warnings=0 \"src/**\"",
"start-backend": "bash -l ./scripts/start-backend-container.sh",
"stop-backend": "bash -l ./scripts/stop-backend-container.sh",
"start-stub": "bash -l ./scripts/start-backend-stub-container.sh",
"stop-stub": "bash -l ./scripts/stop-backend-stub-container.sh",
"prettier": "prettier --write **/*{ts,tsx}"
},
I get the following error:
# yarn start
$ webpack-dev-server --config scripts/webpack.dev.js
error Couldn't find the binary webpack-dev-server --config scripts/webpack.dev.js
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.
# yarn test
$ jest -c scripts/jest.config.js --testPathIgnorePatterns="services/contract-tests"
error Couldn't find the binary jest -c scripts/jest.config.js --testPathIgnorePatterns="services/contract-tests"
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.
This applies to all scripts (its not spesific to webpack etc). However, when I use it npm run start, it works. yarn add or yarn commands alone also work. Just I can't run any script with yarn.
Does anyone encountered this before?
My yarn version is: 1.22.10
I have uninstalled and installed a few times but the problem continues. OS: Windows
This might be an issue with node trying to spawn a command on windows when specifying bash as the shell since Yarn uses node's child_process.spawn.
The shell-script specified in .yarnrc, passes that shell as the shell option to spawn, and when a shell is specified and process.platform evaluates to win32, ['/d', '/s', '/c' will be tacked in the arguments (see below source of spawn()).
if (options.shell) {
const command = [file].concat(args).join(' ');
if (process.platform === 'win32') {
if (typeof options.shell === 'string')
file = options.shell;
else
file = process.env.comspec || 'cmd.exe';
args = ['/d', '/s', '/c', `"${command}"`];
options.windowsVerbatimArguments = true;
Please check your yarn configuration via yarn config get script-shell in order to verify the settings of the bash-path.
See child_process.spawn for more info..

Testing an Android .apk that's built from Expo's Turtle CLI with Detox

I'm hoping to confirm my thought process when trying to test an Android application that's built with Expo's Turtle-CLI tool. I've got iOS running well, just need help getting Android working.
I have a build process that will spit out an .apk to build/android.apk. Here's the command that does that
turtle build:android \
--output $BUILD_DIR/android.apk \
--username $EXPO_USERNAME \
--password $EXPO_PASSWORD \
--config app.config.ts \
--release-channel $RELEASE_CHANNEL \
--type apk \
--mode debug
This successfully outputs the .apk in build.
Here is my detoxrc.json configuration
{
"testRunner": "jest",
"runnerConfig": "e2e/config.json",
"configurations": {
"ios": {
"type": "ios.simulator",
"binaryPath": "build/app-native.app",
"build": "./scripts/build_test_app ios",
"device": {
"type": "iPhone 11"
}
},
"android": {
"type": "android.attached",
"binaryPath": "build/android.apk",
"testBinaryPath": "build/android.apk",
"build": "./scripts/build_test_app android",
"device": {
"adbName": "059aaa47"
}
}
}
}
I then attempt to run my tests with
detox test --configuration android --loglevel trace
Which then yields (more logs at the bottom of this post)
No instrumentation runner found on device 059aaa47 for package com.foobar.mobilern
at ADB.getInstrumentationRunner (../node_modules/detox/src/devices/drivers/android/exec/ADB.js:250:13)
at Instrumentation.launch (../node_modules/detox/src/devices/drivers/android/tools/Instrumentation.js:19:24)
at MonitoredInstrumentation.launch (../node_modules/detox/src/devices/drivers/android/tools/MonitoredInstrumentation.js:18:5)
at AttachedAndroidDriver._launchInstrumentationProcess (../node_modules/detox/src/devices/drivers/android/AndroidDriver.js:284:5)
at AttachedAndroidDriver._launchApp (../node_modules/detox/src/devices/drivers/android/AndroidDriver.js:267:7)
at AttachedAndroidDriver._handleLaunchApp (../node_modules/detox/src/devices/drivers/android/AndroidDriver.js:120:7)
at AttachedAndroidDriver.launchApp (../node_modules/detox/src/devices/drivers/android/AndroidDriver.js:91:12)
at Device._doLaunchApp (../node_modules/detox/src/devices/Device.js:85:19)
at traceCall (../node_modules/detox/src/utils/trace.js:41:20)
If I omit the testBinaryPath key from .detoxrc.json, then I get this result.
Running adb -s 059aaa47 shell pm list instrumentation on the test device yields an empty response, so I'm inclined to believe that some testing setup isn't being completed thoroughly and/or perhaps I'm thinking about this wrong.
I guess the gist of my question is, is it possible to test one .apk without having to make use of some sort of testing harness / binary?
Full Log Output

React Native Detox - Run specific test file

I am running e2e tests using Detox (https://github.com/wix/Detox) and I was wondering if there is a way to control which test file to run, either through the CLI or some config file.
Currently I am using two test files in the following file structure:
> e2e
config.json
environment.js
firstTest.js
secondTest.js
My .detoxrc.json file below:
{
"testRunner": "jest",
"runnerConfig": "e2e/config.json",
"configurations": {
"android.emu.debug": {
"binaryPath": "android/app/build/outputs/apk/debug/app-debug.apk",
"build":
"cd android && sh gradlew assembleDebug assembleAndroidTest -DtestBuildType=debug && cd ..",
"type": "android.emulator",
"device": {
"avdName": "Pixel_2_API_28"
}
},
"android.emu.release": {
"binaryPath": "android/app/build/outputs/apk/release/app-release.apk",
"build": "cd android && sh gradlew assembleRelease assembleAndroidTest -DtestBuildType=release &&
cd ..",
"type": "android.emulator",
"device": {
"avdName": "Pixel_2_API_28"
}
}
}
}
When I run the tests using
detox test --configuration android.emu.debug
firstTest.js runs first and then secondTest.js runs, which is fine.
Sometimes you would not like to run firstTest.js to save time and only run secondTest.js.
So my question is: Is it possible to control which test file to run either through the detox CLI or by modifying the .detoxrc.json file? Or by some other means?
I am not interested in a dummy hack like commenting out all the tests in firstTest.js file or something like that.
You can now do this from the command line using the "-f filepath" flag:
detox test --configuration ios -f e2e/signupTest.e2e.js
In e2e folder you have config.json and inside of the config you have testRegex:
"testRegex": "\\.js\\.js$"
If you want to run only 1 set/file of tests you can change the name there and give the file name.
Example:
{
"testEnvironment": "./environment",
"testRunner": "jest-circus/runner",
"testTimeout": 120000,
"testRegex": "firstTest.js.js$",
"reporters": ["detox/runners/jest/streamlineReporter"],
"verbose": true
}
I got your feeling. On other tools you can add flags.
Here are stated some cli flags, but none points to what you want:
https://github.com/wix/Detox/blob/master/docs/APIRef.DetoxCLI.md

detox test as app loading TypeError: null is not an object 'evaluating RNGestureHandler.default.Direction'

I am trying to run the initial test I set up yesterday, which was working. Today when I launch the test I get the TypeError: null is not an object 'evaluating RNGestureHandler.default.Direction' and the app will not load. react-native run-ios launches the app as expected with no issues. When I run the detox test command the app build fails.
Android is behaving properly.
I've tried linking manually in XCode. I've tried clearing the cache. I've removed and installed the RN modules. I've added the podfile reference manually.
I'm trying to figure out why the app will load with react-native run-ios but the detox test app load fails. Could it be loading a different build? Is there a file somewhere Detox saves an iOS build folder? I thought it uses the value in the binaryPath. I can't figure out why it worked yesterday but not today.
Here's the package.json:
"test-runner": "jest",
"configurations": {
"ios.sim.debug": {
"binaryPath": "ios/build/Build/Products/Debug-iphonesimulator/MyApp.app",
"build": "xcodebuild -workspace ios/MyApp.xcworkspace -scheme MyApp -configuration Debug -
sdk iphonesimulator -derivedDataPath ios/build",
"type": "ios.simulator",
"device": {
"type": "iPhone 11"
}
},
"android.emu.debug": {
"binaryPath": "android/app/build/outputs/apk/debug/app-debug.apk",
"build": "cd android && ./gradlew assembleDebug assembleAndroidTest -DtestBuildType=debug && cd ..",
"type": "android.emulator",
"device": {
"avdName": "Nexus_5X_API_26"
}
},
"android.emu.release": {
"binaryPath": "android/app/build/outputs/apk/release/app-release.apk",
"build": "cd android && ./gradlew assembleRelease assembleAndroidTest -DtestBuildType=release && cd ..",
"type": "android.emulator",
"device": {
"avdName": "Nexus_5X_API_26"
}
}
}
}```
Ok Figured it out. Posting it here for anyone who has this issue too.
I removed the ios/build folder and did a new build with Detox:
detox build -c ios.sim.debug
And now everything is working again on iOS.

How not rebuild react native app before running e2e tests?

I am using detox for testing my RN application
I have a stub for Facebook login in tests like this:
// js/actions/login.e2e.js
function fbAuth() {
console.log('stubbed auth with Facebook');
}
module.exports = { fbAuth };
When I build my app with RN_SRC_EXT=e2e.js react-native run-android and then run the tests detox test -c android.emu.debug it uses file with the stub
When I build my app with react-native run-android and then run the tests it uses non-stub version (real login with Facebook)
My detox config looks as follows
"detox": {
"configurations": {
"android.emu.debug": {
"binaryPath": "android/app/build/outputs/apk/debug/app-debug.apk",
"build": "cd android && RN_SRC_EXT=e2e.js ./gradlew assembleDebug assembleAndroidTest -DtestBuildType=debug && cd ..",
"type": "android.emulator",
"name": "Android_Accelerated_Nougat"
}
}
}
The question is: how can I configure detox to use *e2e.js files in tests without running RN_SRC_EXT=e2e.js react-native run-android before starting the tests?
I've tried
RN_SRC_EXT=e2e.js node_modules/.bin/mocha e2e --opts e2e/mocha.opts --configuration android.emu.debug --grep :ios: --invert
RN_SRC_EXT=e2e.js detox test -c android.emu.debug
but it didn't help
UPDATE:
Actually RN_SRC_EXT=e2e.js react-native run-android doesn't help: I need to stop my Metro process and run RN_SRC_EXT=e2e.js react-native run-android to force RN to use e2e.js files in the test bundle