-
Notifications
You must be signed in to change notification settings - Fork 36
/
gulpfile.js
88 lines (80 loc) · 2.28 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
var gulp = require('gulp-help')(require('gulp')),
spawn = require('child_process').spawn,
mocha = require('gulp-mocha'),
jshint = require('gulp-jshint'),
path = require('path'),
nicePackage = require('gulp-nice-package'),
shrinkwrap = require('gulp-shrinkwrap'),
istanbul = require('gulp-istanbul'),
coverageEnforcer = require('gulp-istanbul-enforcer'),
TEST_FILES = [
'./test/unit/**/*.js',
'./test/integ/**/*.js'
];
gulp.task('nice-package', 'Validates package.json', function () {
return gulp.src('package.json')
.pipe(nicePackage(null, {
recommendations: false
}));
});
gulp.task('shrinkwrap', 'Cleans package.json deps and generates npm-shrinkwrap.json', function () {
return gulp.src('package.json')
.pipe(shrinkwrap())
.pipe(gulp.dest('./'));
});
gulp.task('lint', 'Lint all js', function () {
return gulp.src([
'./*.js',
'./lib/**/*.js'
].concat(TEST_FILES))
.pipe(jshint())
.pipe(jshint.reporter('jshint-stylish', {verbose: true}))
.pipe(jshint.reporter('fail'));
});
gulp.task('test', 'Tests', function () {
return gulp.src(TEST_FILES)
.pipe(mocha());
});
gulp.task('test-cover', 'Unit tests and coverage', function (cb) {
gulp.src([
'./index.js',
'./lib/**/*.js'
])
.pipe(istanbul())
.pipe(istanbul.hookRequire())
.on('finish', function () {
gulp.src(TEST_FILES)
.pipe(mocha())
.pipe(istanbul.writeReports())
.on('end', function() {
var options = {
thresholds: {
statements: 95,
branches: 93,
functions: 94,
lines: 96
},
coverageDirectory: 'coverage',
rootDirectory: ''
};
gulp.src('.')
.pipe(coverageEnforcer(options))
.on('end', cb);
});
});
});
gulp.task('test-debug', 'Run unit tests in debug mode', function () {
spawn('node', [
'--debug-brk',
path.join(__dirname, 'node_modules/gulp/bin/gulp.js'),
'test'
], {stdio: 'inherit'});
});
gulp.task('watch', 'Watch files and test on change', function () {
gulp.watch([
'./index.js',
'./lib/**/*.js',
'./test/**/*.js'
], ['test']);
});
gulp.task('ci', 'Runs all ci validation checks', ['lint', 'test-cover', 'nice-package']);