Skip to content

Commit

Permalink
Merge pull request #44 from yeahoffline/master
Browse files Browse the repository at this point in the history
upgrade dependencies + support for include-all-sources
  • Loading branch information
taichi committed Feb 8, 2016
2 parents 02b4fa9 + a394352 commit 8b177d4
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 11 deletions.
19 changes: 10 additions & 9 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "grunt-istanbul",
"description": "JavaScript codecoverage tool for Grunt",
"version": "0.6.1",
"version": "0.6.2",
"homepage": "https://github.com/taichi/grunt-istanbul",
"author": {
"name": "taichi",
Expand All @@ -14,7 +14,8 @@
"rowanbeentje <[email protected]>",
"Martin Geisler <[email protected]>",
"Seth Pollack <[email protected]>",
"tcrevoisier <[email protected]>"
"tcrevoisier <[email protected]>",
"yeahoffline <[email protected]>"
],
"repository": {
"type": "git",
Expand All @@ -38,22 +39,22 @@
"test": "grunt test"
},
"dependencies": {
"chalk": "~1.0.0",
"istanbul" : "~0.3.7",
"chalk": "1.1.1",
"istanbul" : "0.4.2",
"nue": "0.7.1"
},
"peerDependencies": {
"grunt": "~0.4.5"
},
"devDependencies": {
"grunt": "~0.4.5",
"grunt-contrib-jshint": "~0.11.0",
"grunt-contrib-jshint": "~0.12.0",
"grunt-contrib-nodeunit": "~0.4.1",
"grunt-contrib-clean" : "~0.6.0",
"grunt-contrib-clean" : "~0.7.0",
"isparta": "^2.2.0",
"mkdirp": "~0.5.0",
"rimraf": "~2.3.2",
"dateformat" : "~1.0.11"
"mkdirp": "~0.5.1",
"rimraf": "~2.5.1",
"dateformat" : "~1.0.12"
},
"keywords": [
"gruntplugin","coverage","code coverage", "JS code coverage", "JS coverage","istanbul"
Expand Down
10 changes: 10 additions & 0 deletions tasks/helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,16 @@ exports.init = function(grunt) {
this.next();
}, done)(files);
},
addUncoveredFiles: function(coverage, options, allFiles){
var instrumenter = new istanbul.Instrumenter({coverageVariable: options.coverageVar , preserveComments: false});
var transformer = instrumenter.instrumentSync.bind(instrumenter);
allFiles.forEach(function (file) {
if (!coverage[file]) {
transformer(fs.readFileSync(file, 'utf-8'), file);
coverage[file] = instrumenter.coverState;
}
});
},
storeCoverage : function(coverage, options, done) {
flow(function write_json(cov) {
var json = path.resolve(options.dir, options.json);
Expand Down
8 changes: 6 additions & 2 deletions tasks/istanbul.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,9 @@ module.exports = function(grunt) {

var expandOptions = options.cwd ? {cwd: options.cwd} : {};

helper.instrument(grunt.file.expand(expandOptions, files), options, this
.async());
var allFiles = grunt.file.expand(expandOptions, files);
global['allFiles'] = allFiles;
helper.instrument(allFiles, options, this.async());
});

grunt.registerTask('reloadTasks', 'override instrumented tasks', function(
Expand All @@ -44,6 +45,9 @@ module.exports = function(grunt) {
coverageVar : '__coverage__'
});
if (global[options.coverageVar]) {
if (options["include-all-sources"]) {
helper.addUncoveredFiles(global[options.coverageVar], options, global['allFiles']);
}
helper.storeCoverage(global[options.coverageVar], options, this.async());
} else {
grunt.fail.fatal('No coverage information was collected');
Expand Down

0 comments on commit 8b177d4

Please sign in to comment.