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: -x only support string #47

Merged
merged 1 commit into from
Mar 31, 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
11 changes: 8 additions & 3 deletions lib/cmd/cov.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ class CovCommand extends Command {
this.options = {
x: {
description: 'istanbul coverage ignore, one or more fileset patterns',
type: 'array',
type: 'string',
},
};

Expand All @@ -43,17 +43,21 @@ class CovCommand extends Command {
process.env.TMPDIR = tmpDir;

// istanbul coverage ignore
const excludes = argv.x || (process.env.COV_EXCLUDES && process.env.COV_EXCLUDES.split(',')) || [];
if (argv.x) {
this[EXCLUDES].add(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);
}
argv.x = undefined;

const covFile = require.resolve('istanbul/lib/cli.js');
const coverageDir = path.join(cwd, 'coverage');
yield rimraf(coverageDir);

const opt = {
cwd,
execArgv,
// resolve istanbul path for coffee
env: Object.assign({
Expand All @@ -69,6 +73,7 @@ class CovCommand extends Command {

// create coverage report
const reportArgs = this.getReportArgs(coverageDir);
debug('reportArgs: %j', reportArgs);
yield this.helper.forkNode(covFile, reportArgs, opt);
}

Expand Down
3 changes: 3 additions & 0 deletions test/fixtures/test-files/ignore/a.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
'use strict';

module.exports = '';
10 changes: 10 additions & 0 deletions test/fixtures/test-files/test/ignore.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
'use strict';

const assert = require('assert');
const a = require('../ignore/a');

describe('ignore.test.js', () => {
it('should success', () => {
assert(a === '');
});
});
45 changes: 32 additions & 13 deletions test/lib/cmd/cov.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ describe('test/lib/cmd/cov.test.js', () => {
.expect('stdout', /a\.test\.js/)
.expect('stdout', /b\/b\.test\.js/)
.notExpect('stdout', /a.js/)
.expect('stdout', /Statements {3}: 75% \( 3\/4 \)/)
.expect('stdout', /Statements {3}: 80% \( 4\/5 \)/)
.expect('code', 0)
.end(err => {
assert.ifError(err);
Expand All @@ -37,27 +37,46 @@ describe('test/lib/cmd/cov.test.js', () => {
});
});

it('should success with COV_EXCLUDES', done => {
it('should success with COV_EXCLUDES', function* () {
mm(process.env, 'TESTS', 'test/**/*.test.js');
mm(process.env, 'COV_EXCLUDES', 'lib/*');
coffee.fork(eggBin, [ 'cov' ], { cwd })
mm(process.env, 'COV_EXCLUDES', 'ignore/*');
yield coffee.fork(eggBin, [ 'cov' ], { cwd })
.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/)
.notExpect('stdout', /a.js/)
.expect('stdout', /Statements {3}: Unknown% \( 0\/0 \)/)
.expect('stdout', /Statements {3}: 75% \( 3\/4 \)/)
.expect('code', 0)
.end(err => {
assert(!err);
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')));
assert(!fs.existsSync(path.join(cwd, '.tmp')));
done();
});
.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')));
assert(!fs.existsSync(path.join(cwd, '.tmp')));
const lcov = fs.readFileSync(path.join(cwd, 'coverage/lcov.info'), 'utf8');
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 })
.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/)
.notExpect('stdout', /a.js/)
.expect('stdout', /Statements {3}: 75% \( 3\/4 \)/)
.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')));
assert(!fs.existsSync(path.join(cwd, '.tmp')));
const lcov = fs.readFileSync(path.join(cwd, 'coverage/lcov.info'), 'utf8');
assert(!/ignore\/a.js/.test(lcov));
});

it('should fail when test fail', done => {
Expand Down