Skip to content

Commit

Permalink
Add coverage task to Grunt file.
Browse files Browse the repository at this point in the history
This patch adds a new task--cover--that runs all unit tests to collect
coverage data. Use `grunt cover` to see the report or `grunt cover
--server` to run the coveraje web server.

Closes GH-14.

Squashed commit of the following:

commit f007515334b251fcc2e40864d5a061d27fadfa13
Author: Anton Kovalyov <anton@kovalyov.net>
Date:   Wed Aug 15 12:55:54 2012 -0700

    Fix path

commit 2056626
Author: Wolfgang Kluge <wolfgang@klugesoftware.de>
Date:   Tue Aug 14 22:14:55 2012 +0200

    Fix path to jshint.js

commit 834225d
Author: Wolfgang Kluge <wolfgang@klugesoftware.de>
Date:   Sun Aug 12 12:22:38 2012 +0200

    Add coverage task to gruntfile

    The task runs all unit tests to collect coverage data. Use `grunt cover`
    to see the report or `grunt cover --server` to run the coveraje web server.
  • Loading branch information
WolfgangKluge authored and valueof committed Aug 15, 2012
1 parent 9cfb2fe commit 4aee3b8
Showing 1 changed file with 56 additions and 0 deletions.
56 changes: 56 additions & 0 deletions grunt.js
Expand Up @@ -30,4 +30,60 @@ module.exports = function (grunt) {
grunt.file.mkdir("./dist");
grunt.file.write("./dist/jshint.js", bundle.bundle());
});

grunt.registerTask("cover", "Shows the test coverage report", function () {
var coveraje, done, runHelper, countdown;
var fileCount = 0;
var tests = {};
var useServer = !!grunt.option("server");

try {
coveraje = require("coveraje");
} catch (ex) {
grunt.log.error('coveraje not installed. '.red +
'Use "' + 'npm install coveraje'.bold + '"');
return false;
}

done = this.async();
runHelper = coveraje.runHelper;

grunt.file.expandFiles(grunt.config("test.all")).forEach(function (f) {
fileCount++;
tests[f] = function (context, instance) {
return runHelper("nodeunit", { reporterName: "minimal" })
.run(f)
.onComplete(function () {
if (!useServer)
countdown.one();
})
;
};
});

if (!useServer) {
countdown = runHelper.createCountdown(
runHelper
.createEmitter(function () {})
.onComplete(function () {
setTimeout(done, 200);
})
.onError(function () {
done(false, "timeout");
}),
fileCount,
5000
);
}

var c = coveraje.cover(
"var jshint = require(require('path').join('" + __dirname + "', 'src', 'jshint.js'));",

This comment has been minimized.

Copy link
@WolfgangKluge

WolfgangKluge Aug 19, 2012

Author Contributor

Ups,

need to fix that for windows another time (sorry). \ in __dirname would break the code...

tests,
{
useServer: useServer,
globals: "node",
resolveRequires: ["*"]
}
);
});
};

0 comments on commit 4aee3b8

Please sign in to comment.