When I change a file (like HelloWorld.js
), I want to run a specific test suite (called HelloWorldSpec.js
) using Karma.
Therefore I created this Gulp task:
gulp.task('dev', function(done) {
// Watch source code changes
gulp.watch('src/**/*.js').on('change', function(file) {
// Assemble path to test file
var pathObject = path.parse(file.path);
var specificationPath = 'test/' + pathObject.name + 'Spec.js';
// Run test file
new Server({
configFile: __dirname + '/karma.conf.js',
files: [
'dist/**/*.js',
specificationPath
],
singleRun: true
}, done).start();
});
});
The problem I have now is that I pass the done
callback to the Karma server which executes it after every test run. Thus I get the following error on the second source code modification (and every following):
Error: task completion callback called too many times
If I don't pass the done
callback to the Server
, then my Gulp tasks ends after the first test run. But I want to keep watching source code modifications. How can I do that?