This is a gulp plugin for karma
Generally, you can use it by normal approach. i.e. like this:
gulpfile.js
/*global require*/
(function (require) {
"use strict";
var g = require("gulp"),
karma = require("gulp-karma-runner");
g.task("test", function () {
g.src([
"src/**/*.js",
"test/**/*.js"
], {"read": false}).pipe(
karma.server({
"singleRun": true,
"frameworks": ["mocha", "chai"],
"browsers": ["Chrome", "Firefox"]
})
);
});
}(require));
Note that the options are equivalent to Karma configucation options
Because this plugin provides runner, aka. a wrap of karma runner
,
you can write 2 tasks and run server task first, then, run runner task with
watching:
gulpfile.js
/*global require*/
(function (require) {
"use strict";
var g = require("gulp"),
karma = require("gulp-karma-runner");
g.task("server", function () {
g.src([
"src/**/*.js",
"test/**/*.js"
], {"read": false}).pipe(
karma.server({
"singleRun": false,
"quiet": true, // quiet mode is important to prevent multiple output
"frameworks": ["mocha", "chai"],
"browsers": ["Chrome", "Firefox"]
})
);
});
g.task("runner", function () {
g.src([
"src/**/*.js",
"test/**/*.js"
], {"read": false}).pipe(
karma.runner({
"singleRun": false,
"frameworks": ["mocha", "chai"],
"browsers": ["Chrome", "Firefox"]
})
);
});
g.task("default", ["server"], function () {
g.watch([
"src/**/*.js",
"test/**/*.js"
], ["runner"]);
});
}(require));