Skip to content

Dotenv and tests #62

Description

@slifty

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.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    Priority

    None yet

    Size

    None yet

    Target date

    None yet

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions