0

I am setting up testing environments on a react native app. Recently, my build commands have stopped including the environment variables that I pass into them.

EMAIL=testemail@test.com PASSWORD=testpassword xcodebuild....

When the app runs, process.env.EMAIL returns undefined and if I log the process.env object the EMAIL, PASSWORD, or any other variable provided in the command line is not listed.

UPDATE: This really seems to be an issue with detox/metro. This is where the passed-in environment variables should be received as is outlined in Detox's docs regarding mocking, which is also broken now.

Any ideas on what I changed that broke this functionality?

ismaupin
  • 27
  • 5

2 Answers2

0

You can't store variables in .env file and access them using process.env directly in react native.

To achieve this you need to integrate react-native-config library.

Pasindu Dilshan
  • 366
  • 1
  • 15
  • Thanks. I have considered this, but for the purposes of my test script, it is far more convenient to pass them in as a bash variable from the build call. (earlier in the script, I use the same variables to create a user through the companion web app) This was working before, so I am less interested in finding a new solution than I am in fixing things to work as they were. – ismaupin Sep 23 '21 at 14:59
  • Can I know where exactly you're passing these bash variables into ? Better if you can update the entire script & flow to give an idea about the whole thing. – Pasindu Dilshan Sep 23 '21 at 15:04
  • Of course. The bash script prompts for variables of PLATFORM, TESTING_ENVIRONMENT, EMAIL, PASSWORD. When stored, these variables configure a call to our web app to run a rake task to create a fresh user. Once created EMAIL and PASSWORD get passed into the build commands for ios/android to be accessed in Detox as string constants used to login and access the application. The variables are defined as in the example above, and have worked successfully in the past, but have mysteriously stopped working at all, and return undefined. – ismaupin Sep 23 '21 at 15:14
  • I think that this may actually be an issue with detox/jest-circus/metro. Node takes bash variables and adds them to the ENV as expected. For some reason, they are not taking the passed-in variables from my shell script. I don't know what I possibly could have changed to affect this. – ismaupin Sep 23 '21 at 20:53
0

I figured it out. I recently modified my bash script to read the variable values, and have them then passed in on the build call. Turns out, those need to be passed in when I call the script itself. So I solved the issue by nesting the script inside of another that reads the variables and then passes them in appropriately.

Any explanation as to why this script nesting works and not a single script would definitely be appreciated.

ismaupin
  • 27
  • 5