orome
orome

Reputation: 48506

Detox attempts to run Android test when none is specified

After following the basic instructions for setting up Detox for my simple example project, and running a successful detox build, detox test produces the output below, even though the the only test configuration I have in my package.json is for iOS:

{
  "name": "Learn",
  "version": "0.0.1",
  "private": true,
  "scripts": {
    "start": "node node_modules/react-native/local-cli/cli.js start",
    "test": "jest"
  },
  "dependencies": {
    "react": "16.4.1",
    "react-native": "0.56.0"
  },
  "devDependencies": {
    "babel-jest": "23.4.0",
    "babel-preset-react-native": "5.0.2",
    "detox": "^8.0.0",
    "jest": "^23.4.1",
    "react-test-renderer": "16.4.1"
  },
  "jest": {
    "preset": "react-native"
  },
  "detox": {
    "configurations": {
      "ios.sim.debug": {
        "binaryPath": "ios/build/Build/Products/Debug-iphonesimulator/Learn.app",
        "build": "xcodebuild -project ios/Learn.xcodeproj -scheme Learn -configuration Debug -sdk iphonesimulator -derivedDataPath ios/build",
        "type": "ios.simulator",
        "name": "iPhone 6"
      }
    },
    "test-runner": "jest"
  }
}

The file mentioned in the error was provided without changes by the install process and has the contents:

/**
 * Copyright (c) 2015-present, Facebook, Inc.
 *
 * This source code is licensed under the MIT license found in the
 * LICENSE file in the root directory of this source tree.
 *
 * @format
 */

'use strict';

module.exports = require('./configs/main');

Why does Detox fail to test my app?


node_modules/.bin/jest e2e --config=e2e/config.json --maxWorkers=1 --testNamePattern='^((?!:android:).)*$'
 FAIL  e2e/firstTest.spec.js
  ● Test suite failed to run

    Plugin 0 specified in "/Users/Rax/Documents/Projects/Coding/React/Learn/node_modules/babel-preset-react-native/index.js" provided an invalid property of "default" (While processing preset: "/Users/Rax/Documents/Projects/Coding/React/Learn/node_modules/babel-preset-react-native/index.js")

      at Plugin.init (../node_modules/babel-core/lib/transformation/plugin.js:131:13)
      at Function.normalisePlugin (../node_modules/babel-core/lib/transformation/file/options/option-manager.js:152:12)
      at ../node_modules/babel-core/lib/transformation/file/options/option-manager.js:184:30
          at Array.map (<anonymous>)
      at Function.normalisePlugins (../node_modules/babel-core/lib/transformation/file/options/option-manager.js:158:20)
      at OptionManager.mergeOptions (../node_modules/babel-core/lib/transformation/file/options/option-manager.js:234:36)
      at ../node_modules/babel-core/lib/transformation/file/options/option-manager.js:265:14
      at ../node_modules/babel-core/lib/transformation/file/options/option-manager.js:323:22
          at Array.map (<anonymous>)
      at OptionManager.resolvePresets (../node_modules/babel-core/lib/transformation/file/options/option-manager.js:275:20)

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

Error: Command failed: node_modules/.bin/jest e2e --config=e2e/config.json --maxWorkers=1 --testNamePattern='^((?!:android:).)*$'
    at checkExecSyncError (child_process.js:603:11)
    at Object.execSync (child_process.js:640:13)
    at runJest (/Users/Rax/Documents/Projects/Coding/React/Learn/node_modules/detox/local-cli/detox-test.js:146:6)
    at run (/Users/Rax/Documents/Projects/Coding/React/Learn/node_modules/detox/local-cli/detox-test.js:81:7)
    at Object.<anonymous> (/Users/Rax/Documents/Projects/Coding/React/Learn/node_modules/detox/local-cli/detox-test.js:191:1)
    at Module._compile (internal/modules/cjs/loader.js:689:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:700:10)
    at Module.load (internal/modules/cjs/loader.js:599:32)
    at tryModuleLoad (internal/modules/cjs/loader.js:538:12)
    at Function.Module._load (internal/modules/cjs/loader.js:530:3)

UPDATE: When I follow the instructions below, I get:

 : Searching for device matching iPhone 6...
 : Booting device 7F2124D7-7A75-4702-9A88-926D0C5B884A
 : running "/usr/bin/xcrun simctl io 7F2124D7-7A75-4702-9A88-926D0C5B884A screenshot "/dev/null"" returned 2
7: stderr: An error was encountered processing the command (domain=SimulatorKit.SimDisplayScreenshotWriter.ScreenshotError, code=2):
Error creating the image

Upvotes: 7

Views: 5274

Answers (2)

Bita Shamsafar
Bita Shamsafar

Reputation: 1

Check also this to be correct

The name of your test emulator device to be exactly the same with the one you mentioned in detox.config.js as avdName

Upvotes: 0

Andrew
Andrew

Reputation: 28539

Firstly, Detox isn't running an android test. It only looks like that because of the negative lookahead in the regex.

--testNamePattern='^((?!:android:).)*$'

Here is the output from a successful iOS test that I just ran.

detox test
node_modules/.bin/jest e2e --config=e2e/config.json --maxWorkers=1 --testNamePattern='^((?!:android:).)*$'

 server listening on localhost:55356...

 : Searching for device matching iPhone 7...

 : Uninstalling com.testapp.test...

 : com.testapp.test uninstalled
 : Installing /Users/work/Documents/test/ios/build/Build/Products/Debug-iphonesimulator/test.app...
 : /Users/work/Documents/test/ios/build/Build/Products/Debug-iphonesimulator/test.app installed
 : Terminating  com.testapp.test...
 : com.testapp.test terminated
 : Launching  com.testapp.test...
7: com.testapp.test launched. The stdout and stderr logs were recreated, you can watch them with:
        tail -F /Users/work/Library/Developer/CoreSimulator/Devices/AF406169-5CF3-4480-9D00-8F934C420043/data/tmp/detox.last_launch_app_log.{out,err}
 PASS  e2e/firstTest.spec.js (10.504s)
  Example
    ✓ should have Home tab (1283ms)
    ✓ should show detail screen after tap (1872ms)

Test Suites: 1 passed, 1 total
Tests:       2 passed, 2 total
Snapshots:   0 total
Time:        11.153s, estimated 12s
Ran all test suites matching /e2e/i with tests matching "^((?!:android:).)*$".

With regard to your test not running, I had this problem when I upgraded my React-Native version from 0.55 to 0.56.

I believe there is an issue with Babel that causes this, as RN 0.56 now requires Babel 7.

Looking at your package.json it seems that you should add to your devDependencies

"@babel/core": "^7.0.0-beta.47", "babel-core": "^7.0.0-beta.47",

This problem has been talked about on the React-Native github page.

For running Jest tests I found that I also had to add "@babel/generator": "^7.0.0-beta.47" to my devDependencies.

Upvotes: 4

Related Questions