Skip to content

Commit

Permalink
feat(cov): add nyc instrument passthrough (#103)
Browse files Browse the repository at this point in the history
  • Loading branch information
yinseny authored and atian25 committed Jul 30, 2018
1 parent 4a8805e commit 8fa805b
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 5 deletions.
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
17 changes: 12 additions & 5 deletions lib/cmd/cov.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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);
Expand Down
11 changes: 11 additions & 0 deletions test/lib/cmd/cov.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});
});

0 comments on commit 8fa805b

Please sign in to comment.