Skip to content

Commit

Permalink
fix: fix cov env (#188)
Browse files Browse the repository at this point in the history
  • Loading branch information
killagu authored Nov 10, 2022
1 parent f5c3538 commit e18ceda
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 1 deletion.
9 changes: 8 additions & 1 deletion lib/cmd/cov.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,12 @@ class CovCommand extends Command {
for (const exclude of excludes) {
this.addExclude(exclude);
}
if (context.argv.parallel) {
env.ENABLE_MOCHA_PARALLEL = 'true';
}
if (context.argv.parallel && context.argv['auto-agent']) {
env.AUTO_AGENT = 'true';
}

const opt = {
cwd,
Expand Down Expand Up @@ -136,7 +142,8 @@ class CovCommand extends Command {
}

getTestCommandAndArgs() {
return [ require.resolve('mocha/bin/_mocha') ];
const mochaFile = process.env.MOCHA_FILE || require.resolve('mocha/bin/_mocha');
return [ mochaFile ];
}
}

Expand Down
2 changes: 2 additions & 0 deletions test/fixtures/bin/fake_mocha.js
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
#!/usr/bin/env node

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/cov.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -185,4 +185,19 @@ describe('test/lib/cmd/cov.test.js', () => {
.expect('stdout', /Statements/)
.end();
});

it('env should work', async () => {
mm(process.env, 'TESTS', 'test/**/*.test.js');
return coffee.fork(eggBin, [ 'cov', '--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 e18ceda

Please sign in to comment.