react-native - 将 env 文件传递​​给 detox

标签 react-native detox react-native-config

我想在我的 react-native 应用程序中运行排毒测试时传递环境变量:

 "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"
    }
  }

我已经安装了 react-native-config .但是当我运行排毒测试时,变量 IS_DETOX 在 JS 中是未定义的。

谢谢

最佳答案

我正在设置没有export的环境变量。

我所有的 .env 变量都存储在 config 文件夹中,我可以为不同的配置加载不同的环境文件。

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.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"
  }
}

关于react-native - 将 env 文件传递​​给 detox,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59735528/

相关文章:

react-native - 如何在 React Native 中移动下一个 textInput

javascript - 使用胖箭头函数更改 React-Native 中的 React.Component

android - Detox - DetoxManager 在运行时找不到 kotlin/jvm/functions/Function1

react-native - 排毒:检测显示的元素

ios - react native 配置无法读取 ios 中的 env 文件

react-native - React VR - 是否可以通过socket.io实现实时对象?

react-native - 我如何在 native react 中使 View 可点击

android - 排毒 - 无法初始化类 DefaultKotlinSourceSetKt

react-native - 使用 .env 变量在 react-native 应用程序上设置 appcenter

ios - 如何修复 JSON 值 '<null>' 类型的 NSNull 无法在 iOS react-native-config 和 AsyncStorage 中转换为 NSString?