diff --git a/README.md b/README.md index 01ed8100..0a751ef3 100644 --- a/README.md +++ b/README.md @@ -170,6 +170,14 @@ 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` - `--typescript` / `--ts` enable typescript support, default to `false`, if true, will auto add `.ts` extension and ignore `typings` and `d.ts`. +- `--nyc` nyc instruments passthrough. you can use this to overwrite egg-bin's default nyc instruments and add additional ones. + >if you want to add addtional nyc reporters, you need to use this rather than add `reporter` key in `.nycrc` because: + >* when same key exists in `.nycrc` and cmd instruments, nyc prefers instrument. + >* egg-bin have some default instruments passed to nyc like `-r` and `--temp-directory` + ```bash + egg-bin cov --nyc="-r teamcity -r text" + ``` + - also support all test params above. #### environment diff --git a/lib/cmd/cov.js b/lib/cmd/cov.js index c2dad72f..d0cb824f 100644 --- a/lib/cmd/cov.js +++ b/lib/cmd/cov.js @@ -25,6 +25,11 @@ class CovCommand extends Command { description: 'prerequire files for coverage instrument', type: 'boolean', }, + nyc: { + description: 'nyc instruments passthrough', + type: 'string', + default: '--temp-directory ./node_modules/.nyc_output -r text-summary -r json-summary -r json -r lcov', + }, }; // you can add ignore dirs here @@ -102,11 +107,6 @@ class CovCommand extends Command { getCovArgs(context) { let covArgs = [ // '--show-process-tree', - '--temp-directory', './node_modules/.nyc_output', - '-r', 'text-summary', - '-r', 'json-summary', - '-r', 'json', - '-r', 'lcov', ]; // typescript support @@ -116,6 +116,13 @@ class CovCommand extends Command { this.addExclude('**/*.d.ts'); } + // nyc args passthrough + const nycArgs = context.argv.nyc; + context.argv.nyc = undefined; + if (nycArgs) { + covArgs = covArgs.concat(nycArgs.split(' ')); + } + for (const exclude of this[EXCLUDES]) { covArgs.push('-x'); covArgs.push(exclude); diff --git a/test/lib/cmd/cov.test.js b/test/lib/cmd/cov.test.js index 5558ba55..f8201c55 100644 --- a/test/lib/cmd/cov.test.js +++ b/test/lib/cmd/cov.test.js @@ -198,4 +198,15 @@ describe('test/lib/cmd/cov.test.js', () => { .expect('code', 0) .end(); }); + + it('should passthrough nyc args', done => { + mm(process.env, 'TESTS', 'test/**/*.test.js'); + mm(process.env, 'NYC_CWD', cwd); + coffee.fork(eggBin, [ 'cov', '--nyc=-r teamcity -r text' ], { cwd }) + // .debug() + .expect('stdout', /should success/) + .expect('stdout', /##teamcity\[blockOpened name='Code Coverage Summary'\]/) + .expect('stdout', /##teamcity\[blockClosed name='Code Coverage Summary'\]/) + .end(done); + }); });