diff --git a/lib/cmd/test.js b/lib/cmd/test.js index 007dad28..19e60623 100644 --- a/lib/cmd/test.js +++ b/lib/cmd/test.js @@ -68,13 +68,7 @@ class TestCommand extends Command { } async run(context) { - const opt = { - env: Object.assign({ - NODE_ENV: 'test', - }, context.env), - execArgv: context.execArgv, - }; - const mochaFile = require.resolve('mocha/bin/_mocha'); + const mochaFile = process.env.MOCHA_FILE || require.resolve('mocha/bin/_mocha'); const testArgs = await this.formatTestArgs(context); if (!testArgs) return; @@ -92,6 +86,12 @@ class TestCommand extends Command { } debug('run test: %s %s', mochaFile, testArgs.join(' ')); + const opt = { + env: Object.assign({ + NODE_ENV: 'test', + }, context.env), + execArgv: context.execArgv, + }; await this.helper.forkNode(mochaFile, testArgs, opt); } diff --git a/test/fixtures/bin/fake_mocha.js b/test/fixtures/bin/fake_mocha.js new file mode 100644 index 00000000..b0ec8934 --- /dev/null +++ b/test/fixtures/bin/fake_mocha.js @@ -0,0 +1,2 @@ +console.log('env: ', process.env); +console.log('argv: ', process.argv); diff --git a/test/lib/cmd/test.test.js b/test/lib/cmd/test.test.js index dd0b6cb5..31a46e16 100644 --- a/test/lib/cmd/test.test.js +++ b/test/lib/cmd/test.test.js @@ -342,4 +342,19 @@ describe('test/lib/cmd/test.test.js', () => { .expect('code', 0) .end(); }); + + it('env should work', async () => { + mm(process.env, 'TESTS', 'test/**/*.test.js'); + return coffee.fork(eggBin, [ 'test', '--parallel' ], { + cwd: path.join(__dirname, '../../fixtures/test-demo-app'), + env: Object.assign({ + MOCHA_FILE: path.join(__dirname, '../../fixtures/bin/fake_mocha.js'), + }, process.env), + }) + // .debug() + .expect('stdout', /AUTO_AGENT: 'true'/) + .expect('stdout', /ENABLE_MOCHA_PARALLEL: 'true'/) + .expect('code', 0) + .end(); + }); });