Matteo Scandolo | d819c92 | 2016-12-02 14:06:14 -0800 | [diff] [blame^] | 1 | process.env.NODE_ENV = 'test'; |
| 2 | |
| 3 | const path = require('path'); |
| 4 | |
| 5 | const gulp = require('gulp'); |
| 6 | const karma = require('karma'); |
| 7 | |
| 8 | gulp.task('karma:single-run', karmaSingleRun); |
| 9 | gulp.task('karma:auto-run', karmaAutoRun); |
| 10 | |
| 11 | function karmaFinishHandler(done) { |
| 12 | return failCount => { |
| 13 | done(failCount ? new Error(`Failed ${failCount} tests.`) : null); |
| 14 | }; |
| 15 | } |
| 16 | |
| 17 | function karmaSingleRun(done) { |
| 18 | const configFile = path.join(process.cwd(), 'conf', 'karma.conf.js'); |
| 19 | const karmaServer = new karma.Server({configFile}, karmaFinishHandler(done)); |
| 20 | karmaServer.start(); |
| 21 | } |
| 22 | |
| 23 | function karmaAutoRun(done) { |
| 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 | } |