Skip to content

Commit

Permalink
fix: fix ENABLE_MOCHA_PARALLEL/AUTO_AGENT env (#187)
Browse files Browse the repository at this point in the history
  • Loading branch information
killagu committed Nov 9, 2022
1 parent ba5f4d3 commit 88ba6d5
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 7 deletions.
14 changes: 7 additions & 7 deletions lib/cmd/test.js
Expand Up @@ -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;

Expand All @@ -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);
}

Expand Down
2 changes: 2 additions & 0 deletions test/fixtures/bin/fake_mocha.js
@@ -0,0 +1,2 @@
console.log('env.AUTO_AGENT:', process.env.AUTO_AGENT);
console.log('env.ENABLE_MOCHA_PARALLEL:', process.env.ENABLE_MOCHA_PARALLEL);
15 changes: 15 additions & 0 deletions test/lib/cmd/test.test.js
Expand Up @@ -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', /env\.AUTO_AGENT: true/)
.expect('stdout', /env\.ENABLE_MOCHA_PARALLEL: true/)
.expect('code', 0)
.end();
});
});

0 comments on commit 88ba6d5

Please sign in to comment.