-
Notifications
You must be signed in to change notification settings - Fork 3
/
gulpfile.js
67 lines (56 loc) · 1.76 KB
/
gulpfile.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
'use strict'
const gulp = require('gulp')
const path = require('path')
const Karma = require('karma').Server
const webpack = require('webpack-stream')
const connect = require('connect')
const serveStatic = require('serve-static')
const http = require('http')
const cucumber = require('gulp-cucumber')
const spawn = require('child_process').spawn
let server
let webdriverProcess
function onExit() {
if (server) {
server.close()
}
}
function runKarma(options, done) {
const config = Object.assign(options, {configFile: path.join(__dirname, 'karma.conf.js')})
new Karma(config, done).start()
}
gulp.task('ci', function (done) {
runKarma({singleRun: false, autoWatch: true}, done)
})
gulp.task('test', function (done) {
runKarma({singleRun: true, autoWatch: false}, function (err) {
done(err)
setTimeout(() => process.exit(err ? 1 : 0), 500)
})
})
gulp.task('server', function () {
const app = connect()
app.use(serveStatic(path.resolve('./tests/fixtures')))
server = http.createServer(app)
server.listen(process.env.PORT || 5050)
})
gulp.task('features', ['server'], function (cb) {
const proc = spawn('./node_modules/.bin/cucumber-js', ['tests/integration'])
proc.stdout.on('data', function (data) {
console.log(data.toString())
})
proc.stderr.on('data', function (data) {
console.error(data.toString())
})
proc.on('exit', function (code) {
onExit()
cb(code === 0 ? null : new Error(`exited with code ${code}`))
})
})
gulp.task('webpack:watch', function () {
return gulp.src('lib/index.js')
.pipe(webpack(Object.assign(require('./webpack.config.js'), {watch: true})))
.pipe(gulp.dest('./dist'))
.once('end', onExit)
})
gulp.task('watch', ['server', 'webpack:watch', 'ci'])