From cdd1c80ff6ac1d0abda401baa5cccdaef010e354 Mon Sep 17 00:00:00 2001 From: hyperreality Date: Tue, 30 Aug 2016 11:14:48 -0400 Subject: [PATCH 1/3] Added coverage to Gulp --- config/env/test.js | 2 +- gulpfile.js | 32 ++++++++++++++++++++++++++++++++ package.json | 1 + 3 files changed, 34 insertions(+), 1 deletion(-) 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..5d0ac6a00b 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'), @@ -318,7 +319,34 @@ 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 () { + var testSuites = changedTestFiles.length ? changedTestFiles : testAssets.tests.server; + + return gulp.src(testSuites) + // 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' } + })); }); // Karma test runner task @@ -387,6 +415,10 @@ gulp.task('test', function (done) { runSequence('env:test', 'test:server', 'karma', 'nodemon', 'protractor', done); }); +gulp.task('test:coverage', function (done) { + runSequence('env:test', ['copyLocalEnvConfig', 'makeUploadsDir', 'dropdb'], 'lint', 'configure-coverage', 'mocha:coverage', 'karma', done); +}); + gulp.task('test:server', function (done) { runSequence('env:test', ['copyLocalEnvConfig', 'makeUploadsDir', 'dropdb'], 'lint', 'mocha', done); }); diff --git a/package.json b/package.json index df9abcfa27..4d2957c3d8 100644 --- a/package.json +++ b/package.json @@ -49,6 +49,7 @@ "glob": "~7.0.0", "grunt": "~1.0.1", "grunt-cli": "~1.2.0", + "gulp-istanbul": "^1.1.1", "gulp-node-inspector": "~0.1.0", "helmet": "~2.1.2", "jasmine-core": "~2.4.1", From 877c094ffb4eeb33085ca963e9b3a2cfc0b87ce0 Mon Sep 17 00:00:00 2001 From: hyperreality Date: Tue, 30 Aug 2016 16:10:58 -0400 Subject: [PATCH 2/3] Integrated coveralls tests with gulp --- .gitignore | 1 + .travis.yml | 2 +- gulpfile.js | 28 +++++++++++++++++++++------- karma.conf.js | 3 +-- package.json | 7 +++++-- 5 files changed, 29 insertions(+), 12 deletions(-) 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/gulpfile.js b/gulpfile.js index 5d0ac6a00b..4761be0b1b 100644 --- a/gulpfile.js +++ b/gulpfile.js @@ -24,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 = []; @@ -330,9 +331,9 @@ gulp.task('configure-coverage', function (done) { // prepare istanbul coverage test gulp.task('pre-test', function () { - var testSuites = changedTestFiles.length ? changedTestFiles : testAssets.tests.server; - return gulp.src(testSuites) + // tell istanbul to show results for all server js assets + return gulp.src(defaultAssets.server.allJS) // Covering files .pipe(plugins.istanbul()) // Force `require` to return covered files @@ -349,6 +350,19 @@ gulp.task('mocha:coverage', ['pre-test', 'mocha'], function () { })); }); +// join the coverage files for client and server into a single file +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({ @@ -415,10 +429,6 @@ gulp.task('test', function (done) { runSequence('env:test', 'test:server', 'karma', 'nodemon', 'protractor', done); }); -gulp.task('test:coverage', function (done) { - runSequence('env:test', ['copyLocalEnvConfig', 'makeUploadsDir', 'dropdb'], 'lint', 'configure-coverage', 'mocha:coverage', 'karma', done); -}); - gulp.task('test:server', function (done) { runSequence('env:test', ['copyLocalEnvConfig', 'makeUploadsDir', 'dropdb'], 'lint', 'mocha', done); }); @@ -436,6 +446,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 4d2957c3d8..4c1a9624ee 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,8 +50,6 @@ "glob": "~7.0.0", "grunt": "~1.0.1", "grunt-cli": "~1.2.0", - "gulp-istanbul": "^1.1.1", - "gulp-node-inspector": "~0.1.0", "helmet": "~2.1.2", "jasmine-core": "~2.4.1", "lodash": "~4.15.0", @@ -103,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", @@ -127,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", From 6aacfaeaba243f30e3a732af8eca6f99a25f66a0 Mon Sep 17 00:00:00 2001 From: hyperreality Date: Wed, 31 Aug 2016 19:15:31 -0400 Subject: [PATCH 3/3] spurious changes to kick off coveralls --- gulpfile.js | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/gulpfile.js b/gulpfile.js index 4761be0b1b..dc95556a03 100644 --- a/gulpfile.js +++ b/gulpfile.js @@ -322,17 +322,17 @@ gulp.task('mocha', function (done) { }); }); -// add configuration options for coverage here +// 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 +// Prepare istanbul coverage test gulp.task('pre-test', function () { - // tell istanbul to show results for all server js assets + // Display coverage for all server JavaScript files return gulp.src(defaultAssets.server.allJS) // Covering files .pipe(plugins.istanbul()) @@ -340,7 +340,7 @@ gulp.task('pre-test', function () { .pipe(plugins.istanbul.hookRequire()); }); -// run istanbul test and write report +// Run istanbul test and write report gulp.task('mocha:coverage', ['pre-test', 'mocha'], function () { var testSuites = changedTestFiles.length ? changedTestFiles : testAssets.tests.server; @@ -350,14 +350,15 @@ gulp.task('mocha:coverage', ['pre-test', 'mocha'], function () { })); }); -// join the coverage files for client and server into a single file +// 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 +// Send coverage test results to coveralls gulp.task('coveralls', ['merge-lcov'], function (done) { return gulp.src('./coverage/merged/lcov.info') .pipe(plugins.coveralls());