Skip to content

Commit

Permalink
fix: -x only support string
Browse files Browse the repository at this point in the history
  • Loading branch information
popomore committed Mar 30, 2017
1 parent cd9c736 commit a9c3b06
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 15 deletions.
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 === '');
});
});
43 changes: 31 additions & 12 deletions test/lib/cmd/cov.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit a9c3b06

Please sign in to comment.