Oh environment variables, how we love thee.
We use dotenv to automatically load the contents of .env for any environment variables that have not been explicitly provided to the node runtime.
The question is whether we want our tests to pull from .env or if we want to provide an engineered way to pass a potentially different set of environment variables when running tests.
OPTION 1: Pull from BOTH .env and .env.test when testing
Have globalSetup call dotenv twice to make the hierarchy explicit:
dotenv.config({ path: '.env.test' });
dotenv.config();
And then it's on the dev to set up .env.test if that is what they want, but it becomes optional if they are OK with just having .env
^ We might consider adding some kind of test safety valve that prevents integration tests from being run against the production database somehow....
OPTION 2: have tests ENSURE that a special .env.test is loaded (and NOT .env)
This would basically mean setting the DOTENV_CONFIG_PATH as part of the test globalSetup
OPTION 3: make it manual
Only ever pull from .env and require the local dev to update to point to a test database before running tests locally.
The downside of this is that we know this will be a needed manual step already.
I'm leaning to Option 1 -- load .env by default but provide a hook to have our tests optionally first pull from .env.test.
Oh environment variables, how we love thee.
We use dotenv to automatically load the contents of
.envfor any environment variables that have not been explicitly provided to the node runtime.The question is whether we want our tests to pull from
.envor if we want to provide an engineered way to pass a potentially different set of environment variables when running tests.OPTION 1: Pull from BOTH
.envand.env.testwhen testingHave
globalSetupcall dotenv twice to make the hierarchy explicit:And then it's on the dev to set up .env.test if that is what they want, but it becomes optional if they are OK with just having
.env^ We might consider adding some kind of test safety valve that prevents integration tests from being run against the production database somehow....
OPTION 2: have tests ENSURE that a special .env.test is loaded (and NOT .env)
This would basically mean setting the
DOTENV_CONFIG_PATHas part of the testglobalSetupOPTION 3: make it manual
Only ever pull from
.envand require the local dev to update to point to a test database before running tests locally.The downside of this is that we know this will be a needed manual step already.
I'm leaning to Option 1 -- load
.envby default but provide a hook to have our tests optionally first pull from.env.test.