I am new to Mocha so this might probably be a trivial question but couldn't yet find an answer:
I have a simple NodeJS project with the below 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 2 tests files under 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 npm test the first test complete succesfully whilst the second fails as per 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.
its pretty clear that the tests are running under the same process... my question is : how can I make them run under completely separate processes so each one can set its own environment?
Thanks,
Davide