I am new to Mocha, so this may be a trivial question, but have not yet found the answer:
I have a simple NodeJS project with the underlying package. json
{ "name": "test", "version": "1.0.0", "description": "test", "main": "index.js", "scripts": { "test": "mocha" }, "author": "davide talesco", "license": "ISC", "devDependencies": { "chai": "^4.0.2", "mocha": "^3.4.2" } }
and the following test files in the test folder:
test1.js
process.env.NODE_ENV = 'test'; var chai = require('chai'); var should = chai.should(); describe('Test setProp', function(){ it('env variable should be test', function(done){ process.env.NODE_ENV.should.be.equal('test'); return done(); }); });
test2.js
process.env.NODE_ENV = 'prod'; var chai = require('chai'); var should = chai.should(); describe('Test setProp', function(){ it('env variable should be prod', function(done){ process.env.NODE_ENV.should.be.equal('prod'); return done(); }); });
when I run the test on npm, the first test succeeds and the second fails as shown below
ie-macp-davidt:crap davide_talesco$ npm test > pc-lib@1.0.0 test /Users/davide_talesco/development/crap > mocha Test setProp 1) env variable should be test Test setProp β env variable should be prod 1 passing (16ms) 1 failing 1) Test setProp env variable should be test: AssertionError: expected 'prod' to equal 'test' + expected - actual -prod +test at Context.<anonymous> (test/test1.js:11:36) npm ERR! Test failed. See above for more details.
itβs pretty clear that the tests work under the same process ... my question is: how can I make them work under completely separate processes so that everyone can set their own environment?
Thanks,
David