Search code examples
react-nativedetoxreact-native-config

Pass env file to detox


I would like to pass environment variable when I run detox tests in my react-native app:

 "ios.sim.debug": {
    "binaryPath": "ios/build/Build/Products/Debug-iphonesimulator/myapp.app",
    "build": "export IS_DETOX=true && xcodebuild -workspace ios/myapp.xcworkspace -scheme my app -configuration Debug -sdk iphonesimulator -derivedDataPath ios/build",
    "type": "ios.simulator",
    "device": {
      "type": "iPhone 11 Pro"
    }
  }

I've installed react-native-config. But the variable IS_DETOX is undefined in JS when I run detox tests.

Thanks


Solution

  • I am setting environmental variable without export.

    All my .env variables are stored in config folder and I am able to load different environmental file for different configurations.

    iOS

    "ios.sim.release": {
      "binaryPath": "ios/build/Build/Products/Release-iphonesimulator/Clim8Invest.app",
      "build": "ENVFILE=config/.env.acceptance xcodebuild -workspace ios/Clim8Invest.xcworkspace -scheme Clim8Invest -configuration Release -sdk iphonesimulator -derivedDataPath ios/build",
      "type": "ios.simulator",
      "device": {
        "type": "iPhone 11"
      }
    },
    

    Android

    "android.emu.debug.e2e": {
      "binaryPath": "android/app/build/outputs/apk/debug/app-debug.apk",
      "build": "cd android && ENVFILE=../config/.env.e2e ./gradlew assembleDebug assembleAndroidTest -DtestBuildType=debug && cd ..",
      "type": "android.emulator",
      "device": {
        "avdName": "Nexus_5X_A"
      }
    }