You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I had some trouble getting the tests to work on travis mainly because travis was complaining that it can't find the config.env file (as we have added it to .gitignore file)
So I used travis cli to encrypt the environment variables and add them to our .travis.yml file so travis can access them when running the tests ( see: https://docs.travis-ci.com/user/environment-variables/#Encrypting-environment-variables ) however the problem with this is that tests done locally do not work (using npm run test) because it needs to read the environment variables from the config.env using env2.
I added a workaround to this by adding the following code (check email.js)
if (process.env.TRAVIS !== true) {
require('env2')('./config.env')
}
This code checks if the current environment is not travis, and if true will load the environment variables from the config.env file.
This is a working solution, as both tests now work locally and on travis however this is going to be quite cumbersome to keep on adding this code whenever we want to load in the environment variables - for example, when working with our database.
I'm just thinking if we have multiple files which will need to access environment variables this will not be an elegant solution, as we will keep on having to paste in that code.
However, we could instead encrypt our config.env file using travis, host it on github and then add a line of code which will decrypt the file and load our environment variables when we build our project.
This way we don't need to worry which environment we are on when loading our environment variables:
I had some trouble getting the tests to work on travis mainly because travis was complaining that it can't find the config.env file (as we have added it to .gitignore file)
So I used travis cli to encrypt the environment variables and add them to our .travis.yml file so travis can access them when running the tests ( see: https://docs.travis-ci.com/user/environment-variables/#Encrypting-environment-variables ) however the problem with this is that tests done locally do not work (using npm run test) because it needs to read the environment variables from the config.env using env2.
I added a workaround to this by adding the following code (check email.js)
This code checks if the current environment is not travis, and if true will load the environment variables from the config.env file.
This is a working solution, as both tests now work locally and on travis however this is going to be quite cumbersome to keep on adding this code whenever we want to load in the environment variables - for example, when working with our database.
I'm just thinking if we have multiple files which will need to access environment variables this will not be an elegant solution, as we will keep on having to paste in that code.
However, we could instead encrypt our config.env file using travis, host it on github and then add a line of code which will decrypt the file and load our environment variables when we build our project.
This way we don't need to worry which environment we are on when loading our environment variables:
See here for more info how to encrypt a file using travis cli: https://github.com/travis-ci/travis.rb#encrypt-file
The text was updated successfully, but these errors were encountered: