Skip to content

Commit

Permalink
fix: should support multi exclude dirs (#66)
Browse files Browse the repository at this point in the history
 100% coverage
  • Loading branch information
fengmk2 authored Jun 20, 2017
1 parent 0a6cce8 commit 1ac9d68
Show file tree
Hide file tree
Showing 4 changed files with 67 additions and 8 deletions.
10 changes: 8 additions & 2 deletions lib/cmd/cov.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,12 +45,18 @@ class CovCommand extends Command {

// ignore coverage
if (argv.x) {
this[EXCLUDES].add(argv.x);
if (Array.isArray(argv.x)) {
for (const exclude of argv.x) {
this.addExclude(exclude);
}
} else {
this.addExclude(argv.x);
}
argv.x = undefined;
}
const excludes = (process.env.COV_EXCLUDES && process.env.COV_EXCLUDES.split(',')) || [];
for (const exclude of excludes) {
this[EXCLUDES].add(exclude);
this.addExclude(exclude);
}

const nycCli = require.resolve('nyc/bin/nyc.js');
Expand Down
9 changes: 9 additions & 0 deletions test/fixtures/mocha-test/test/foo.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
'use strict';

const assert = require('assert');

describe('mocha-test', () => {
it('should work', () => {
assert(true);
});
});
39 changes: 33 additions & 6 deletions test/lib/cmd/cov.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ describe('test/lib/cmd/cov.test.js', () => {
mm(process.env, 'TESTS', 'test/**/*.test.js');
mm(process.env, 'NYC_CWD', cwd);
const child = coffee.fork(eggBin, [ 'cov' ], { cwd })
.debug()
// .debug()
.expect('stdout', /should success/)
.expect('stdout', /a\.test\.js/)
.expect('stdout', /b[\/|\\]b\.test\.js/)
Expand Down Expand Up @@ -62,15 +62,42 @@ describe('test/lib/cmd/cov.test.js', () => {
assert(!/ignore[\/|\\]a.js/.test(lcov));
});

it('should success with -x to ignore files', function* () {
yield coffee.fork(eggBin, [ 'cov', '-x', 'ignore/*', 'test/**/*.test.js' ], { cwd })
it('should success with -x to ignore one dirs', function* () {
const child = coffee.fork(eggBin, [ 'cov', '-x', 'ignore/', 'test/**/*.test.js' ], { cwd })
// .debug()
.expect('stdout', /should success/)
.expect('stdout', /a\.test\.js/)
.expect('stdout', /b[\/|\\]b\.test\.js/)
.notExpect('stdout', /a.js/)
// .expect('stdout', /Statements {3}: 75% \( 3[\/|\\]4 \)/)
.expect('code', 0)
.notExpect('stdout', /a.js/);

// only test on npm run test
if (!process.env.NYC_ROOT_ID) {
child.expect('stdout', /Statements {3}: 75% \( 3[\/|\\]4 \)/);
}

yield child.expect('code', 0)
.end();
assert(fs.existsSync(path.join(cwd, 'coverage/coverage-final.json')));
assert(fs.existsSync(path.join(cwd, 'coverage/lcov-report/index.html')));
assert(fs.existsSync(path.join(cwd, 'coverage/lcov.info')));
const lcov = fs.readFileSync(path.join(cwd, 'coverage/lcov.info'), 'utf8');
assert(!/ignore[\/|\\]a.js/.test(lcov));
});

it('should success with -x to ignore multi dirs', function* () {
const child = coffee.fork(eggBin, [ 'cov', '-x', 'ignore2/*', '-x', 'ignore/', 'test/**/*.test.js' ], { cwd })
// .debug()
.expect('stdout', /should success/)
.expect('stdout', /a\.test\.js/)
.expect('stdout', /b[\/|\\]b\.test\.js/)
.notExpect('stdout', /a.js/);

// only test on npm run test
if (!process.env.NYC_ROOT_ID) {
child.expect('stdout', /Statements {3}: 75% \( 3[\/|\\]4 \)/);
}

yield child.expect('code', 0)
.end();
assert(fs.existsSync(path.join(cwd, 'coverage/coverage-final.json')));
assert(fs.existsSync(path.join(cwd, 'coverage/lcov-report/index.html')));
Expand Down
17 changes: 17 additions & 0 deletions test/mocha-bin.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
'use strict';

const path = require('path');
const coffee = require('coffee');

describe('test/mocha-bin.test.js', () => {
const mochaBin = require.resolve('../bin/mocha.js');
const cwd = path.join(__dirname, 'fixtures/mocha-test');

it('should test with mocha', () => {
return coffee.fork(mochaBin, [ 'test/*.test.js' ], { cwd })
.debug()
.expect('stdout', /1 passing/)
.expect('code', 0)
.end();
});
});

0 comments on commit 1ac9d68

Please sign in to comment.