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

[BUGFIX] Add support for multiple -i args for cover command #756

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
34 changes: 33 additions & 1 deletion lib/util/file-matcher.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,38 @@ var async = require('async'),
path = require('path'),
seq = 0;

function joinGlobResults(results) {
var uniqNames = {};

return results.reduce(function (uniqFiles, files) {
return files.reduce(function (acc, fileName) {
if (!uniqNames[fileName]) {
uniqNames[fileName] = true;
acc.push(fileName);
}

return acc;
}, uniqFiles);
}, []);
}

function globMany(patterns, opts, callback) {
var args = patterns.map(function (pattern) {
return function (callback) {
glob(pattern, opts, callback);
};
});

async.parallel(args, function (err, results) {
if (err) {
callback(err);
return;
}

callback(null, joinGlobResults(results));
});
}

function filesFor(options, callback) {
if (!callback && typeof options === 'function') {
callback = options;
Expand All @@ -30,7 +62,7 @@ function filesFor(options, callback) {
opts = { cwd: root, nodir: true, ignore: excludes };
seq += 1;
opts['x' + seq + new Date().getTime()] = true; //cache buster for minimatch cache bug
glob(includes.join(' '), opts, function (err, files) {
globMany(includes, opts, function (err, files) {
if (err) { return callback(err); }
if (relative) { return callback(err, files); }

Expand Down
17 changes: 17 additions & 0 deletions test/cli/test-cover-command.js
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,23 @@ module.exports = {
test.done();
});
},
"should cover tests as expected without extra noise and using multiple includes": function (test) {
helper.setOpts({ lazyHook : true });
run([ 'test/run.js', '-i', '**/foo.js', '-i', '**/bar.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