gulp-karma-runner
v2.0.1
Published
Gulp plugin for karma
Downloads
301
Maintainers
Readme
Gulp plugin for karma
What this?
This is a gulp plugin for karma
How can I use it?
Generally, you can use it by normal approach. i.e. like this:
gulpfile.js
((require) => {
"use strict";
const g = require('gulp');
const karma = require('gulp-karma-runner');
g.task(
'test', () => g.src(['src/**/*.js', 'test/**/*.js'], {read: false})
.pipe(karma.server({
singleRun: true,
autoWatch: false,
frameworks: ['mocha', 'chai'],
browsers: ['ChromeHeadless'],
plugins: [
'karma-mocha', 'karma-chai',
'karma-chrome-launcher'
]
}));
);
}(require));
Note that the options are equivalent to Karma configucation options
Deal with gulp.watch
Considering browser ready event, dealing with gulp.watch
might be a
little-bit tricky, because you might need to start runner task after ensuring
the server is ready, while gulp task finishes when the server is closed.
To handle this issue, you can declare the server task as asynchronous task,
and call the callback when karma.server.browsers_ready
event is emitted.
In particular, like this:
gulpfile.js
((req) => {
const gulp = req('gulp');
const karma = req('gulp-karma-runner');
const config = {
autoWatch: false,
quiet: true,
frameworks: ['mocha', 'chai'],
browsers: ['ChromeHeadless'],
plugins: [
'karma-mocha', 'karma-chai',
'karma-chrome-launcher'
]
};
gulp.task(
'server',
done => gulp.src(['src/**/*.js', 'tests/**/*.js'], { read:false })
.pipe(karma.server(config))
.once('karma.server.browsers_ready', () => done());
});
gulp.task(
'runner',
() => gulp.src(['src/**/*.js', 'tests/**/*.js'], { read:false })
.pipe(karma.runner(config));
);
gulp.task(
'default',
gulp.series(
'server',
() => gulp.watch(
['src/**/*.js', 'tests/**/*.js'],
gulp.series('runner')
),
)
);
})(require);
Contribution
Before you create an issue/pull request,
- Read the code
- Read the code again
- Understand the code
- Understand the code again.