Skip to content

Commit

Permalink
Merge 937efb4 into 13cd75d
Browse files Browse the repository at this point in the history
  • Loading branch information
dougwilson committed Aug 3, 2014
2 parents 13cd75d + 937efb4 commit 2526db2
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 3 deletions.
1 change: 1 addition & 0 deletions .jshintignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
lib/vendor
test/cli/sample-project
test/cli/sample-project-link
test/browser/support/vendor


18 changes: 15 additions & 3 deletions lib/util/file-matcher.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@
Copyrights licensed under the New BSD License. See the accompanying LICENSE file for terms.
*/

var fileset = require('fileset'),
var async = require('async'),
fileset = require('fileset'),
fs = require('fs'),
path = require('path'),
seq = 0;

Expand All @@ -17,6 +19,7 @@ function filesFor(options, callback) {
var root = options.root,
includes = options.includes,
excludes = options.excludes,
realpath = options.realpath,
relative = options.relative,
opts;

Expand All @@ -29,10 +32,18 @@ function filesFor(options, callback) {
opts['x' + seq + new Date().getTime()] = true; //cache buster for minimatch cache bug
fileset(includes.join(' '), excludes.join(' '), opts, function (err, files) {
if (err) { return callback(err); }
if (!relative) {
if (relative) { return callback(err, files); }

if (!realpath) {
files = files.map(function (file) { return path.resolve(root, file); });
return callback(err, files);
}
callback(err, files);

var realPathCache = module.constructor._realpathCache || {};

async.map(files, function (file, done) {
fs.realpath(path.resolve(root, file), realPathCache, done);
}, callback);
});
}

Expand All @@ -44,6 +55,7 @@ function matcherFor(options, callback) {
}
options = options || {};
options.relative = false; //force absolute paths
options.realpath = true; //force real paths (to match Node.js module paths)

filesFor(options, function (err, files) {
var fileMap = {},
Expand Down
32 changes: 32 additions & 0 deletions test/cli/test-cover-command.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ var path = require('path'),
mkdirp = require('mkdirp'),
COMMAND = 'cover',
DIR = path.resolve(__dirname, 'sample-project'),
DIR_LINK = path.resolve(__dirname, 'sample-project-link'),
OUTPUT_DIR = path.resolve(DIR, 'coverage'),
helper = require('../cli-helper'),
existsSync = fs.existsSync || path.existsSync,
Expand Down Expand Up @@ -199,5 +200,36 @@ module.exports = {
test.ok(results.succeeded());
test.done();
});
},
"should cover tests when under symlink": function (test) {
try {
fs.symlinkSync(DIR, DIR_LINK);
} catch (ex) {
if (ex.code === 'EPERM') {
console.error('#');
console.error('# Skipping symlink test');
console.error('# ' + ex.message);
console.error('#');
test.ok(true);
test.done();
} else {
throw ex;
}
return;
}
helper.setOpts({ cwd: DIR_LINK, lazyHook : true });
run([ 'test/run.js', '-v' ], 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/) || k.match(/bar/); });
test.ok(filtered.length === 2);
fs.unlinkSync(DIR_LINK);
test.done();
});
}
};

0 comments on commit 2526db2

Please sign in to comment.