mocha : how to run multiple JS test files under separate process environment -
i new mocha might trivial question couldn't yet find answer:
i have simple nodejs project 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 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 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 prod', function(done){ process.env.node_env.should.be.equal('prod'); return done(); }); }); when run npm test first test complete succesfully whilst second fails 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 test test setprop ✓ env variable should prod 1 passing (16ms) 1 failing 1) test setprop env variable should test: assertionerror: expected 'prod' equal 'test' + expected - actual -prod +test @ context.<anonymous> (test/test1.js:11:36) npm err! test failed. see above more details. its pretty clear tests running under same process... question : how can make them run under separate processes each 1 can set own environment?
thanks,
davide
Comments
Post a Comment