-
-
Save manjurulcis/4421045bc982978f8bc5c4b59c2ed694 to your computer and use it in GitHub Desktop.
Gulp Karma Integration
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* 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); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment