Detox automated tests in iOS app with Expo
14:51 31 Jan 2024

I have an app in React Native that builds with Expo. I added Detox for automated tests. I eject the app with npx expo run:ios to create a binaryPath. The problem is in my build configuration in the detox.config.js file:

/* eslint-disable */
module.exports = {
  logger: {
    level: process.env.CI ? 'debug' : undefined
  },
  testRunner: {
    args: {
      config: './e2e/jest.config.js',
      maxWorkers: process.env.CI ? 2 : undefined,
      _: ['e2e']
    }
  },
  artifacts: {
    plugins: {
      log: process.env.CI ? 'failing' : undefined,
      screenshot: process.env.CI ? 'failing' : undefined
    }
  },
  apps: {
    'ios.release': {
      type: 'ios.app',
      binaryPath:
        'ios/build/Build/Products/Release-iphonesimulator/application.app',
      build:
        'export RCT_NO_LAUNCH_PACKAGER=true && \
        xcodebuild \
        -workspace ios/application.xcworkspace \
        -UseNewBuildSystem=NO \
        -scheme application \
        -configuration Release \
        -sdk iphonesimulator \
        -derivedDataPath ios/build \
        -quiet'
    }
  },
  devices: {
    simulator: {
      type: 'ios.simulator',
      headless: Boolean(process.env.CI),
      device: {
        type: 'iPhone 15 Pro Max'
      }
    }
  },
  configurations: {
    'ios.sim.release': {
      device: 'simulator',
      app: 'ios.release',
    }
  }
};

The build created with my scripts:

{
    "e2e:build": "detox build -c ios.sim.release",
    "e2e:test": "detox test -c ios.sim.release",
    "e2e": "yarn e2e:build && yarn e2e:test"
}

is not pointing to the desired API URL. When I try to login the app is displaying the default network error message (because is not pointing to my stage env vars).

My questions are: how can I point my build to a desired API URL. What I'm doing wrong in the "build" part in my detox.config.js file? There is another way to build this?

react-native expo detox eas