Matteo Scandolo | e19fa10 | 2017-03-09 15:38:59 -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) { |
| 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 | |
| 22 | function 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 | } |