Matteo Scandolo | d819c92 | 2016-12-02 14:06:14 -0800 | [diff] [blame] | 1 | const path = require('path'); |
| 2 | |
| 3 | const gulp = require('gulp'); |
| 4 | const karma = require('karma'); |
| 5 | |
| 6 | gulp.task('karma:single-run', karmaSingleRun); |
| 7 | gulp.task('karma:auto-run', karmaAutoRun); |
| 8 | |
| 9 | function karmaFinishHandler(done) { |
| 10 | return failCount => { |
| 11 | done(failCount ? new Error(`Failed ${failCount} tests.`) : null); |
| 12 | }; |
| 13 | } |
| 14 | |
| 15 | function karmaSingleRun(done) { |
Matteo Scandolo | 43ffb67 | 2016-12-02 14:49:58 -0800 | [diff] [blame] | 16 | process.env.NODE_ENV = 'test'; |
Matteo Scandolo | d819c92 | 2016-12-02 14:06:14 -0800 | [diff] [blame] | 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 | |
| 22 | function karmaAutoRun(done) { |
Matteo Scandolo | 43ffb67 | 2016-12-02 14:49:58 -0800 | [diff] [blame] | 23 | process.env.NODE_ENV = 'test'; |
Matteo Scandolo | d819c92 | 2016-12-02 14:06:14 -0800 | [diff] [blame] | 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 | } |
Matteo Scandolo | 70377e5 | 2017-04-10 16:41:28 -0700 | [diff] [blame] | 28 | |
| 29 | const remapIstanbul = require('remap-istanbul/lib/gulpRemapIstanbul'); |
| 30 | gulp.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 | }); |