diff --git a/lib/cmd/cov.js b/lib/cmd/cov.js index e8c96b4a..41e73814 100644 --- a/lib/cmd/cov.js +++ b/lib/cmd/cov.js @@ -22,6 +22,10 @@ class CovCommand extends Command { description: 'istanbul coverage ignore, one or more fileset patterns', type: 'string', }, + prerequire: { + description: 'prerequire files for coverage instrument', + type: 'boolean', + }, }; // you can add ignore dirs here @@ -44,6 +48,11 @@ class CovCommand extends Command { * run(context) { const { cwd, argv, execArgv, env } = context; + if (argv.prerequire) { + env.EGG_BIN_PREREQUIRE = 'true'; + } + delete argv.prerequire; + // ignore coverage if (argv.x) { if (Array.isArray(argv.x)) { @@ -99,13 +108,6 @@ class CovCommand extends Command { getCovArgs(context) { let covArgs = [ // '--show-process-tree', - // instrument all files in nyc process and cache to disk, - // Then in mocha process, read instrumented files from cache. - // - // nyc - // `- egg-bin test - // `- mocha - '--all', '--temp-directory', './node_modules/.nyc_output', '-r', 'text-summary', '-r', 'json-summary', diff --git a/test/lib/cmd/cov.test.js b/test/lib/cmd/cov.test.js index 0ab95084..e7ce0d39 100644 --- a/test/lib/cmd/cov.test.js +++ b/test/lib/cmd/cov.test.js @@ -148,4 +148,21 @@ describe('test/lib/cmd/cov.test.js', () => { .expect('code', 0) .end(); }); + + it('should set EGG_BIN_PREREQUIRE', function* () { + const cwd = path.join(__dirname, '../../fixtures/prerequire'); + yield coffee.fork(eggBin, [ 'cov' ], { cwd }) + // .debug() + .coverage(false) + .expect('stdout', /EGG_BIN_PREREQUIRE undefined/) + .expect('code', 0) + .end(); + + yield coffee.fork(eggBin, [ 'cov', '--prerequire' ], { cwd }) + // .debug() + .coverage(false) + .expect('stdout', /EGG_BIN_PREREQUIRE true/) + .expect('code', 0) + .end(); + }); });