Skip to content
This repository has been archived by the owner on Aug 30, 2021. It is now read-only.

feat(tests): Add client and server test coverage to Gulp #1466

Merged
merged 3 commits into from
Sep 3, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ app/tests/coverage/
.bower-*/
.idea/
coverage/
.coveralls.yml

# MEAN.js app and assets
# ======================
Expand Down
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ before_install:
- sleep 3
after_script:
- nsp audit-package
- grunt coverage
- gulp test:coverage
notifications:
webhooks:
urls:
Expand Down
2 changes: 1 addition & 1 deletion config/env/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
};
49 changes: 48 additions & 1 deletion gulpfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -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'),
Expand All @@ -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 = [];
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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);
Expand Down
3 changes: 1 addition & 2 deletions karma.conf.js
Original file line number Diff line number Diff line change
Expand Up @@ -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' }
],
Expand Down
6 changes: 5 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
},
Expand All @@ -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",
Expand Down Expand Up @@ -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",
Expand All @@ -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",
Expand Down