Skip to main content

Running Detox tests on Bitrise

Abstract

Detox is a gray box end-to-end tests and automation library for mobile apps built with React Native. If you have a React Native app on Bitrise, you can run Detox tests.

Detox is a gray box end-to-end tests and automation library for mobile apps built with React Native. It supports both iOS and Android apps. If you have a React Native app on Bitrise, you can run Detox tests.

Before you start

Running Detox requires:

  • A Mac with a macOS (El Capitan 10.11 or newer version).

  • Xcode 8.3 or newer version with Xcode command line tools.

  • A working React Native app.

Install and set up Detox for your project. You will need to install Homebrew, Node.js and applesimutils, as well as the Detox command line tools. Add Detox to your project and then create and run Detox tests locally. If you have an Android app, go through this guide after the initial setup process.

Once you are done, you can test your Detox-configured project on Bitrise.

Running a Detox test

  1. Create a release device configuration either in the package.json file under the detox section, or in a separate Detox configuration file. For more information on setting up a Detox configuration, check out the documentation: Project setup.

    Example:

    "detox": {
     "configurations": {
       "ios.sim.debug": {
         "binaryPath": "ios/build/Build/Products/Debug-iphonesimulator/SampleProjectReactNative.app",
         "build": "xcodebuild -project ios/SampleProjectReactNative.xcodeproj -scheme SampleProjectReactNative -configuration Debug -sdk iphonesimulator -derivedDataPath ios/build -UseNewBuildSystem=NO",
         "type": "ios.simulator",
         "name": "iPhone 8"
       },
       "ios.sim.release": {
         "binaryPath": "ios/build/Build/Products/Release-iphonesimulator/SampleProjectReactNative.app",
         "build": "xcodebuild -project ios/SampleProjectReactNative.xcodeproj -scheme SampleProjectReactNative -configuration Release -sdk iphonesimulator -derivedDataPath ios/build -UseNewBuildSystem=NO",
         "type": "ios.simulator",
         "name": "iPhone 8"
       }
     },
  2. On bitrise.io, go to your project and open the Workflow Editor.

  3. Switch to the Workflow you want to use.

  4. Add a Run npm command Step to your Workflow.

  5. Install the Detox CLI and the React Native CLI using the npm command with arguments to run input:

    install -g detox-cli
    install -g react-native-cli
  6. Install a test runner.

    For example, our sample app uses mocha, installed with the yarn Step. To install yarn dependencies, just set the The yarn command to run input’s value to install.

  7. Add a Script Step to install the necessary utilities and then run Detox.

    #!/bin/bash
       
    # applesimutils is a collection of utils for Apple simulators
    brew tap wix/brew
    brew install applesimutils
       
    # we are building and testing a release device configuration
    detox build --configuration ios.sim.release
    detox test --configuration ios.sim.release --cleanup

    You can, of course, put each of these commands in separate Script Steps, for the sake of modularity.

  8. Run a build.

If the build fails, check out our example bitrise.yml file:

---
workflows:
  primary:
    steps:
    - activate-ssh-key: {}
    - git-clone:
        inputs:
        - clone_depth: ''
        title: Git Clone Repo
    - [email protected]:
        inputs:
        - command: install
    - [email protected]:
        inputs:
        - command: install -g detox-cli
        title: Install Detox CLI
    - [email protected]:
        inputs:
        - content: |-
            #!/bin/bash
            brew tap wix/brew
            brew install applesimutils
            
            detox build --configuration ios.sim.release
            detox test --configuration ios.sim.release --cleanup
        title: Detox - Build and Test Release App
    - [email protected]: {}
Troubleshootin

Troubleshooting Detox tests

If you run into issues with using Detox on Bitrise, we recommend trying to rebuild the entire Detox package before running the test.

To do so, run the following command in your Bitrise build:

  npm rebuild detox

If your Detox tests still fail or hang, contact our support!