【问题标题】:Expo + Detox + CircleCI世博+排毒+CircleCI
【发布时间】:2019-11-11 00:54:18
【问题描述】:

在过去的两天里,我一直在寻找使用 Expo + Detox + CircleCI 的良好设置,以便可以在 CI 过程中构建应用程序。

在本地,我可以通过下载 Exponent.app 并将其放入 bin 并运行 expo start(在不同的终端中)来让 Expo + Detox 工作。但是,expo start 在 Circle CI 中被阻塞,所以有没有一种有效的方法来实现这一点。

我查看了很多示例,但没有找到一个带有更新示例的明确响应,考虑到 Expo 的受欢迎程度,这真是令人遗憾。

如果有人有您可以分享的示例 CircleCI 文件,那就太好了!或者确实有一些帮助解释了实现这一目标的流程。

我很欣赏这也是 Detox 和 CircleCI 的一个问题,但我想我会在这里添加它,因为很多人可能也想知道答案?

我当前的 Circle-CI 代码,我一直在努力寻找可行的解决方案......

# Javascript Node CircleCI 2.0 configuration file
#
# Check https://circleci.com/docs/2.0/language-javascript/ for more details
#
version: 2

defaults: &defaults
  working_directory: ~/iynk-react-app

jobs:

  test:
    <<: *defaults

    docker:
      - image: circleci/node:10

    steps:
      - checkout

      - run:
          name: Update npm
          command: 'sudo npm install -g npm@latest'

      - run:
          name: Install Firebase Tools
          command: sudo npm install -g firebase-tools@latest

      - restore_cache:
          name: Restore Yarn Package Cache
          keys:
            - yarn-packages-{{ checksum "yarn.lock" }}

      - run:
          name: Install Dependencies
          command: yarn install --frozen-lockfile

      - save_cache:
          name: Save Yarn Package Cache
          key: yarn-packages-{{ checksum "yarn.lock" }}
          paths:
            - ~/.cache/yarn

      - run: yarn test

      - run:
          name: Install modules in functions
          command: yarn --cwd ./functions --ignore-engines

  e2e:
    <<: *defaults

    macos:
      xcode: "10.2.1"

    steps:
      - run:
          # Note: the [ character is necessary to uniquely identify the iPhone 8 simulator, as the phone + watch simulator is also present in the build image: 
          # Will show what looks like an error - Instruments Usage Error: Unknown device specified: "iPhone 8 (12.2) [") - but it launch
          name: Pre-start simulator first to ensure that it is open
          command: xcrun instruments -w "iPhone 8 (12.2) [" || true

      - checkout

      - restore_cache:
            key: yarn-v1-{{ checksum "yarn.lock" }}-{{ arch }}

      - restore_cache:
          key: node-v1-{{ checksum "package.json" }}-{{ arch }}

      - run: yarn install --ignore-engines

      - save_cache:
          key: yarn-v1-{{ checksum "yarn.lock" }}-{{ arch }}
          paths:
            - ~/.cache/yarn

      - save_cache:
          key: node-v1-{{ checksum "package.json" }}-{{ arch }}
          paths:
            - node_modules

      - run:
          name: Install applesimutils
          command: |
            brew tap wix/brew
            brew install applesimutils

      - run:
          name: Install react-native, detox CLI and expo CLI
          command: |
            npm install -g react-native-cli
            npm install -g detox-cli
            npm install -g expo-cli

      - run:
          name: Prepare detox environment
          command: |
            detox clean-framework-cache && 
            detox build-framework-cache

      - run: 
          name: Download Exponent.app into bin
          command: |
            brew install wget
            ./scripts/setup.sh

      # - run:
      #     name: Install the downloaded version of the expo iOS app on the Simulator
      #     command: |
      #       xcrun simctl install booted ./bin/Exponent.app

      # - run:
      #     name: Login into Expo and publish to staging
      #     command: |
      #       npx expo login -u $EXPO_USERNAME -p $EXPO_PASSWORD
      #       npx expo publish --non-interactive --max-workers 1 --release-channel staging

      - run: 
          name: Run expo locally using (&) Run detox tests
          # shell: /bin/sh
          command: |
            yarn test:e2e & 
            expo start -c    

