未指定排毒时尝试运行Android测试

时间:2018-07-14 16:51:20

标签: ios react-native detox

在遵循the basic instructions for setting up Detox作为我的简单示例项目并运行成功的detox build之后,detox test会产生以下输出,即使我的{{1 }}适用于iOS:

package.json

错误中提到的文件由安装过程提供,没有更改,并且具有以下内容:

{
  "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"
  }
}

为什么排毒无法测试我的应用程序?


/**
 * 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');

更新:当我遵循instructions below时,我得到:

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)

2 个答案:

答案 0 :(得分:1)

首先,Detox没有运行android测试。只是因为正则表达式中的negative lookahead而已。

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

这是我刚刚运行的一次成功的iOS测试的输出。

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:).)*$".

关于您的测试未运行,当我将React-Native版本从0.55升级到0.56时,我遇到了这个问题。

我相信Babel会导致此问题,因为RN 0.56现在需要Babel 7

在查看package.json时,您似乎应该添加到devDependencies

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

已在React-Native github页面上讨论了此问题。

对于运行Jest测试,我发现我还必须添加 "@babel/generator": "^7.0.0-beta.47"到我的devDependencies。

答案 1 :(得分:0)

还要检查这个是否正确

您的测试模拟器设备的名称与您在 detox.config.js 中提到的 avdName 完全相同