blob: 3f828e04c98617f7fe24f5f942ca0cd77437e475 [file] [log] [blame]
Matteo Scandolod819c922016-12-02 14:06:14 -08001const 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) {
Matteo Scandolo43ffb672016-12-02 14:49:58 -080016 process.env.NODE_ENV = 'test';
Matteo Scandolod819c922016-12-02 14:06:14 -080017 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) {
Matteo Scandolo43ffb672016-12-02 14:49:58 -080023 process.env.NODE_ENV = 'test';
Matteo Scandolod819c922016-12-02 14:06:14 -080024 const configFile = path.join(process.cwd(), 'conf', 'karma-auto.conf.js');
25 const karmaServer = new karma.Server({configFile}, karmaFinishHandler(done));
26 karmaServer.start();
27}
Matteo Scandolo70377e52017-04-10 16:41:28 -070028
29const remapIstanbul = require('remap-istanbul/lib/gulpRemapIstanbul');
30gulp.task('remap-istanbul', function() {
31 return gulp.src('coverage/coverage-final.json')
32 .pipe(remapIstanbul({
33 reports: {
34 'json': 'coverage/coverage-final.json',
35 'html': 'coverage/html',
36 'cobertura': 'coverage/coverage.xml'
37 }
38 }));
39});