From 70a3e4cac359cc60236b8b0057c88e18d8337893 Mon Sep 17 00:00:00 2001 From: hyperreality Date: Mon, 5 Sep 2016 18:42:37 +0100 Subject: [PATCH] fix(tests): Reorganized coverage tests (#1480) * Added coverage to Gulp * Moved karma coverage task to Gulpfile, moved LCOV posting to coveralls to .travis.yml config --- .travis.yml | 1 + config/env/test.js | 4 +--- gulpfile.js | 55 +++++++++++++++++++++++++--------------------- karma.conf.js | 28 +---------------------- package.json | 1 - 5 files changed, 33 insertions(+), 56 deletions(-) diff --git a/.travis.yml b/.travis.yml index 4eebc76975..5dd238526c 100644 --- a/.travis.yml +++ b/.travis.yml @@ -36,6 +36,7 @@ before_install: after_script: - nsp check - gulp test:coverage + - node_modules/.bin/lcov-result-merger 'coverage/**/lcov.info' | node_modules/coveralls/bin/coveralls.js notifications: webhooks: urls: diff --git a/config/env/test.js b/config/env/test.js index bfbc63ed5e..f8fb5d7368 100644 --- a/config/env/test.js +++ b/config/env/test.js @@ -92,7 +92,5 @@ module.exports = { roles: ['user', 'admin'] } } - }, - // This config is set to true during gulp coverage - coverage: process.env.COVERAGE || false + } }; diff --git a/gulpfile.js b/gulpfile.js index dc95556a03..c8052d8c27 100644 --- a/gulpfile.js +++ b/gulpfile.js @@ -24,8 +24,7 @@ var _ = require('lodash'), protractor = require('gulp-protractor').protractor, webdriver_update = require('gulp-protractor').webdriver_update, webdriver_standalone = require('gulp-protractor').webdriver_standalone, - KarmaServer = require('karma').Server, - lcovMerger = require('lcov-result-merger'); + KarmaServer = require('karma').Server; // Local settings var changedTestFiles = []; @@ -322,13 +321,6 @@ gulp.task('mocha', function (done) { }); }); -// Add configuration options for coverage here -gulp.task('configure-coverage', function (done) { - // Set coverage config environment variable so karma-coverage knows to run it - testConfig.coverage = true; - done(); -}); - // Prepare istanbul coverage test gulp.task('pre-test', function () { @@ -350,25 +342,37 @@ gulp.task('mocha:coverage', ['pre-test', 'mocha'], function () { })); }); -// Join the coverage files for client and server into a single file -// Otherwise they get sent to coveralls as separate builds -gulp.task('merge-lcov', function (done) { - return gulp.src('./coverage/**/lcov.info') - .pipe(lcovMerger()) - .pipe(gulp.dest('./coverage/merged/')); -}); - -// Send coverage test results to coveralls -gulp.task('coveralls', ['merge-lcov'], function (done) { - return gulp.src('./coverage/merged/lcov.info') - .pipe(plugins.coveralls()); -}); - // Karma test runner task gulp.task('karma', function (done) { + new KarmaServer({ + configFile: __dirname + '/karma.conf.js' + }, done).start(); +}); + +// Run karma with coverage options set and write report +gulp.task('karma:coverage', function(done) { new KarmaServer({ configFile: __dirname + '/karma.conf.js', - singleRun: true + preprocessors: { + 'modules/*/client/views/**/*.html': ['ng-html2js'], + 'modules/core/client/app/config.js': ['coverage'], + 'modules/core/client/app/init.js': ['coverage'], + 'modules/*/client/*.js': ['coverage'], + 'modules/*/client/config/*.js': ['coverage'], + 'modules/*/client/controllers/*.js': ['coverage'], + 'modules/*/client/directives/*.js': ['coverage'], + 'modules/*/client/services/*.js': ['coverage'] + }, + reporters: ['progress', 'coverage'], + coverageReporter: { + dir: 'coverage/client', + reporters: [ + { type: 'lcov', subdir: '.' } + // printing summary to console currently weirdly causes gulp to hang so disabled for now + // https://github.com/karma-runner/karma-coverage/issues/209 + // { type: 'text-summary' } + ] + } }, done).start(); }); @@ -448,7 +452,7 @@ gulp.task('test:e2e', function (done) { }); gulp.task('test:coverage', function (done) { - runSequence('env:test', ['copyLocalEnvConfig', 'makeUploadsDir', 'dropdb'], 'lint', 'configure-coverage', 'mocha:coverage', 'karma', 'coveralls', done); + runSequence('env:test', ['copyLocalEnvConfig', 'makeUploadsDir', 'dropdb'], 'lint', 'mocha:coverage', 'karma:coverage', done); }); // Run the project in development mode @@ -465,3 +469,4 @@ gulp.task('debug', function (done) { gulp.task('prod', function (done) { runSequence(['copyLocalEnvConfig', 'makeUploadsDir', 'templatecache'], 'build', 'env:prod', 'lint', ['nodemon', 'watch'], done); }); + diff --git a/karma.conf.js b/karma.conf.js index 56fbe08065..409af1168d 100644 --- a/karma.conf.js +++ b/karma.conf.js @@ -9,25 +9,13 @@ var _ = require('lodash'), testConfig = require('./config/env/test'), karmaReporters = ['progress']; -if (testConfig.coverage) { - karmaReporters.push('coverage'); -} - // Karma configuration module.exports = function (karmaConfig) { karmaConfig.set({ - // Frameworks to use frameworks: ['jasmine'], preprocessors: { - 'modules/*/client/views/**/*.html': ['ng-html2js'], - 'modules/core/client/app/config.js': ['coverage'], - 'modules/core/client/app/init.js': ['coverage'], - 'modules/*/client/*.js': ['coverage'], - 'modules/*/client/config/*.js': ['coverage'], - 'modules/*/client/controllers/*.js': ['coverage'], - 'modules/*/client/directives/*.js': ['coverage'], - 'modules/*/client/services/*.js': ['coverage'] + 'modules/*/client/views/**/*.html': ['ng-html2js'] }, ngHtml2JsPreprocessor: { @@ -45,20 +33,6 @@ module.exports = function (karmaConfig) { // Possible values: 'dots', 'progress', 'junit', 'growl', 'coverage' reporters: karmaReporters, - // Configure the coverage reporter - coverageReporter: { - dir: 'coverage/client', - reporters: [ - // Reporters not supporting the `file` property - { type: 'lcov', subdir: '.' }, - // Output coverage to console - { type: 'text' } - ], - instrumenterOptions: { - istanbul: { noCompact: true } - } - }, - // Web server port port: 9876, diff --git a/package.json b/package.json index 2c82fc1e9d..bcecd37843 100644 --- a/package.json +++ b/package.json @@ -102,7 +102,6 @@ "gulp-angular-templatecache": "~1.8.0", "gulp-autoprefixer": "~3.1.0", "gulp-concat": "~2.6.0", - "gulp-coveralls": "~0.1.4", "gulp-csslint": "~0.2.0", "gulp-csso": "~1.1.0", "gulp-eslint": "~2.0.0",