forked from tobernguyen/fu-marketplace-api
-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.js
59 lines (50 loc) · 1.72 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
'use strict';
var gulp = require('gulp'),
mocha = require('gulp-mocha'),
gutil = require('gulp-util'),
gulpIf = require('gulp-if'),
eslint = require('gulp-eslint'),
istanbul = require('gulp-istanbul');
function isFixed(file) {
// Has ESLint fixed the file contents?
return file.eslint != null && file.eslint.fixed;
}
gulp.doneCallback = function (err) {
process.exit(err ? 1 : 0);
};
gulp.task('set-test-node-env', function() {
return process.env.NODE_ENV = 'test';
});
gulp.task('mocha', ['set-test-node-env'],function() {
return gulp.src(['test/**/*.js'], {read:false})
.pipe(mocha({reporter: 'spec'}))
.on('error', gutil.log);
});
gulp.task('lint-n-fix', function() {
return gulp.src(['**/*.js', '*.js', '!node_modules/**', '!coverage/**', '!bin/**'], {base: './'})
.pipe(eslint({
fix: true
}))
.pipe(eslint.format())
.pipe(gulpIf(isFixed, gulp.dest('./')));
});
gulp.task('lint', function() {
return gulp.src(['**/*.js', '*.js', '!node_modules/**', '!coverage/**', '!bin/**'])
.pipe(eslint({}))
.pipe(eslint.format());
});
gulp.task('pre-istanbul', function () {
return gulp.src(['controllers/**/*.js', '!controllers/index.js', 'libs/**/*.js', 'middlewares/**/*.js', 'models/**/*.js', '!models/index.js', 'routes/**/*.js'])
// Covering files
.pipe(istanbul())
// Force `require` to return covered files
.pipe(istanbul.hookRequire());
});
gulp.task('istanbul', ['set-test-node-env', 'pre-istanbul'], function () {
return gulp.src(['test/**/*.js'])
.pipe(mocha())
// Creating the reports after tests ran
.pipe(istanbul.writeReports())
// Enforce a coverage of at least 90%
.pipe(istanbul.enforceThresholds({ thresholds: { global: 90 } }));
});