-
Notifications
You must be signed in to change notification settings - Fork 5
/
gulpfile.js
93 lines (82 loc) · 2.43 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
// Include gulp
var gulp = require('gulp');
var plugins = require('gulp-load-plugins')();
var argv = require('yargs').argv;
var stylish = require('jshint-stylish');
var paths = {
sourceFiles: 'lib/**/*.js',
testFiles: 'test/**/*.js',
gulpFile: 'gulpfile.js',
};
var envVars = {
COVERAGE_DIR: '.',
};
/* jshint camelcase: false */
gulp.task('style', function () {
gulp.src([paths.sourceFiles, paths.testFiles, paths.gulpFile])
.pipe(plugins.jscs());
});
gulp.task('cover', function () {
if (process.env.NODE_ENV !== 'test') {
Object.keys(envVars).forEach(function (key) {
process.env[key] = envVars[key];
});
}
return gulp.src(paths.sourceFiles)
.pipe(plugins.istanbul());
});
gulp.task('coveralls', function () {
gulp.src('coverage/**/lcov.info')
.pipe(plugins.coveralls());
});
gulp.task('test', ['lint', 'style', 'cover'], function () {
if (process.env.NODE_ENV !== 'test') {
gulp.src(process.env.COVERAGE_DIR + '/coverage')
.pipe(plugins.clean());
Object.keys(envVars).forEach(function (key) {
process.env[key] = envVars[key];
});
}
var options = {
dir: process.env.COVERAGE_DIR + '/coverage',
reporters: ['lcov', 'json', 'text', 'text-summary'],
reportOpts: {dir: process.env.COVERAGE_DIR + '/coverage'}
};
return gulp.src(paths.testFiles)
.pipe(plugins.mocha({reporter: 'spec', timeout: 15000, grep: argv.grep}))
.on('error', function (error) {
plugins.util.log(plugins.util.colors.red(error.message));
process.exit(1);
})
.pipe(plugins.istanbul.writeReports(options))
.pipe(plugins.exit());
});
gulp.task('enforce', function () {
return gulp.src('.')
.pipe(plugins.istanbulEnforcer({
thresholds: {
statements: 96,
branches: 96,
functions: 96,
lines: 96
},
coverageDirectory: process.env.COVERAGE_DIR,
rootDirectory: ''
}))
.on('error', function (error) {
plugins.util.log(plugins.util.colors.red(error.message));
process.exit(1);
})
.pipe(plugins.exit());
});
gulp.task('lint', function () {
gulp.src([paths.sourceFiles, paths.testFiles, paths.gulpFile])
.pipe(plugins.jshint())
.pipe(plugins.jshint.reporter(stylish))
.pipe(plugins.jshint.reporter('fail'));
});
gulp.task('lint-nofail', function () {
gulp.src([paths.sourceFiles, paths.testFiles, paths.gulpFile])
.pipe(plugins.jshint())
.pipe(plugins.jshint.reporter(stylish));
});