Setting up Environment Variables in Mocha
When running TypeScript tests using the great mocha library, you may want to set environment variables that are only valid for your test process.
This comment on GitHub details on how to do just that.
In your mocha.opts which is referred to in your
package.json file for
The above will require a
mocha.env file to be sourced before your tests are
mocha.env.ts referenced by the options:
ts process.env.NODE_ENV = 'test';
From here, the
NODE_ENV environment variable will be set to
test, you can
then use the value of this environment variable as a global constant to
determine the logic of your application.