-
Notifications
You must be signed in to change notification settings - Fork 13
/
gulpfile.js
100 lines (87 loc) · 2.69 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
'use strict';
var gulp = require('gulp')
, assign = Object.assign || require('object.assign')
, del = require('del')
, jshint = require('gulp-jshint')
, plumber = require('gulp-plumber')
, browserify = require('browserify')
, source = require('vinyl-source-stream')
, glob = require('glob')
, mocha = require('gulp-mocha')
, mochaPhantomJS = require('gulp-mocha-phantomjs')
, size = require('gulp-size')
, sourcemaps = require('gulp-sourcemaps')
, buffer = require('vinyl-buffer')
;
var builtins = assign({}, require('browserify/lib/builtins'), {
http: require.resolve('./lib/util/http'),
https: require.resolve('./lib/util/https'),
// This one deserves a massive warning:
// BEWARE, NOCK IN BROWSER TESTS IS NOT THE SAME AS THE ONE IN NODE TESTS
// I'm overriding it here to reduce the size of diff.
// TODO: inline the change during refactoring
nock: require.resolve('./lib/util/mock')
});
// Timeout for each integration test (in ms)
var INTEGRATION_TEST_TIMEOUT = 10000;
gulp.task('clean', function(cb) {
del(['dist'], cb);
});
gulp.task('lint', function() {
return gulp.src(['index.js', 'tests/**/*.js'])
.pipe(plumber())
.pipe(jshint())
.pipe(jshint.reporter('default'));
});
gulp.task('browserify', function() {
return browserify('./index.js', {
standalone: 'st2client',
builtins: builtins
}).bundle()
.pipe(source('st2client.js'))
.pipe(buffer())
.pipe(gulp.dest('dist'))
.pipe(size({
showFiles: true
}))
.pipe(size({
showFiles: true,
gzip: true
}));
});
gulp.task('browserify-tests', function() {
return browserify(glob.sync('./tests/test-*.js'), {
debug: true,
builtins: builtins
}).bundle()
.pipe(source('tests.js'))
.pipe(buffer())
.pipe(sourcemaps.init({ loadMaps: true }))
.pipe(sourcemaps.write('./'))
.pipe(gulp.dest('dist'));
});
gulp.task('test', function () {
return gulp.src('tests/**/*.js', {read: false})
.pipe(mocha({
reporter: process.env.reporter || 'spec'
}));
});
gulp.task('test-browser', gulp.series('browserify', 'browserify-tests', function () {
return gulp.src('tests/tests.html')
.pipe(mochaPhantomJS({
reporter: process.env.reporter || 'spec',
phantomjs: {
useColors: true
}
}));
}));
gulp.task('test-integration', function () {
var options = {'timeout': INTEGRATION_TEST_TIMEOUT};
return gulp.src('integration/**/*.js', {read: false})
.pipe(mocha(options));
});
gulp.task('build', gulp.series('browserify'));
gulp.task('watch', function() {
gulp.watch(['index.js', 'tests/**/*.js'], ['lint', 'browserify']);
});
gulp.task('default', gulp.series('lint', 'browserify', 'browserify-tests', 'test'));