Skip to content

Commit

Permalink
support explicit includes for cover + tests
Browse files Browse the repository at this point in the history
  • Loading branch information
tonylukasavage committed Dec 10, 2014
1 parent 5a951b7 commit 5b99059
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 2 deletions.
6 changes: 4 additions & 2 deletions lib/command/common/run-with-cover.js
Expand Up @@ -26,6 +26,7 @@ function usage(arg0, command) {
formatOption('--config <path-to-config>', 'the configuration file to use, defaults to .istanbul.yml'),
formatOption('--root <path> ', 'the root path to look for files to instrument, defaults to .'),
formatOption('-x <exclude-pattern> [-x <exclude-pattern>]', 'one or more fileset patterns e.g. "**/vendor/**"'),
formatOption('-i <include-pattern> [-x <include-pattern>]', 'one or more fileset patterns e.g. "**/*.js"'),
formatOption('--[no-]default-excludes', 'apply default excludes [ **/node_modules/**, **/test/**, **/tests/** ], defaults to true'),
formatOption('--hook-run-in-context', 'hook vm.runInThisContext in addition to require (supports RequireJS), defaults to false'),
formatOption('--post-require-hook <file> | <module>', 'JS module that exports a function for post-require processing'),
Expand Down Expand Up @@ -56,7 +57,8 @@ function run(args, commandName, enableHooks, callback) {
'post-require-hook': String,
'preserve-comments': Boolean,
'include-all-sources': Boolean,
'preload-sources': Boolean
'preload-sources': Boolean,
i: [ Array, String ]
},
opts = nopt(template, { v : '--verbose' }, args, 0),
overrides = {
Expand Down Expand Up @@ -140,7 +142,7 @@ function run(args, commandName, enableHooks, callback) {
excludes.push(path.relative(process.cwd(), path.join(reportingDir, '**', '*')));
matcherFor({
root: config.instrumentation.root() || process.cwd(),
includes: [ '**/*.js' ],
includes: opts.i || [ '**/*.js' ],
excludes: excludes
},
function (err, matchFn) {
Expand Down
17 changes: 17 additions & 0 deletions test/cli/test-cover-command.js
Expand Up @@ -117,6 +117,23 @@ module.exports = {
test.done();
});
},
"should cover tests as expected without extra noise and using includes": function (test) {
helper.setOpts({ lazyHook : true });
run([ 'test/run.js', '-i', '**/foo.js' ], function (results) {
test.ok(results.succeeded());
test.ok(!results.grepError(/Module load hook:/));
test.ok(existsSync(path.resolve(OUTPUT_DIR, 'lcov.info')));
test.ok(existsSync(path.resolve(OUTPUT_DIR, 'lcov-report')));
test.ok(existsSync(path.resolve(OUTPUT_DIR, 'coverage.json')));
var coverage = JSON.parse(fs.readFileSync(path.resolve(OUTPUT_DIR, 'coverage.json'), 'utf8')),
filtered;
filtered = Object.keys(coverage).filter(function (k) { return k.match(/foo/); });
test.ok(filtered.length !== 0);
filtered = Object.keys(coverage).filter(function (k) { return k.match(/bar/); });
test.ok(filtered.length === 0);
test.done();
});
},
"should skip reporting when requested": function (test) {
helper.setOpts({ lazyHook : true });
run([ 'test/run.js', '--report', 'none', '--print', 'detail' ], function (results) {
Expand Down

0 comments on commit 5b99059

Please sign in to comment.