-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathgulpfile.js
106 lines (94 loc) · 2.54 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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
var gulp = require('gulp')
var mocha = require('gulp-mocha')
var cucumber = require('gulp-cucumber')
var istanbul = require('gulp-istanbul')
var fs = require('fs')
require('hide-stack-frames-from')('cucumber', 'bluebird')
var files = {
specs: ['spec/**/*_spec.js'],
sources: [
'*.js',
'bms/*.js',
'compiler/*.js',
'keysounds/*.js',
'notes/*.js',
'reader/*.js',
'song-info/*.js',
'speedcore/*.js',
'time-signatures/*.js',
'timing/*.js',
'util/*.js',
],
get features () {
var home = process.env.BMSPEC_HOME
if (home === undefined) {
console.error('WARNING! BMSPEC_HOME is not set. BMSpec test suites will not be run!')
return []
}
return require('./features').map(function (file) {
var filePath = home + '/features/' + file
if (!fs.existsSync(filePath)) {
console.error('WARNING! ' + filePath + ' does not exist.')
}
return filePath
})
}
}
gulp.task('test', function (callback) {
return cover(mochaThenCucumberTest, callback)
})
gulp.task('test:cov', function (callback) {
process.env.ENABLE_COVERAGE = 'true'
return cover(mochaThenCucumberTest, callback)
})
gulp.task('test:cucumber', function (callback) {
return cover(cucumberTest, callback)
})
gulp.task('test:mocha', function (callback) {
return cover(mochaTest, callback)
})
function cover (fn, callback) {
if (process.env.COV === 'true' || process.env.ENABLE_COVERAGE === 'true') {
gulp.src(files.sources)
.pipe(istanbul())
.pipe(istanbul.hookRequire())
.on('finish', function () {
console.log('TESTING BEGIN')
fn(function (error) {
console.log('TESTING DONE')
if (error) return callback(error)
istanbul.writeReports()
.once('end', callback)
.once('error', callback)
.emit('end')
})
})
} else {
fn(callback)
}
}
function mochaTest (callback) {
global.expect = require('chai').expect
gulp.src(files.specs, { read: false })
.pipe(mocha({reporter: 'nyan'}))
.on('end', callback)
.on('error', callback)
}
function cucumberTest (callback) {
gulp.src(files.features, { read: false })
.pipe(cucumber({
steps: 'features/step_definitions/**/*_steps.js',
support: [
'features/support/world.js',
'features/support/*.js',
],
}))
.on('end', callback)
.on('error', callback)
}
function mochaThenCucumberTest (callback) {
mochaTest(function (error) {
if (error) return callback(error)
cucumberTest(callback)
})
}