workflows:
  version: 2

  build_and_test:
    jobs:
      - test
      - e2e

我的包裹:

"detox": "12.3.0",
"detox-expo-helpers": "^0.6.0",
"expo-detox-hook": "^1.0.10",

本地作品

我的本​​地设置运行并且测试通过。这是目前的过程:

确保已设置本地环境:

brew update
brew tap wix/brew
brew install --HEAD applesimutils
npm install -g detox-cli

运行安装脚本:

./setup.sh

然后开始博览会。

expo start -c

启动您计划用于测试的模拟器(因此,如果您选择了 iPhone X,请启动 iPhone X 等)。不过,您不需要从 expo 运行 i,只需打开 Simulator 程序即可。

open -a Simulator.app

最后,从不同的终端运行排毒测试:

yarn test:e2e

已知问题

我不认为这是相关的,因为我可以让我的设置在本地运行...

2019 年 7 月 2 日更新

如果我用以下方法在我的圈子 ci 中构建,我可以通过测试:

      - run:
          name: Login into Expo and publish to staging (could update with $CIRCLE_BRANCH)
          command: |
            npx expo login -u $EXPO_USERNAME -p $EXPO_PASSWORD --non-interactive
            npx expo publish --non-interactive --max-workers 1 --release-channel testing

然后在 e2e/init.js 文件中从该发布通道加载:

beforeAll(async () => {
  await detox.init(config);

  // Run from the remote build if in CI
  if (__CI__) {
    const url = 'exp://exp.host/@alexpchin/iynk?release-channel=testing';
    await device.relaunchApp({ url, sourceApp: 'host.exp.exponent' });
    await expect(element(by.label('Got it'))).toBeVisible();
    await element(by.label('Got it')).tap();
  }
});

但是,如果我使用它,我不能使用 detox-expo-helpers 中的 reloadApp(在 e2e/init.js 中):

beforeEach(async () => {
  await adapter.beforeEach();
  // If not CI, use `reloadApp` from `detox-expo-helpers`
  if (!__CI__) {
    await reloadApp();
  }
});

这显然真的很慢,因为每次要测试 UI 时都必须创建一个新构建,而不是从分支代码运行...

【问题讨论】:

  • 嗨,我最近设法在 iOS 上的 CircleCI(没有 Expo)上运行我们的测试套件。您可以在此处查看配置文件:github.com/wix/Detox/blob/TravisCITest/.circleci/config.yml 和相应的脚本。这没有 Expo,不确定这会使您的测试复杂化。请注意,Detox 和 Expo 的最新版本存在一个已知问题。
  • 我遇到的问题是针对未弹出的 Expo 应用程序。我想我可以在没有 Expo 的情况下让事情顺利进行,但 Expo 似乎更具挑战性。
  • 你正在运行哪种排毒?最新版本的 Detox 存在一个已知问题。请查阅文档以获取最新的支持版本。
  • 我已将版本添加到我的问题中。我还添加了有关我如何在本地运行的信息。

标签: react-native expo circleci detox circleci-2.0


【解决方案1】:

仍然没有答案或更新,所以我会尽力提供我的。 据我了解,您想要自动化的流程是test on Simulator。附加链接中列出了步骤。

即iOS版

expo build:ios -t simulator
expo build:status (or expo url:ipa)
tar -xvzf your-app.tar.gz
open /Applications/Xcode.app/Contents/Developer/Applications/Simulator.app --args -CurrentDeviceUDID `xcrun instruments -s | grep "iPhone 7 (12.2)" -m1 | cut -d "[" -f2 | cut -d "]" -f1`
xcrun simctl install booted <app path>
xcrun simctl launch booted <app identifier>

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2022-07-15
    • 1970-01-01
    • 2019-08-09
    • 2018-07-12
    • 2019-03-25
    • 1970-01-01
    • 2021-03-13
    • 2022-06-23
    相关资源
    最近更新 更多