I am trying to run karma tests from gulp task and I am getting this error:
Error: 1
at formatError (C:\\Users\\Tim\\AppData\\Roaming\\npm\\node_modules\\g
gulp.task('test', function(done) {
karma.start({
configFile: __dirname + '/karma.conf.js',
singleRun: false
}, done);
});
passing singleRun: false
argument will prevent the process from returning a value different of 0 (which would signify an error and exit gulp).
Run with singleRun: true
if you only launching your test from a command line, not part of a continuous integration suite.
What worked for me and gave a nice formatted error message is to provide an Error instance to the done
callback.
gulp.task('test', function(done) {
karma.start({
configFile: __dirname + '/karma.conf.js',
singleRun: true
}, function(result) {
if (result > 0) {
return done(new Error(`Karma exited with status code ${result}`));
}
done();
});
});
Not sure about Ubuntu, but I was getting a similar error on Windows, and installing one version back fixed it right away like this:
npm install -g gulp@3.8.8
npm install gulp@3.8.8
How are you running your tests with Gulp? I came up against this issue recently on OSX, running node v0.11.14
and gulp 3.8.10
, whenever there were failing tests.
Changing from the recommended:
gulp.task('test', function(done) {
karma.start({
configFile: __dirname + '/karma.conf.js',
singleRun: true
}, done);
});
To:
gulp.task('test', function(done) {
karma.start({
configFile: __dirname + '/karma.conf.js',
singleRun: true
}, function() {
done();
});
});
...got rid of this error.
Seems to be down to how gulp handles error messages when an error is signalled in a callback. See Improve error messages on exit for more information.