Hi,
How do I run testing without creating .env.test?
when I run the test (that inside test folder), it uses the .env file in the main folder.
but I want to run the test with different environment variables.

Hi @shai32, great question.
Ideally, you should mock or set them individually in each test. Here is a nice tool to mock them:
https://www.npmjs.com/package/mock-env
and here is a good example of setting them:
http://stackoverflow.com/questions/24589021/how-to-stub-process-env-in-node-js
mock-env look redundant.
the stackoverflow suggestion is to just change it directly (and return the original value to env after)
but this also is not a good idea. because I have a lot of tests files that all need the same env variables
so I need to write down those variables for each file.
adding .env.test solve all this issues.
Try to work your tests toward smaller chunks - where your test is only dependent on an ENV or two at a time. Mocking really helps with this and mock-env will do the trick for you.
If you really want to include a .env.test you can do so by specifying the path to it, and then call dotenv.config(path: '') inside a before suite hook of your test suite: https://github.com/motdotla/dotenv#path
@mostlyjason yea I used the path options, works great.
Hi @motdotla and @shai32
I'm working on Unit Test of angular 2. I use Dotenv for defining application variables for Dev and Prod env.
Now I want to use for my test. Could you show me the way in details ?
Thanks
Nam
Most helpful comment
Try to work your tests toward smaller chunks - where your test is only dependent on an ENV or two at a time. Mocking really helps with this and
mock-envwill do the trick for you.If you really want to include a
.env.testyou can do so by specifying the path to it, and then calldotenv.config(path: '')inside a before suite hook of your test suite: https://github.com/motdotla/dotenv#path