Karma plugin for gulp 3
First, install gulp-karma
as a development dependency:
npm install --save-dev gulp-karma
Then, add it to your gulpfile.js
:
var karma = require('gulp-karma');
var testFiles = [
'client/todo.js',
'client/todo.util.js',
'client/todo.App.js',
'test/client/*.js'
];
gulp.task('test', function() {
// Be sure to return the stream
return gulp.src(testFiles)
.pipe(karma({
configFile: 'karma.conf.js',
action: 'run'
}))
.on('error', function(err) {
// Make sure failed tests cause gulp to exit non-zero
throw err;
});
});
gulp.task('default', function() {
gulp.src(testFiles)
.pipe(karma({
configFile: 'karma.conf.js',
action: 'watch'
}));
});
Type: String
The path to the Karma configuration file.
Type: String
Default: run
One of the following:
run
: Start the server, run tests once, then exit.watch
: Start the server, run tests once, then watch for changes and run when files change.
Any Karma option can be passed as part of the options object. See Karma Configuration for a complete list of options. Note: It's best practice to put options in your Karma config file.
Karma runs asynchronously. When using action: 'run'
in a task, you should return the stream so gulp knows the task finished.
Due to the way Karma works, using gulp.watch
to watch files results in contrived usage that doesn't work as expected in some cases. As a result, Karma's watch mechanism is employed to make usage of this plugin as straight forward as possible.
Globs are resolved before they're sent to Karma, so if you add a new file that matches a glob you passed using gulp.src('test/*').pipe(karma)
, it won't be caught by Karma.