Open bennett000 opened 9 years ago
thank you @bennett000, this worked for me! A PR to update the documentation on this one might help out a lot of people.
Likewise, thanks @bennett000, this helped me out too.
@bennett000 chaining :grin:
/*global require*/
var gulp = require('gulp'),
gutil = require('gulp-util'),
Server = require('karma').Server;
gulp.task('test', function (done) {
new Server({
configFile: __dirname + '/karma.conf.js',
singleRun: true
}).on('browser_error', function (browser, err){
gutil.log('Karma Run Failed: ' + err.message);
throw err;
}).on('run_complete', function (browsers, results){
if (results.failed) {
throw new Error('Karma: Tests Failed');
}
gutil.log('Karma Run Complete: No Failures');
done();
}).start();
});
The given example seems to end properly, but eventually calls back on my end too many times with the following error:
Error: task completion callback called too many times
. I would guess this is related to me using multiple browsers?I was able to stop the issue by listening to Karma's
run_complete
event, and firing gulp'sdone
at that point, instead of through the Karma Server constructor's callback.This is not really an "issue", but this might be useful to someone else.
Current Example:
More or less produces on my end:
("KARMA DONE" was console.logged out, and the task was named "test-karma" instead of just "test")
Updated (Working For Me) Example
Skimming through the Karma docs I updated the example to throw on browser error, and check Karma's results.
I'm very new to gulp so this might be all wrong, but it completes as expected on my end.