From cf9bd403766226a3c0df6fe4495bcc53392db56c Mon Sep 17 00:00:00 2001 From: Arun Mahapatra Date: Fri, 11 Dec 2015 18:46:23 +0530 Subject: [PATCH] Add support for code coverage with istanbul. --- gulpfile.js | 22 ++++++++++++++++++---- package.json | 1 + tests/TestTaskTests/TestTaskTests.ts | 8 +++----- 3 files changed, 22 insertions(+), 9 deletions(-) diff --git a/gulpfile.js b/gulpfile.js index 331679c..92c2b1b 100644 --- a/gulpfile.js +++ b/gulpfile.js @@ -3,10 +3,13 @@ var rimraf = require("rimraf"); var tsb = require("gulp-tsb"); var mocha = require("gulp-mocha"); var tslint = require("gulp-tslint"); +var istanbul = require("gulp-istanbul"); +var path = require("path"); var buildDirectory = "_build"; var sourceFiles = ["src/**/*.ts", "tests/**/*.ts"]; var testFiles = [buildDirectory + "/**/*Tests*.js"]; +var jsCoverageDir = path.join(buildDirectory, "codecoverage"); // create and keep compiler var compilation = tsb.create({ @@ -19,7 +22,9 @@ var compilation = tsb.create({ gulp.task("build", ["lint"], function() { return gulp.src(sourceFiles, { base: "." }) .pipe(compilation()) - .pipe(gulp.dest(buildDirectory)); + .pipe(gulp.dest(buildDirectory)) + .pipe(istanbul({includeUntested: true})) + .pipe(istanbul.hookRequire()); }); gulp.task("lint", function() { @@ -37,12 +42,22 @@ gulp.task("clean", function(done) { gulp.task("test", ["build"], function() { return gulp.src(testFiles, { read: false }) - .pipe(mocha()); + .pipe(mocha()) + .pipe(istanbul.writeReports({ + dir: jsCoverageDir, + reportOpts: { dir: jsCoverageDir } + })) + .pipe(istanbul.enforceThresholds({ thresholds: { global: 95 } })); }); gulp.task("testci", ["build"], function() { return gulp.src(testFiles, { read: false }) - .pipe(mocha({ reporter: 'xunit', reporterOptions: { output: '_build/testTaskMochaTestResult.xml'} })); + .pipe(mocha({ reporter: "xunit", reporterOptions: { output: path.join(buildDirectory, "mochaTestResult.xml") } })) + .pipe(istanbul.writeReports({ + dir: jsCoverageDir, + reportOpts: { dir: jsCoverageDir } + })) + .pipe(istanbul.enforceThresholds({ thresholds: { global: 95 } })); }); gulp.task("watch", function() { @@ -50,4 +65,3 @@ gulp.task("watch", function() { }); gulp.task("default", ["build"]); - diff --git a/package.json b/package.json index b709b49..8342bd1 100644 --- a/package.json +++ b/package.json @@ -12,6 +12,7 @@ "devDependencies": { "chai": "^3.4.1", "gulp": "^3.9.0", + "gulp-istanbul": "^0.10.3", "gulp-mocha": "^2.1.3", "gulp-tsb": "^1.7.4", "gulp-tslint": "^3.5.0", diff --git a/tests/TestTaskTests/TestTaskTests.ts b/tests/TestTaskTests/TestTaskTests.ts index 35de6f4..fa11650 100644 --- a/tests/TestTaskTests/TestTaskTests.ts +++ b/tests/TestTaskTests/TestTaskTests.ts @@ -6,11 +6,9 @@ import * as testTask from "../../src/Tasks/TestTask/testTask"; describe("HelloWorldWriter.Write", () : void => { it("should throw not implemented error", () : void => { assert.doesNotThrow(() : void => { - // dummy code - var helloWorldWriter = new testTask.HelloWorldWriter(); - helloWorldWriter.Write(); + // dummy code + var helloWorldWriter = new testTask.HelloWorldWriter(); + helloWorldWriter.Write(); }); }); }); - -