Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: fix ENABLE_MOCHA_PARALLEL/AUTO_AGENT env #187

Merged
merged 1 commit into from Nov 9, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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');
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

cov 按道理默认继承会支持的。

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();
});
});