Skip to content

Commit

Permalink
Merge f447bc4 into 1242e83
Browse files Browse the repository at this point in the history
  • Loading branch information
dragn committed Mar 5, 2015
2 parents 1242e83 + f447bc4 commit fbb0d01
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 3 deletions.
14 changes: 12 additions & 2 deletions lib/command/check-coverage.js
Expand Up @@ -14,6 +14,12 @@ var nopt = require('nopt'),
Command = require('./index'),
configuration = require('../config');

if (!path.isAbsolute) {
path.isAbsolute = function(file) {
return path.resolve(file) === path.normalize(file);
};
}

function CheckCoverageCommand() {
Command.call(this);
}
Expand All @@ -24,11 +30,15 @@ function removeFiles(covObj, root, files) {

// Create lookup table.
files.forEach(function (file) {
filesObj[path.join(root, file)] = true;
filesObj[file] = true;
});

Object.keys(covObj).forEach(function (key) {
if (filesObj[key] !== true) {
// Exclude keys will always be relative, but covObj keys can be absolute or relative
var excludeKey = path.isAbsolute(key) ? path.relative(root, key) : key;
// Also normalize for files that start with `./`, etc.
excludeKey = path.normalize(excludeKey);
if (filesObj[excludeKey] !== true) {
obj[key] = covObj[key];
}
});
Expand Down
45 changes: 44 additions & 1 deletion test/cli/test-check-coverage-command.js
Expand Up @@ -18,6 +18,19 @@ module.exports = {
mkdirp.sync(OUTPUT_DIR);
helper.resetOpts();
runCover([ 'test/run.js', '--report', 'none' ], function (/* results */) {

// Mutate coverage.json to test relative key paths.
var covObj = require('./sample-project/coverage/coverage.json');
var relCovObj = {};
var relCovDotSlashObj = {};
Object.keys(covObj).forEach(function (key) {
var relKey = path.relative(__dirname + '/sample-project', key);
relCovObj[relKey] = covObj[key];
relCovDotSlashObj['./' + relKey] = covObj[key];
});
fs.writeFileSync(path.resolve(__dirname, 'sample-project/coverage/relative.json'), JSON.stringify(relCovObj));
fs.writeFileSync(path.resolve(__dirname, 'sample-project/coverage/relative-dot-slash.json'), JSON.stringify(relCovDotSlashObj));

cb();
});
},
Expand Down Expand Up @@ -138,6 +151,36 @@ module.exports = {
test.done();
});
},
"should fail on inadequate statement and line coverage with relative coverage": function (test) {
test.ok(existsSync(path.resolve(OUTPUT_DIR, 'relative.json')));
run([ '--config', 'config-check-each.istanbul.yml', 'coverage/relative.json' ], function (results) {
test.ok(!results.succeeded());
test.ok(!results.grepError(/Coverage for lines .* global/));
test.ok(results.grepError(/Coverage for lines .* per-file/));
test.ok(results.grepError(/Coverage for statements .* per-file/));
test.ok(!results.grepError(/Coverage for branches .* per-file/));
test.ok(!results.grepError(/Coverage for functions .* per-file/));
test.ok(results.grepError(/dummy_vendor_lib\.js/));
test.ok(!results.grepError(/foo\.js/));
test.ok(!results.grepError(/foo\.js/));
test.done();
});
},
"should fail on inadequate statement and line coverage with relative './' key coverage": function (test) {
test.ok(existsSync(path.resolve(OUTPUT_DIR, 'relative-dot-slash.json')));
run([ '--config', 'config-check-each.istanbul.yml', 'coverage/relative-dot-slash.json' ], function (results) {
test.ok(!results.succeeded());
test.ok(!results.grepError(/Coverage for lines .* global/));
test.ok(results.grepError(/Coverage for lines .* per-file/));
test.ok(results.grepError(/Coverage for statements .* per-file/));
test.ok(!results.grepError(/Coverage for branches .* per-file/));
test.ok(!results.grepError(/Coverage for functions .* per-file/));
test.ok(results.grepError(/dummy_vendor_lib\.js/));
test.ok(!results.grepError(/foo\.js/));
test.ok(!results.grepError(/foo\.js/));
test.done();
});
},
"should fail on inadequate mixed global args / each coverage": function (test) {
test.ok(existsSync(path.resolve(OUTPUT_DIR, 'coverage.json')));
run([ '--branches=100', '--functions=100', '--config', 'config-check-each.istanbul.yml' ], function (results) {
Expand Down Expand Up @@ -169,4 +212,4 @@ module.exports = {
});
}
}
};
};

0 comments on commit fbb0d01

Please sign in to comment.