Running your Karma tests
Next, we want to run our tests. Of course, we already created some tests and ran them with Karma. No worries, we are not going to undo all that. Instead, we are going to run Karma automatically using Gulp. That way, we lint, test, and minify our code with a single gulp
command. There used to be a Karma plugin for Gulp, but now it is recommended to just run Karma directly from Gulp. This is actually surprisingly easy:
var gulp = require('gulp'); var karma = require('karma').Server; gulp.task('test', function () { new karma({ configFile: __dirname + '/test/karma.conf.js' }).start(); });
The __dirname
variable is a global Node.js variable and contains the current file path. So, we set up a new Karma server from code, pass it our config file, and start it up. The config file still has PhantomJS set up and watches files as they change. This is a bit of a problem, as our Gulp file can watch files as well, but currently does not. So, Gulp never returns because...