Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(cov): add nyc instrument passthrough #103

Merged
merged 3 commits into from
Jul 30, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

markdown style, if you want to use ref, should add space after >

or change to - if for secondary list

>* 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',
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

how about move covArgs to this default value ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

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);
});
});