diff --git a/package.json b/package.json index 06ca796..2a867a4 100644 --- a/package.json +++ b/package.json @@ -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", @@ -14,7 +14,8 @@ "rowanbeentje ", "Martin Geisler ", "Seth Pollack ", - "tcrevoisier " + "tcrevoisier ", + "yeahoffline " ], "repository": { "type": "git", @@ -38,8 +39,8 @@ "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": { @@ -47,13 +48,13 @@ }, "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" diff --git a/tasks/helpers.js b/tasks/helpers.js index d06b96c..fd3c8f8 100644 --- a/tasks/helpers.js +++ b/tasks/helpers.js @@ -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); diff --git a/tasks/istanbul.js b/tasks/istanbul.js index 28e866c..ceb2968 100644 --- a/tasks/istanbul.js +++ b/tasks/istanbul.js @@ -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( @@ -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');