-
Notifications
You must be signed in to change notification settings - Fork 17
/
gulpfile.js
169 lines (145 loc) · 4.11 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
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
var fs = require('fs');
var os = require('os');
var http = require('http');
var path = require('path');
var childProcess = require('child_process');
var resolve = require('resolve');
var gulp = require('gulp');
var gutil = require('gulp-util');
var eslint = require('gulp-eslint');
var democase = require('gulp-democase');
var excludeGitignore = require('gulp-exclude-gitignore');
var webpack = require('webpack');
var del = require('del');
// coveralls
var coveralls = require('gulp-coveralls');
// coveralls-end
var jsdoc = require('gulp-jsdoc3');
function webpackBuild(configFilePath) {
return function (cb) {
webpack(require(configFilePath), function (err, stats) {
gutil.log(stats.toString({ colors: true }));
cb(err || stats.hasErrors() && new Error('webpack compile error'));
});
};
}
function getSeleniumFilePath() {
var SELENIUM_NAME = 'selenium-server-standalone-2.53.0.jar';
return path.resolve(os.tmpdir(), SELENIUM_NAME);
}
gulp.task('download-selenium', function (cb) {
var filePath = getSeleniumFilePath();
fs.stat(filePath, function (err) {
if (!err) {
return cb(null);
}
var file = fs.createWriteStream(filePath);
var URL = 'http://selenium-release.storage.googleapis.com/2.53/selenium-server-standalone-2.53.0.jar';
http.get(URL, function (response) {
response.pipe(file);
});
file.on('error', function (err) {
fs.unlinkSync(filePath);
cb(err);
});
file.on('finish', cb);
});
});
function startSeleniumServer() {
var filePath = getSeleniumFilePath();
return childProcess.spawn('java', ['-jar', filePath], {
stdio: 'inherit',
env: { path: path.join(__dirname, 'node_modules', '.bin') },
});
}
function testWithKarmaCmd(handler) {
var karmaCmd = path.resolve('./node_modules/.bin/karma');
if (process.platform === 'win32') {
karmaCmd += '.cmd';
}
childProcess.spawn(karmaCmd, [
'start',
'--single-run',
], { stdio: 'inherit' }).on('close', handler);
}
/*
function testWithKarmaAPI(handler) {
var Server = require('karma').Server;
new Server({
configFile: path.join(__dirname, 'karma.conf.js'),
singleRun: true,
}, handler).start();
}
*/
gulp.task('test:unit', function (cb) {
var handler = function (code) {
if (code) {
cb(new Error('test failure'));
} else {
cb();
}
};
testWithKarmaCmd(handler);
});
// coveralls
gulp.task('coveralls', ['test'], function () {
if (!process.env.CI) {
return;
}
return gulp.src(path.join(__dirname, 'coverage/report-lcov/lcov.info'))
.pipe(coveralls());
});
// coveralls-end
gulp.task('static', function () {
return gulp.src(['js/**/*.js', 'demos/**/*.js', 'spec/**/*.js'])
.pipe(excludeGitignore())
.pipe(eslint())
.pipe(eslint.format())
.pipe(eslint.failAfterError());
});
gulp.task('jsdoc', function (cb) {
gulp.src(['README.md', './src/**/*.js'], { read: false })
.pipe(jsdoc(require('./jsdoc.json'), cb));
});
gulp.task('webpack', webpackBuild('./webpack.config'));
gulp.task('demos', function () {
return gulp.src('./demos').pipe(democase());
});
gulp.task('test:demos', ['download-selenium'], function (done) {
var pathCli = path.resolve(path.dirname(resolve.sync('webdriverio', {
basedir: '.',
})), 'lib/cli');
var cpSelenium = null;
var cpWdio = null;
cpSelenium = startSeleniumServer().on('error', function () {
if (cpWdio) {
cpWdio.kill();
}
done(new Error('Failed to launch the selenium standalone server. Make sure you have JRE available'));
});
cpWdio = childProcess.fork(pathCli, [path.join(__dirname, 'wdio.conf.js')], {
env: { DEMOCASE_HTTP_PORT: 8081 },
}).on('close', function (code) {
cpSelenium.kill();
if (code) {
done(new Error('selenium test failue'));
}
done();
});
});
gulp.task('test', ['test:unit']);
gulp.task('prepublish', ['webpack']);
gulp.task('clean:test', function () {
return del(['coverage']);
});
gulp.task('clean:build', function () {
return del(['dist']);
});
gulp.task('clean', ['clean:build', 'clean:test']);
gulp.task('default', [
'static',
'webpack',
// coveralls
'coveralls',
// coveralls-end
]);