From a6a2b4a3f44ffb08e09e09ca372e00f0477573ba Mon Sep 17 00:00:00 2001 From: Haoliang Gao Date: Thu, 18 May 2017 18:35:39 +0800 Subject: [PATCH] feat(cov): add prerequire option (#53) --- README.md | 1 + lib/cmd/cov.js | 8 ++++++++ test/fixtures/prerequire/test/index.test.js | 3 +++ test/lib/cmd/cov.test.js | 17 +++++++++++++++++ 4 files changed, 29 insertions(+) create mode 100644 test/fixtures/prerequire/test/index.test.js diff --git a/README.md b/README.md index 74219721..c8a1cd77 100644 --- a/README.md +++ b/README.md @@ -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 diff --git a/lib/cmd/cov.js b/lib/cmd/cov.js index 9894773c..89b3a370 100644 --- a/lib/cmd/cov.js +++ b/lib/cmd/cov.js @@ -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 @@ -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); diff --git a/test/fixtures/prerequire/test/index.test.js b/test/fixtures/prerequire/test/index.test.js new file mode 100644 index 00000000..456b684e --- /dev/null +++ b/test/fixtures/prerequire/test/index.test.js @@ -0,0 +1,3 @@ +'use strict'; + +console.log('EGG_BIN_PREREQUIRE', process.env.EGG_BIN_PREREQUIRE); diff --git a/test/lib/cmd/cov.test.js b/test/lib/cmd/cov.test.js index 651bd01d..7e12fe67 100644 --- a/test/lib/cmd/cov.test.js +++ b/test/lib/cmd/cov.test.js @@ -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 => {