Search code examples
react-nativedetox

React Native Detox - Run specific test file


I am running e2e tests using Detox (https://github.com/wix/Detox) and I was wondering if there is a way to control which test file to run, either through the CLI or some config file.

Currently I am using two test files in the following file structure:

> e2e 
 config.json
 environment.js
 firstTest.js
 secondTest.js

My .detoxrc.json file below:

{
 "testRunner": "jest",
 "runnerConfig": "e2e/config.json",
 "configurations": {
 "android.emu.debug": {
  "binaryPath": "android/app/build/outputs/apk/debug/app-debug.apk",
  "build":
    "cd android && sh gradlew assembleDebug assembleAndroidTest -DtestBuildType=debug && cd ..",
  "type": "android.emulator",
  "device": {
    "avdName": "Pixel_2_API_28"
  }
},
"android.emu.release": {
  "binaryPath": "android/app/build/outputs/apk/release/app-release.apk",
  "build": "cd android && sh gradlew assembleRelease assembleAndroidTest -DtestBuildType=release && 
   cd ..",
  "type": "android.emulator",
  "device": {
    "avdName": "Pixel_2_API_28"
  }
  }

 }
}

When I run the tests using

detox test --configuration android.emu.debug

firstTest.js runs first and then secondTest.js runs, which is fine.

Sometimes you would not like to run firstTest.js to save time and only run secondTest.js.

So my question is: Is it possible to control which test file to run either through the detox CLI or by modifying the .detoxrc.json file? Or by some other means?

I am not interested in a dummy hack like commenting out all the tests in firstTest.js file or something like that.


Solution

  • In e2e folder you have config.json and inside of the config you have testRegex:

     "testRegex": "\\.js\\.js$"
    

    If you want to run only 1 set/file of tests you can change the name there and give the file name. Example:

    {
        "testEnvironment": "./environment",
        "testRunner": "jest-circus/runner",
        "testTimeout": 120000,
        "testRegex": "firstTest.js.js$",
        "reporters": ["detox/runners/jest/streamlineReporter"],
        "verbose": true
    

    }

    I got your feeling. On other tools you can add flags. Here are stated some cli flags, but none points to what you want: https://github.com/wix/Detox/blob/master/docs/APIRef.DetoxCLI.md