Detox + Jest

Follow this guide to enable integrating Detox + Jest with Currents

Detoxarrow-up-right is a popular gray-box end-to-end testing and automation framework for React Native apps.

Detox delegates scheduling and running tests onto a test runner. Jest is the default and the recommended choice, for many reasons, including - but not limited to, parallel test suite execution capability, and complete integration with Detox API.

Currents integration with Jest allows sending the results of your Detox tests to Currents.

Add Currents Reporter for Jest

After you setup and configure Detox for your mobile application, add @currents/jest reporter to jest.config.js

jest.config.js
/** @type {import('jest').Config} */
module.exports = {
  maxWorkers: 1,
  globalSetup: './globalSetup.ts',
  globalTeardown: 'detox/runners/jest/globalTeardown',
  testEnvironment: 'detox/runners/jest/testEnvironment',
  setupFilesAfterEnv: ['./setup.ts'],
  testRunner: 'jest-circus/runner',
  testTimeout: 120000,
  testMatch: ['**/*.test.ts'],
  transform: {
    '\\.tsx?$': 'ts-jest'
  },
  reporters: ['detox/runners/jest/reporter', '@currents/jest'], // 👈🏻
  verbose: true
};

Run Detox Tests

Run detox tests:

Running this command with @currents/jest reporter enabled generates results in a format compatible for processing by Currents.

In order to send the results for processing you'd invoke an additional command currents upload from @currents/cmd npm package.

Uploading Results to Currents

Run the following command to upload the results to Currents (see currents upload for details)

Before running currents upload you must explicitly define detox configuration that matches the configuration used to run the tests.

For example, if you run the tests using --configuration android.emu.release, then you should also define the same configuration value for currents upload command.

circle-exclamation

Setting Detox Configuration

To explicitly set Detox configuration set the selectedConfiguration: <configuration key> in the Detox config filearrow-up-right:

If you have only one configuration value in the configurations object of detox configuration file, Detox will pick it by default and there's no need to explicitly set the configuration.

circle-info

The currents upload command will execute jest to discover the full test suite. During this process, the globalSetup script will be run, which can only utilize the selectedConfiguration option or the single value from the configurations object.

Detox retries limitation

When retries are used (e.g. with Detox), results can end up in multiple report directories or show only the last attempt. This section explains why and how to configure the reporter.

How the report directory works

The reporter writes results into a report directory. One Jest process uses one directory per run.

  • Not set: A new unique directory is created for each run (e.g. .currents/2025-03-05-…-uuid). If your workflow starts Jest more than once (e.g. Detox re-runs failed tests in a new process), each run gets its own directory. Results are split across folders and upload may see only one or fail.

  • Set: Every run writes to the same folder. Upload sees one report. If a later run only re-runs failed tests, it overwrites those tests results in that folder, so Currents shows only the last attempt for retried specs.

Configuration: Set the path in Jest config (reportDir in the reporter options) or with the CURRENTS_REPORT_DIR environment variable. Env var overrides the config option when both are set.

Why Detox is different

Detox runs tests via Jest in separate processes. With detox test --retries <n>arrow-up-right, Detox starts Jest again for failed test files only. So you get multiple Jest runs in one logical run - which leads to either multiple report directories (if report dir is not set) or overwritten retry results (if it is set). The same applies to any setup that runs Jest more than once.

What to do

Option 1: Use Jest retries (recommended)

Use Jest's built-in retries (e.g. jest.retryTimes()arrow-up-right in config). Retries stay in the same Jest process, so there is one run, one report directory, and full retry history in Currents.

Use this when Jest-level retries are enough and you don't need Detox’s “re-run only failed files in a new process” behavior.

Option 2: Fixed report directory with Detox retries

When you must use Detox's retriesarrow-up-right, set a fixed report directory so every run writes to the same place and upload finds a single report.

Jest config:

Or environment variable:

Trade-off: The retry run writes to the same directory and overwrites the first run’s results for those tests, so Currents shows only the last attempt for retried specs.

Quick reference

Scenario
No fixed report directory
Fixed report directory

Single Jest run (or Jest retries in one process)

One directory, full results

One directory, full results

Multiple Jest runs (e.g. Detox --retries)

Several directories; upload may use only one

One directory; retried tests overwrite → only last attempt visible

Recommendation: Prefer Jest retries when possible (one directory, full retry history). If using Detox --retries, set a fixed report directory and accept that retried specs show only the last attempt.

circle-info

Improved support for Detox-style retries (e.g. merging retry runs into one report or full retry history in Currents) is proposed on Featurebasearrow-up-right. Upvote there to help prioritise implementation.

Last updated

Was this helpful?