【问题标题】:Detox attempts to run Android test when none is specified未指定时,Detox 尝试运行 Android 测试
【发布时间】:2018-12-22 19:12:51
【问题描述】:

在为我的简单示例项目关注the basic instructions for setting up Detox 并成功运行detox build 之后,detox test 会产生以下输出,即使我在package.json 中拥有的唯一测试配置是针对 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"
  }
}

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

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

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


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)

更新:当我关注 instructions below 时,我得到:

 : 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

【问题讨论】:

标签: ios react-native detox


【解决方案1】:

首先,Detox 没有运行安卓测试。由于正则表达式中的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。

【讨论】:

    【解决方案2】:

    检查是否正确

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2011-03-04
      • 2021-01-07
      • 2018-11-19
      • 2020-08-24
      • 2020-03-09
      • 2018-10-24
      • 2019-05-17
      • 2019-01-11
      相关资源
      最近更新 更多