$NODE_ENV to "test".
Works best with
Because to force environment, I was used to add
process.env.NODE_ENV = "test" at the beginning of every test file.
Because relying on
package.json to set this environment is almost always OK, but when one user just throws
mocha in his terminal we don't want to punish him with data loss or any other hell.
Whereas relying on
mocha.opts makes it easy (no more ugly line in each test file) and reliable (always loaded).
- Install with
npm install --save-dev env-test
test/mocha.optsand add the line