diff --git a/lib/util/file-matcher.js b/lib/util/file-matcher.js index 98606425..e147155f 100644 --- a/lib/util/file-matcher.js +++ b/lib/util/file-matcher.js @@ -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; @@ -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); } diff --git a/test/cli/test-cover-command.js b/test/cli/test-cover-command.js index c4043b51..67310a2b 100644 --- a/test/cli/test-cover-command.js +++ b/test/cli/test-cover-command.js @@ -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) {