blob: 5b905727e244c710b8133501f9426f21981faa82 [file] [log] [blame]
Matteo Scandoloc46a82d2017-03-24 18:37:18 -07001const path = require('path');
2
3const gulp = require('gulp');
4const karma = require('karma');
5
6gulp.task('karma:single-run', karmaSingleRun);
7gulp.task('karma:auto-run', karmaAutoRun);
8
9function karmaFinishHandler(done) {
10 return failCount => {
11 done(failCount ? new Error(`Failed ${failCount} tests.`) : null);
12 };
13}
14
15function karmaSingleRun(done) {
16 process.env.NODE_ENV = 'test';
17 const configFile = path.join(process.cwd(), 'conf', 'karma.conf.js');
18 const karmaServer = new karma.Server({configFile}, karmaFinishHandler(done));
19 karmaServer.start();
20}
21
22function karmaAutoRun(done) {
23 process.env.NODE_ENV = 'test';
24 const configFile = path.join(process.cwd(), 'conf', 'karma-auto.conf.js');
25 const karmaServer = new karma.Server({configFile}, karmaFinishHandler(done));
26 karmaServer.start();
27}