-
Notifications
You must be signed in to change notification settings - Fork 10
/
GulpFile.js
90 lines (79 loc) · 2.18 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
'use strict';
const gulp = require('gulp');
const mocha = require('gulp-mocha');
const istanbul = require('gulp-istanbul');
const argv = require('yargs').argv;
const eslint = require('gulp-eslint');
const gulpIf = require('gulp-if');
/**
* Istanbul coverage
*/
gulp.task('pre-test', () => {
return gulp.src([
'**/*.js',
'!GulpFile.js',
'!coverage/**',
'!test/**',
'!node_modules/**',
'!public/**',
'!views/**'])
.pipe(istanbul())
.pipe(istanbul.hookRequire());
});
/**
* Mocha tests and coverage report
*/
gulp.task('test', ['pre-test'], () => {
const stream = gulp.src(['test/**/*.js'], { read: false })
.pipe(mocha({
ui: 'bdd',
timeout: 100000,
slow: 50,
reporter: 'spec',
recursive: true,
require: ['./test/common']
}));
if (!argv.noReport) stream.pipe(istanbul.writeReports());
return stream.pipe(istanbul.enforceThresholds({ thresholds: { global: 10 } })) // TODO increase the limit to mandate coverage
.once('error', err => {
console.error(err); // eslint-disable-line no-console
return process.exit(1);
})
.once('end', () => {
return process.exit(0);
});
});
gulp.task('eslint', () => {
return gulp.src(['**/*.js', 'bin/www', '!coverage/**/*.js', '!tools/**/*.js'])
.pipe(eslint({
useEslintrc: true
}))
.pipe(eslint.format())
.pipe(eslint.failAfterError())
.on('error', err => {
console.error(err); // eslint-disable-line no-console
process.exit(1);
});
});
gulp.task('fix', () => {
const isFixed = file => file.eslint && file.eslint.fixed;
return gulp.src(['**/*.js', '**/www', '!coverage/**/*.js', '!tools/**/*.js'])
.pipe(eslint({
useEslintrc: true,
fix: true
}))
.pipe(eslint.format())
.pipe(gulpIf(isFixed, gulp.dest('./')));
});
/**
* Global check
*/
gulp.task('check', ['eslint', 'test']);
/**
* Pre-push hook
*/
gulp.task('pre-push', ['check']);
/**
* Default task
*/
gulp.task('default', ['check']);