Skip to content

Commit

Permalink
feat: add COV_EXCLUDES for coverage excludes (#7)
Browse files Browse the repository at this point in the history
  • Loading branch information
fengmk2 authored Aug 4, 2016
1 parent 1c6bcba commit a33e561
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 3 deletions.
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,14 @@ Using [istanbul] to run code coverage, it support all test params above.

Coverage reporter will output text-summary, json and lcov.

#### excludes

You can set `COV_EXCLUDES` env to add dir ignore coverage.

```bash
$ COV_EXCLUDES="app/plugins/c*,app/autocreate/**" egg-bin cov
```

## Custom egg-bin for your team

You maybe need a custom egg-bin to implement more custom features
Expand Down
8 changes: 8 additions & 0 deletions README.zh-CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,14 @@ TEST_TIMEOUT=2000 egg-bin test

支持的表报有 text-summary,json,lcov,并通过 [alicov] 上传。

#### excludes

可以通过设置 `COV_EXCLUDES` 环境变量忽略对指定目录的代码覆盖率测试。

```bash
$ COV_EXCLUDES="app/plugins/c*,app/autocreate/**" egg-bin cov
```

## 定制属于你团队的 egg-bin

如果你的团队已经基于 egg 开发了属于自己的框架,那么很可能你会需要在 egg-bin 上做更多自定义功能。
Expand Down
6 changes: 6 additions & 0 deletions lib/cov_command.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,12 @@ class CovCommand extends Command {
'examples/**',
'mocks_*/**',
];
if (process.env.COV_EXCLUDES) {
const excludes = process.env.COV_EXCLUDES.split(',');
for (const exclude of excludes) {
this.excludes.push(exclude);
}
}
}

* run(cwd, args) {
Expand Down
28 changes: 25 additions & 3 deletions test/egg-cov.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,17 +28,39 @@ describe('egg-bin cov', () => {
.end((err, res) => {
assert.ifError(err);
assert.ok(!/a.js/.test(res.stdout));
// 测试 report json
assert.ok(fs.existsSync(path.join(appdir, 'coverage/coverage-final.json')));
// 测试 report lcov
assert.ok(fs.existsSync(path.join(appdir, 'coverage/lcov-report/index.html')));
assert.ok(fs.existsSync(path.join(appdir, 'coverage/lcov.info')));
// 已删除
assert.ok(!fs.existsSync(path.join(appdir, '.tmp')));
done();
});
});

it('should success with COV_EXCLUDES', done => {
mm(process.env, 'TESTS', 'test/**/*.test.js');
mm(process.env, 'COV_EXCLUDES', 'lib/*');
coffee.fork(eggBin, [ 'cov' ], {
cwd: appdir,
})
.coverage(false)
// .debug()
.expect('stdout', /\/test\/fixtures\/test-files\/\.tmp true/)
.expect('stdout', /✓ should success/)
.expect('stdout', /a\.test\.js/)
.expect('stdout', /b\/b\.test\.js/)
.expect('stdout', /Statements {3}: 100% \( 0\/0 \)/)
.expect('code', 0)
.end((err, res) => {
assert(!err);
assert(!/a.js/.test(res.stdout));
assert(fs.existsSync(path.join(appdir, 'coverage/coverage-final.json')));
assert(fs.existsSync(path.join(appdir, 'coverage/lcov-report/index.html')));
assert(fs.existsSync(path.join(appdir, 'coverage/lcov.info')));
assert(!fs.existsSync(path.join(appdir, '.tmp')));
done();
});
});

it('should fail when test fail', done => {
mm(process.env, 'TESTS', 'test/fail.js');
coffee.fork(eggBin, [ 'cov' ], {
Expand Down

0 comments on commit a33e561

Please sign in to comment.