Skip to content

Commit 4638bd5

Browse files
committed
Build: add code coverage for node + browsers
2 parents 733d23f + df7d8cd commit 4638bd5

File tree

2 files changed

+47
-19
lines changed

2 files changed

+47
-19
lines changed

gulpfile.js

+44-18
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,11 @@
77

88
var ARGV = require("yargs").
99
usage("$0 [options] task [task ...]").
10+
option("coverage", {
11+
type: "boolean",
12+
describe: "include coverage",
13+
default: false
14+
}).
1015
option("browsers", {
1116
type: "string",
1217
describe: "browsers to run tests in",
@@ -84,22 +89,29 @@ function doTestsNodejs() {
8489
}
8590

8691
gulp.task("test:nodejs:single", function() {
92+
// Constructing the environment descriptor
93+
var environ = require("util").format(
94+
"%s %s (%s %s)",
95+
(process.release && process.release.name) || "node",
96+
process.version,
97+
process.platform,
98+
process.arch
99+
);
100+
if (ARGV.coverage) {
101+
return gulp.src(SOURCES).
102+
pipe(istanbul()).
103+
pipe(istanbul.hookRequire()).
104+
on("finish", function() {
105+
doTestsNodejs().
106+
pipe(istanbul.writeReports({
107+
dir: "./coverage/" + environ,
108+
reporters: ["html", "text-summary"]
109+
}));
110+
});
111+
}
87112
return doTestsNodejs();
88113
});
89114

90-
gulp.task("cover:nodejs", function() {
91-
return gulp.src(SOURCES).
92-
pipe(istanbul()).
93-
pipe(istanbul.hookRequire()).
94-
on("finish", function() {
95-
doTestsNodejs().
96-
pipe(istanbul.writeReports({
97-
dir: "./coverage/nodejs",
98-
reporters: ["html", "text-summary"]
99-
}));
100-
});
101-
});
102-
103115
gulp.task("test:nodejs", function(cb) {
104116
runSequence("test:lint",
105117
"test:nodejs:single",
@@ -252,6 +264,25 @@ gulp.task("test:browser:single", function(done) {
252264
return found;
253265
});
254266
}
267+
if (ARGV.coverage) {
268+
config.browserify.transform = [
269+
require("browserify-istanbul")({
270+
ignore: [
271+
"**/node_modules/**",
272+
"**/test/**",
273+
"**/env/**"
274+
]
275+
})
276+
];
277+
config.reporters.push("coverage");
278+
config.coverageReporter = {
279+
dir: "./coverage",
280+
reporters: [
281+
{ type: "html" },
282+
{ type: "text-summary" }
283+
]
284+
};
285+
}
255286

256287
karma.server.start(config, done);
257288
});
@@ -275,11 +306,6 @@ gulp.task("test", function(cb) {
275306
"test:nodejs:single",
276307
cb);
277308
});
278-
gulp.task("coverage", function(cb) {
279-
runSequence("test:lint",
280-
"cover:nodejs",
281-
cb);
282-
});
283309
gulp.task("clean", ["clean:coverage", "clean:dist"]);
284310
gulp.task("dist", function(cb) {
285311
runSequence("clean:dist",

package.json

+3-1
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@
4444
},
4545
"devDependencies": {
4646
"browserify": "^11.0.1",
47+
"browserify-istanbul": "^0.2.1",
4748
"chai": "^1.10.0",
4849
"conventional-changelog": "^0.4.3",
4950
"del": "^1.1.1",
@@ -54,11 +55,12 @@
5455
"gulp-rename": "^1.2.0",
5556
"gulp-sourcemaps": "^1.3.0",
5657
"gulp-uglify": "^1.1.0",
57-
"istanbul": "^0.3.5",
58+
"istanbul": "^0.4.0",
5859
"jose-cookbook": "git+https://github.com/ietf-jose/cookbook.git",
5960
"karma": "^0.12.31",
6061
"karma-browserify": "^3.0.1",
6162
"karma-chrome-launcher": "^0.1.7",
63+
"karma-coverage": "^0.5.3",
6264
"karma-firefox-launcher": "^0.1.4",
6365
"karma-ie-launcher": "^0.2.0",
6466
"karma-mocha": "^0.1.10",

0 commit comments

Comments
 (0)