diff --git a/.gitignore b/.gitignore index f100db8aa0..a18088a4c5 100644 --- a/.gitignore +++ b/.gitignore @@ -15,6 +15,7 @@ app/tests/coverage/ .bower-*/ .idea/ coverage/ +.coveralls.yml # MEAN.js app and assets # ====================== diff --git a/.travis.yml b/.travis.yml index 78678b032a..aee321a749 100644 --- a/.travis.yml +++ b/.travis.yml @@ -35,7 +35,7 @@ before_install: - sleep 3 after_script: - nsp audit-package - - grunt coverage + - gulp test:coverage notifications: webhooks: urls: diff --git a/config/env/test.js b/config/env/test.js index d8b0e80a2a..bfbc63ed5e 100644 --- a/config/env/test.js +++ b/config/env/test.js @@ -93,6 +93,6 @@ module.exports = { } } }, - // This config is set to true during grunt coverage + // This config is set to true during gulp coverage coverage: process.env.COVERAGE || false }; diff --git a/gulpfile.js b/gulpfile.js index a36c5ecead..dc95556a03 100644 --- a/gulpfile.js +++ b/gulpfile.js @@ -7,6 +7,7 @@ var _ = require('lodash'), fs = require('fs'), defaultAssets = require('./config/assets/default'), testAssets = require('./config/assets/test'), + testConfig = require('./config/env/test'), glob = require('glob'), gulp = require('gulp'), gulpLoadPlugins = require('gulp-load-plugins'), @@ -23,7 +24,8 @@ 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; + KarmaServer = require('karma').Server, + lcovMerger = require('lcov-result-merger'); // Local settings var changedTestFiles = []; @@ -318,7 +320,48 @@ 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 () { + // Display coverage for all server JavaScript files + return gulp.src(defaultAssets.server.allJS) + // Covering files + .pipe(plugins.istanbul()) + // Force `require` to return covered files + .pipe(plugins.istanbul.hookRequire()); +}); + +// Run istanbul test and write report +gulp.task('mocha:coverage', ['pre-test', 'mocha'], function () { + var testSuites = changedTestFiles.length ? changedTestFiles : testAssets.tests.server; + + return gulp.src(testSuites) + .pipe(plugins.istanbul.writeReports({ + reportOpts: { dir: './coverage/server' } + })); +}); + +// 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 @@ -404,6 +447,10 @@ gulp.task('test:e2e', function (done) { runSequence('env:test', 'lint', 'dropdb', 'nodemon', 'protractor', done); }); +gulp.task('test:coverage', function (done) { + runSequence('env:test', ['copyLocalEnvConfig', 'makeUploadsDir', 'dropdb'], 'lint', 'configure-coverage', 'mocha:coverage', 'karma', 'coveralls', done); +}); + // Run the project in development mode gulp.task('default', function (done) { runSequence('env:dev', ['copyLocalEnvConfig', 'makeUploadsDir'], 'lint', ['nodemon', 'watch'], done); diff --git a/karma.conf.js b/karma.conf.js index c47045263f..56fbe08065 100644 --- a/karma.conf.js +++ b/karma.conf.js @@ -50,8 +50,7 @@ module.exports = function (karmaConfig) { dir: 'coverage/client', reporters: [ // Reporters not supporting the `file` property - { type: 'html', subdir: 'report-html' }, - { type: 'lcov', subdir: 'report-lcov' }, + { type: 'lcov', subdir: '.' }, // Output coverage to console { type: 'text' } ], diff --git a/package.json b/package.json index fc615809bc..2c82fc1e9d 100644 --- a/package.json +++ b/package.json @@ -26,6 +26,7 @@ "test:server:watch": "gulp test:server:watch", "test:client": "gulp test:client", "test:e2e": "gulp test:e2e", + "test:coverage": "gulp test:coverage", "postinstall": "bower install --allow-root && bower prune --allow-root", "generate-ssl-certs": "scripts/generate-ssl-certs.sh" }, @@ -49,7 +50,6 @@ "glob": "~7.0.0", "grunt": "~1.0.1", "grunt-cli": "~1.2.0", - "gulp-node-inspector": "~0.1.0", "helmet": "~2.1.2", "jasmine-core": "~2.4.1", "lodash": "~4.15.0", @@ -102,15 +102,18 @@ "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", "gulp-imagemin": "~2.4.0", + "gulp-istanbul": "~1.1.1", "gulp-less": "~3.0.5", "gulp-livereload": "~3.8.1", "gulp-load-plugins": "~1.2.0", "gulp-mocha": "~3.0.1", "gulp-ng-annotate": "~1.1.0", + "gulp-node-inspector": "~0.1.0", "gulp-nodemon": "~2.0.6", "gulp-protractor": "~2.1.0", "gulp-rename": "~1.2.2", @@ -126,6 +129,7 @@ "karma-jasmine": "~0.3.7", "karma-ng-html2js-preprocessor": "~0.2.1", "karma-phantomjs-launcher": "~1.0.0", + "lcov-result-merger": "~1.2.0", "load-grunt-tasks": "~3.4.1", "mock-fs": "~3.11.0", "node-inspector": "~0.12.7",