I learned a bit more about Karma and discovered karma.runner.run()
, which triggers an already-running server (for example, a Karma server you started in a different command window) to rerun its tests. In my gulp task I now do something like this:
gulp.task('run-tests', function() {
gulp.watch('/glob/to/my/files').on('change', function() {
karma.runner.run({ configFile: 'karma.conf.js' });
});
});
Note that if you run this task from the same process that spawned your Karma server, you will see duplicate test results since both the server and the runner report their results to the command line. To only show one set of test results, you can start your Karma server in a background process using something like this.