Detox is gray box end-to-end testing and automation library for mobile apps. It has a lot of great features:

  • Cross Platform
  • Runs on Devices
  • Automatically Synchronized
  • Test Runner Independent
  • Debuggable

Setting Up Detox

Setup Environment

Install applesimutils (Mac only)

applesimutils is a collection of utils for Apple simulators.

1brew tap wix/brew 2brew install applesimutils 3

Install Jest Globally

1npm install -g jest 2

Installation

Keep Nx Package Versions In Sync

Make sure to install the @nx/detox version that matches the version of nx in your repository. If the version numbers get out of sync, you can encounter some difficult to debug errors. You can fix Nx version mismatches with this recipe.

In any Nx workspace, you can install @nx/detox by running the following command:

nx add @nx/detox

This will install the correct version of @nx/detox.

How @nx/detox Infers Tasks

The @nx/detox plugin will create a task for any project that has an ESLint configuration file present. Any of the following files will be recognized as an ESLint configuration file:

  • .detoxrc.js
  • .detoxrc.json
  • detox.config.js
  • detox.config.json

View Inferred Tasks

To view inferred tasks for a project, open the project details view in Nx Console or run nx show project my-project --web in the command line.

@nx/detox Configuration

The @nx/detox/plugin is configured in the plugins array in nx.json.

nx.json
1{ 2 "plugins": [ 3 { 4 "plugin": "@nx/detox/plugin", 5 "options": { 6 "buildTargetName": "build", 7 "startTargetName": "start", 8 "testTargetName": "test" 9 } 10 } 11 ] 12} 13
Nx 15 and lower use @nrwl/ instead of @nx/

Once a Detox configuration file has been identified, the targets are created with the name you specify under buildTargetName, startTargetName or testTargetName in the nx.json plugins array. The default names for the inferred targets are build and test.