Skip to content

Commit

Permalink
Build: add code coverage for node + browsers
Browse files Browse the repository at this point in the history
  • Loading branch information
linuxwolf committed Nov 24, 2015
2 parents 733d23f + df7d8cd commit 4638bd5
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 19 deletions.
62 changes: 44 additions & 18 deletions gulpfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,11 @@

var ARGV = require("yargs").
usage("$0 [options] task [task ...]").
option("coverage", {
type: "boolean",
describe: "include coverage",
default: false
}).
option("browsers", {
type: "string",
describe: "browsers to run tests in",
Expand Down Expand Up @@ -84,22 +89,29 @@ function doTestsNodejs() {
}

gulp.task("test:nodejs:single", function() {
// Constructing the environment descriptor
var environ = require("util").format(
"%s %s (%s %s)",
(process.release && process.release.name) || "node",
process.version,
process.platform,
process.arch
);
if (ARGV.coverage) {
return gulp.src(SOURCES).
pipe(istanbul()).
pipe(istanbul.hookRequire()).
on("finish", function() {
doTestsNodejs().
pipe(istanbul.writeReports({
dir: "./coverage/" + environ,
reporters: ["html", "text-summary"]
}));
});
}
return doTestsNodejs();
});

gulp.task("cover:nodejs", function() {
return gulp.src(SOURCES).
pipe(istanbul()).
pipe(istanbul.hookRequire()).
on("finish", function() {
doTestsNodejs().
pipe(istanbul.writeReports({
dir: "./coverage/nodejs",
reporters: ["html", "text-summary"]
}));
});
});

gulp.task("test:nodejs", function(cb) {
runSequence("test:lint",
"test:nodejs:single",
Expand Down Expand Up @@ -252,6 +264,25 @@ gulp.task("test:browser:single", function(done) {
return found;
});
}
if (ARGV.coverage) {
config.browserify.transform = [
require("browserify-istanbul")({
ignore: [
"**/node_modules/**",
"**/test/**",
"**/env/**"
]
})
];
config.reporters.push("coverage");
config.coverageReporter = {
dir: "./coverage",
reporters: [
{ type: "html" },
{ type: "text-summary" }
]
};
}

karma.server.start(config, done);
});
Expand All @@ -275,11 +306,6 @@ gulp.task("test", function(cb) {
"test:nodejs:single",
cb);
});
gulp.task("coverage", function(cb) {
runSequence("test:lint",
"cover:nodejs",
cb);
});
gulp.task("clean", ["clean:coverage", "clean:dist"]);
gulp.task("dist", function(cb) {
runSequence("clean:dist",
Expand Down
4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
},
"devDependencies": {
"browserify": "^11.0.1",
"browserify-istanbul": "^0.2.1",
"chai": "^1.10.0",
"conventional-changelog": "^0.4.3",
"del": "^1.1.1",
Expand All @@ -54,11 +55,12 @@
"gulp-rename": "^1.2.0",
"gulp-sourcemaps": "^1.3.0",
"gulp-uglify": "^1.1.0",
"istanbul": "^0.3.5",
"istanbul": "^0.4.0",
"jose-cookbook": "git+https://github.com/ietf-jose/cookbook.git",
"karma": "^0.12.31",
"karma-browserify": "^3.0.1",
"karma-chrome-launcher": "^0.1.7",
"karma-coverage": "^0.5.3",
"karma-firefox-launcher": "^0.1.4",
"karma-ie-launcher": "^0.2.0",
"karma-mocha": "^0.1.10",
Expand Down

0 comments on commit 4638bd5

Please sign in to comment.