首页 > 解决方案 > Bitrise + Detox + React-native - Hello World 示例挂在 detox.init 上

问题描述

我正在尝试使用 Detox 设置react-native “Hello World”应用程序并在 Bitrise.io 上运行。我浏览了 react-native-cli 入门指南,并尝试在 Bitrise 上使用 Detox + Jest 运行最简单的排毒测试。

我遇到的具体错误是未定义device和全局变量(请参阅日志或下面的链接)。element从我到目前为止的研究来看,这是由于detox.init没有完成造成的。

Bitrise 是否有一些我缺少的基本配置?该detox test命令对我来说在本地运行得很好。

我正在使用免费的 Bitrise 帐户,该项目是公开的。你可以在这里看到一个失败的构建:https ://app.bitrise.io/build/e7926ddfc759288f#?tab=log

该仓库也是公开的:https ://github.com/jamesopti/react-native-test/blob/add_detox/AwesomeProject/e2e/firstTest.spec.js

提前致谢!

比特上升错误日志

Example: should have welcome screen
Example: should have welcome screen [FAIL]
FAIL e2e/firstTest.spec.js (122.008s)
  Example
    ✕ should have welcome screen (8ms)
  ● Example › should have welcome screen
    Timeout - Async callback was not invoked within the 120000ms timeout specified by jest.setTimeout.Error: Timeout - Async callback was not invoked within the 120000ms timeout specified by jest.setTimeout.
      at mapper (../node_modules/jest-jasmine2/build/queueRunner.js:25:45)
  ● Example › should have welcome screen
    ReferenceError: device is not defined
      1 | describe('Example', () => {
      2 |   beforeEach(async () => {
    > 3 |     await device.reloadReactNative();
        |           ^
      4 |   });
      5 | 
      6 |   it('should have welcome screen', async () => {

比特升.yml

---
format_version: '8'
default_step_lib_source: https://github.com/bitrise-io/bitrise-steplib.git
project_type: react-native
trigger_map:
- push_branch: "*"
  workflow: primary
- pull_request_source_branch: "*"
  workflow: primary
workflows:
  deploy:
    description: "## ..."
    steps:
    - activate-ssh-key@4.0.3:
        run_if: '{{getenv "SSH_RSA_PRIVATE_KEY" | ne ""}}'
    - git-clone@4.0.17: {}
    - script@1.1.5:
        title: Do anything with Script step
    - yarn@0.1.0:
        inputs:
        - workdir: AwesomeProject
        - command: install
    - install-missing-android-tools@2.3.7:
        inputs:
        - gradlew_path: "$PROJECT_LOCATION/gradlew"
    - android-build@0.10.0:
        inputs:
        - project_location: "$PROJECT_LOCATION"
    - certificate-and-profile-installer@1.10.1: {}
    - xcode-archive@2.7.0:
        inputs:
        - project_path: "$BITRISE_PROJECT_PATH"
        - scheme: "$BITRISE_SCHEME"
        - export_method: "$BITRISE_EXPORT_METHOD"
        - configuration: Release
    - deploy-to-bitrise-io@1.9.2: {}
  primary:
    steps:
    - activate-ssh-key@4.0.3:
        run_if: '{{getenv "SSH_RSA_PRIVATE_KEY" | ne ""}}'
    - git-clone@4.0.17: {}
    - yarn@0.1.0:
        inputs:
        - workdir: AwesomeProject
        - command: install
        title: Yarn Install
    - yarn@0.1.0:
        inputs:
        - workdir: AwesomeProject
        - command: test
        title: Unit tests
    after_run:
    - detox
  detox:
    steps:
    - cocoapods-install@1.9.1:
        inputs:
        - source_root_path: "$BITRISE_SOURCE_DIR/AwesomeProject/ios"
    - npm@1.1.0:
        title: Install Global
        inputs:
        - workdir: "$BITRISE_SOURCE_DIR/AwesomeProject"
        - command: install -g detox-cli react-native-cli
    - script@1.1.5:
        inputs:
        - working_dir: "$BITRISE_SOURCE_DIR/AwesomeProject"
        - content: |-
            #!/usr/bin/env bash

            brew tap facebook/fb
            export CODE_SIGNING_REQUIRED=NO
            brew install fbsimctl
            brew tap wix/brew
            brew install applesimutils --HEAD
        title: Install detox utils
    - script@1.1.5:
        inputs:
        - working_dir: "$BITRISE_SOURCE_DIR/AwesomeProject"
        - content: |-
            #!/usr/bin/env bash

            detox build --configuration ios.sim.debug
        title: Detox Build
    - script@1.1.5:
        inputs:
        - working_dir: "$BITRISE_SOURCE_DIR/AwesomeProject"
        - content: |-
            #!/usr/bin/env bash

            detox test --configuration ios.sim.debug --cleanup
        title: Detox Test
app:
  envs:
  - opts:
      is_expand: false
    PROJECT_LOCATION: AwesomeProject/android
  - opts:
      is_expand: false
    MODULE: app
  - opts:
      is_expand: false
    VARIANT: ''
  - opts:
      is_expand: false
    BITRISE_PROJECT_PATH: AwesomeProject/ios/AwesomeProject.xcworkspace
  - opts:
      is_expand: false
    BITRISE_SCHEME: AwesomeProject
  - opts:
      is_expand: false
    BITRISE_EXPORT_METHOD: ad-hoc
meta:
  bitrise.io:
    machine_type: elite

标签: react-nativejestjsdetoxbitrise

解决方案


不幸的是,这是一个非常普遍的错误,可能是由多种原因引起的(不兼容的 OS/jest + detox 版本/node + detox 版本等)。

如果您使用的是 MacOS,您可以选择通过屏幕共享连接来检查 Bitrise 的 VM 中出了什么问题:我建议while someFileDoesntExist在您当前的工作流程中添加一个(在没有中止按钮的情况下自然停止迭代)包安装步骤(节点、排毒、开玩笑等),然后检查它是否与您在本地运行的相同。

如果不是这种情况,请检查 VM 是否运行相同的模拟器——手机型号 && 操作系统版本;如果不是,那么您可以在排毒配置中指定模拟器和操作系统版本。

如果那也不起作用,我不确定它可能是什么:(


推荐阅读