Skip to content

Commit

Permalink
feat(cov): add prerequire option (#53)
Browse files Browse the repository at this point in the history
Pick from a6a2b4a
  • Loading branch information
popomore authored and fengmk2 committed Jun 21, 2017
1 parent 1a51f95 commit 055c47f
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 7 deletions.
16 changes: 9 additions & 7 deletions lib/cmd/cov.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)) {
Expand Down Expand Up @@ -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',
Expand Down
17 changes: 17 additions & 0 deletions test/lib/cmd/cov.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
});
});

0 comments on commit 055c47f

Please sign in to comment.