> For the complete documentation index, see [llms.txt](https://docs.currents.dev/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.currents.dev/getting-started/other-frameworks/jest/detox-+-jest.md).

# Detox + Jest

Send the results of Detox + Jest tests to Currents

[Detox](https://wix.github.io/Detox/) is a gray-box end-to-end testing framework for React Native apps. Detox runs the tests with a test runner, and Jest is the recommended one.

Currents receives the results of Detox tests through the [@currents/jest](/resources/reporters/currents-jest.md) reporter and the `currents run upload` command of [@currents/cmd](/resources/reporters/currents-cmd.md). A Detox run in Currents includes:

* the result of every test attempt, including the attempts of `detox test --retries`
* the videos, screenshots and device logs that Detox records, attached to the attempt they belong to
* `detox.trace.json`, the Detox trace of the session

{% hint style="info" %}
Detox support requires `@currents/jest` 1.4.0 or later and `@currents/cmd` 1.11.0 or later. See [the example project](https://github.com/currents-dev/currents-examples/tree/main/generic-reporter/jest/detox) for a React Native app that runs Detox in GitHub Actions and reports to Currents.
{% endhint %}

### Install the packages

```bash
npm install --save-dev @currents/jest @currents/cmd
```

### Add the reporter

Add `@currents/jest` next to the Detox reporter in the Jest configuration of your Detox tests:

{% code title="e2e/jest.config.js" %}

```javascript
/** @type {import('jest').Config} */
module.exports = {
  rootDir: '..',
  testMatch: ['<rootDir>/e2e/**/*.test.js'],
  testTimeout: 120000,
  maxWorkers: 1,
  globalSetup: 'detox/runners/jest/globalSetup',
  globalTeardown: 'detox/runners/jest/globalTeardown',
  testEnvironment: 'detox/runners/jest/testEnvironment',
  reporters: ['detox/runners/jest/reporter', '@currents/jest'], // 👈🏻
  verbose: true,
};
```

{% endcode %}

### Record artifacts

Currents uploads the files that Detox records. Turn on the artifact plugins in the Detox configuration, or with the `--record-logs`, `--take-screenshots` and `--record-videos` options of `detox test`:

{% code title=".detoxrc.js" %}

```javascript
module.exports = {
  artifacts: {
    plugins: {
      log: 'all',
      screenshot: 'failing',
      video: 'failing',
    },
  },
  // ...
};
```

{% endcode %}

Detox writes `detox.trace.json` only when it records logs.

### Run the tests and upload the results

```bash
npx detox test --configuration android.emu.release --retries 1
npx currents run upload --project-id=<project id> --key=<record key>
```

Run `currents run upload` after `detox test` exits. Detox finishes writing the videos and logs only when the test run ends. See [currents run upload](/resources/reporters/currents-cmd/currents-upload.md) for the options of the command.

### Retries

`detox test --retries <n>` starts Jest again for the spec files that failed. The reporter adds the attempts of every rerun to the results of the same test, so a test that fails on the first run and passes on the rerun shows both attempts and is marked flaky in Currents.

Jest retries ([`jest.retryTimes()`](https://jestjs.io/docs/jest-object#jestretrytimesnumretries-options)) also work: they run in the same Jest process.

### Report directory

All the Jest processes of one `detox test` write their results to `.currents/<session>`, named after the Detox artifacts directory of the session. `currents run upload` reads the most recent directory in `.currents`.

To use another directory, set `reportDir` in the reporter options or the `CURRENTS_REPORT_DIR` environment variable, and pass the same directory to `currents run upload --report-dir`. The results of an earlier `detox test` stay in that directory, so remove it before each run.

{% hint style="info" %}
We recommend adding `.currents` to `.gitignore`
{% endhint %}

### Earlier versions

With `@currents/jest` before `1.4.0-beta.0`:

* `currents run upload` runs Jest to list the tests, which runs the Detox `globalSetup`. Set `selectedConfiguration` in the [Detox config file](https://wix.github.io/Detox/docs/config/overview/#config-structure) to the configuration you run the tests with, or upload fails with `Cannot determine which configuration to use from Detox config`.
* Every rerun of `detox test --retries` writes to a new report directory, or replaces the results of the earlier run when the report directory is set. Currents shows only one attempt of a retried test.
* Detox artifacts are not uploaded.

With `@currents/cmd` `1.11.0-beta.1`, runs of `pull_request` workflows in GitHub Actions show the merge commit that GitHub creates (`Merge <sha> into <sha>`) instead of the last commit of the pull request. To set the commit yourself, use the `COMMIT_INFO_*` variables, see [Overriding Commit Info](/dashboard/runs/commit-information.md#overriding-commit-info).


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://docs.currents.dev/getting-started/other-frameworks/jest/detox-+-jest.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
