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 | } |