Detox automated tests in iOS app with Expo

101 Views Asked by At

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?

1

There are 1 best solutions below

0
brpinto On

which version of Expo, Detox, React Native are you using ?

Is your app running in a bare or a managed workflow ? As you talked about eject in your message, I assume you are in a managed expo app.

As today there is quite no need to properly "eject" you app to run native packages, you still have to prebuild your app using npx expo prebuild. You can add the --platform option with ios or android according to the one you are interested in.

In my case (expo managed app), the build command is as follow :

xcodebuild -workspace ios/[your-app-name].xcworkspace -scheme [your-app-name] -configuration Release -sdk iphonesimulator -derivedDataPath ios/build