From c5772fef50183f00173a15b262c9e643f2df6f41 Mon Sep 17 00:00:00 2001 From: Trey Hunner Date: Tue, 17 Feb 2015 14:03:28 -0800 Subject: [PATCH] Use istanbul to measure karma code coverage Notes: - browserify-istanbul is used instead of a karma-coverage preprocessor because of this bug: https://github.com/karma-runner/karma-coverage/issues/16#issuecomment-62091196 - karma-coverage version pinned to 0.2.6 to workaround this bug: https://github.com/karma-runner/karma-coverage/issues/123#issuecomment-68278237 --- .gitignore | 1 + karma.conf.js | 16 ++++++++++++++-- package.json | 2 ++ 3 files changed, 17 insertions(+), 2 deletions(-) diff --git a/.gitignore b/.gitignore index 32c57f2..2d3dc70 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,5 @@ .idea +coverage node_modules server/datasources.local.json server/model-config.local.json \ No newline at end of file diff --git a/karma.conf.js b/karma.conf.js index 6db143d..8917667 100644 --- a/karma.conf.js +++ b/karma.conf.js @@ -1,6 +1,8 @@ // Karma configuration // Generated on Sun Jan 18 2015 21:07:20 GMT-0800 (PST) +var istanbul = require('browserify-istanbul'); + module.exports = function(config) { config.set({ @@ -32,7 +34,9 @@ module.exports = function(config) { browserify: { debug: true, - transform: ['brfs'], + transform: ['brfs', istanbul({ + ignore: ['**/node_modules/**', '**/spec/**'], + })], bundleDelay: 1000 }, @@ -40,7 +44,15 @@ module.exports = function(config) { // test results reporter to use // possible values: 'dots', 'progress' // available reporters: https://npmjs.org/browse/keyword/karma-reporter - reporters: ['dots'], + reporters: ['coverage', 'dots'], + + + coverageReporter: { + reporters: [ + {type: 'html'}, + {type: 'cobertura'}, + ], + }, // web server port diff --git a/package.json b/package.json index 48f4df2..fb77302 100644 --- a/package.json +++ b/package.json @@ -39,6 +39,7 @@ "loopback-explorer": "^1.1.0" }, "devDependencies": { + "browserify-istanbul": "^0.1.5", "frisby": "git+https://github.com/vlucas/frisby.git", "gulp": "^3.8.10", "gulp-develop-server": "^0.2.5", @@ -52,6 +53,7 @@ "karma": "^0.12.31", "karma-browserify": "^2.0.0", "karma-chrome-launcher": "^0.1.7", + "karma-coverage": "^0.2.6", "karma-jasmine": "^0.3.5", "strongloop": "^2.10.2" }