Skip to content

Commit

Permalink
feat(cov): add prerequire option (#53)
Browse files Browse the repository at this point in the history
  • Loading branch information
popomore authored and fengmk2 committed May 18, 2017
1 parent 93bf537 commit a6a2b4a
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 0 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,7 @@ Coverage reporter will output text-summary, json and lcov.
You can pass any mocha argv.

- `-x` add dir ignore coverage, support multiple argv
- `--prerequire` prerequire files for coverage instrument, you can use this options if load files slowly when call `mm.app` or `mm.cluster`
- also support all test params above.

#### environment
Expand Down
8 changes: 8 additions & 0 deletions lib/cmd/cov.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,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 Down Expand Up @@ -48,6 +52,10 @@ class CovCommand extends Command {
process.env.NODE_ENV = 'test';
process.env.TMPDIR = tmpDir;

if (argv.prerequire) {
process.env.EGG_BIN_PREREQUIRE = 'true';
}

// istanbul coverage ignore
if (argv.x) {
this[EXCLUDES].add(argv.x);
Expand Down
3 changes: 3 additions & 0 deletions test/fixtures/prerequire/test/index.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
'use strict';

console.log('EGG_BIN_PREREQUIRE', process.env.EGG_BIN_PREREQUIRE);
17 changes: 17 additions & 0 deletions test/lib/cmd/cov.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,23 @@ describe('test/lib/cmd/cov.test.js', () => {
.expect('code', 1)
.end(done);
});

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();
});
});
} else {
it('should exec test instead of cov in win32', done => {
Expand Down

0 comments on commit a6a2b4a

Please sign in to comment.