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

Commit

Permalink
fix(tests): Reorganized coverage tests (#1480)
Browse files Browse the repository at this point in the history
* Added coverage to Gulp

* Moved karma coverage task to Gulpfile, moved LCOV posting to coveralls to .travis.yml config
  • Loading branch information
hyperreality authored and lirantal committed Sep 5, 2016
1 parent 03160a9 commit 70a3e4c
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 56 deletions.
1 change: 1 addition & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
4 changes: 1 addition & 3 deletions config/env/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,5 @@ module.exports = {
roles: ['user', 'admin']
}
}
},
// This config is set to true during gulp coverage
coverage: process.env.COVERAGE || false
}
};
55 changes: 30 additions & 25 deletions gulpfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 = [];
Expand Down Expand Up @@ -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 () {

Expand All @@ -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();
});

Expand Down Expand Up @@ -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
Expand All @@ -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);
});

28 changes: 1 addition & 27 deletions karma.conf.js
Original file line number Diff line number Diff line change
Expand Up @@ -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: {
Expand All @@ -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,

Expand Down
1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down

0 comments on commit 70a3e4c

Please sign in to comment.