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

fix: should support multi exclude dirs #66

Merged
merged 3 commits into from
Jun 20, 2017
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
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();
});
});