Skip to content

Instantly share code, notes, and snippets.

@renegare
Last active March 28, 2018 05:37
Show Gist options
  • Save renegare/9173656 to your computer and use it in GitHub Desktop.
Save renegare/9173656 to your computer and use it in GitHub Desktop.
Gulp Karma Integration
/**
* testing tasks (using karma to test in the browser). Requires a karma.conf.js for full config
* single-run testing
* continuous testing
*/
/** base deps, but you may need more specifically for your application */
var gulp = require('gulp');
var gutil = require('gulp-util');
var path = require('path');
var karma = require('karma');
var karmaParseConfig = require('karma/lib/config').parseConfig;
function runKarma(configFilePath, options, cb) {
configFilePath = path.resolve(configFilePath);
var server = karma.server;
var log=gutil.log, colors=gutil.colors;
var config = karmaParseConfig(configFilePath, {});
Object.keys(options).forEach(function(key) {
config[key] = options[key];
});
server.start(config, function(exitCode) {
log('Karma has exited with ' + colors.red(exitCode));
cb();
process.exit(exitCode);
});
}
/** actual tasks */
/** single run */
gulp.task('test', function(cb) {
runKarma('karma.conf.js', {
autoWatch: false,
singleRun: true
}, cb);
});
/** continuous ... using karma to watch (feel free to circumvent that;) */
gulp.task('test-dev', function(cb) {
runKarma('karma.conf.js', {
autoWatch: true,
singleRun: false
}, cb);
});
@aidanhmiles
Copy link

👍

@jeremyGoupil
Copy link

👍

@felipecodes
Copy link

Thank you!!! 🤘

@shaharkazaz
Copy link

Great Job! Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment