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 2 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
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,12 @@ 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
> This is primaryly for adding additional nyc reporters because `egg-bin cov` calls `nyc` with some fixed params like `-r json -r lcov...`, which overides `reporter` key in `.nycrc`/`package.json`.
```bash
egg-bin cov --nyc="--reporter=teamcity -r text"
```

- also support all test params above.

#### environment
Expand Down
12 changes: 12 additions & 0 deletions lib/cmd/cov.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,10 @@ 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

},
};

// you can add ignore dirs here
Expand Down Expand Up @@ -116,6 +120,14 @@ class CovCommand extends Command {
this.addExclude('**/*.d.ts');
}

// nyc args passthrough
let nycArgs = context.argv.nyc;
delete context.argv.nyc;
Copy link
Member

Choose a reason for hiding this comment

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

prefer set to undefined

if (nycArgs) {
nycArgs = nycArgs.substring(1, nycArgs.length - 1);
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="--reporter=teamcity"' ], { cwd })
// .debug()
.expect('stdout', /should success/)
.expect('stdout', /##teamcity\[blockOpened name='Code Coverage Summary'\]/)
.expect('stdout', /##teamcity\[blockClosed name='Code Coverage Summary'\]/)
.end(done);
});
});