Karma test runs fine but exits with code 1
if 0 of 0
tests are run. Does anyone know how to return exit code 0
and normally exit in this case? Using gulp-karma
which fails the task when no specs are run.
Asked
Active
Viewed 9,143 times
9
![](../../users/profiles/843244.webp)
Encore PTL
- 7,144
- 8
- 35
- 72
-
2I solved it by creating unit tests! ;) – Justus Romijn Feb 24 '15 at 14:39
2 Answers
31
There is a configuration option that allows for empty test suites. Just add
failOnEmptyTestSuite: false
to your karma.conf.js
and the process will exit with exit code 0.
BR Chris
![](../../users/profiles/842181.webp)
cschuff
- 5,192
- 3
- 31
- 51
-
3
-
This solves the question! But note, it still does output "0 of 0 ERROR" to the console in red coloring, which can be visually misleading. – trusktr Oct 02 '20 at 23:12
1
In your gulpfile, replace the "throw err" on the error callback in the your gulp test task with "this.emit('end')".
gulp.task('test', function() {
return gulp.src(testFiles)
.pipe(karma({
configFile: 'karma.conf.js',
action: 'run'
}))
.on('error', function(err) {
throw err;
});
});
so your test task now looks like;
gulp.task('test', function() {
return gulp.src(testFiles)
.pipe(karma({
configFile: 'karma.conf.js',
action: 'run'
}))
.on('error', function(err) {
this.emit('end');
});
});
![](../../users/profiles/3841782.webp)
Olatunde Garuba
- 979
- 1
- 15
- 21
-
1This would make the gulp task swallow every error, no? But the asker only wants to ignore the 'no-test' case. – cschuff Aug 16 '16 at 11:33
-