-
Notifications
You must be signed in to change notification settings - Fork 5
/
gulpfile.js
84 lines (70 loc) · 1.75 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
var gulp = require('gulp'),
cover = require('gulp-coverage'),
jshint = require('gulp-jshint'),
rimraf = require('gulp-rimraf'),
mocha = require('gulp-mocha'),
watch = require('gulp-watch'),
chalk = require('chalk');
// Common project paths
var paths = {
'src':['./index.js', './lib/**/*.js','./routes/**/*.js'],
'tests':['./test/**/*.js']
};
// An error handler for the tests during gulp-watch
// Otherwise the gulp-watch will terminate
var handleError = function(err){
console.log(chalk.red(err.name + ': ' + err.plugin + ' - ' + err.message));
return;
};
/**
* Gulp Tasks
*/
// lint source with jshint
gulp.task('lint', function(){
return gulp.src(paths.src)
.pipe(jshint())
.pipe(jshint.reporter('default'));
});
// run the mocha tests with the default dot reporter
gulp.task('test', function(){
return gulp.src(paths.tests)
.pipe(mocha({
reporter: 'dot'
}))
.on('error', handleError);
});
// run the mocha tests with the spec reporter
gulp.task('spec', function(){
return gulp.src(paths.tests)
.pipe(mocha({
reporter: 'spec'
}))
.on('error', handleError);
});
// generate a coverage report
gulp.task('coverage', function(){
return gulp.src(paths.tests)
.pipe(cover.instrument({
pattern: paths.src,
debugDirectory: '.coverdebug'
}))
.pipe(mocha({
reporter: 'spec'
}))
.pipe(cover.report({
outFile: 'coverage.html'
}))
.on('error', handleError);
});
// delete the coverage report
gulp.task('clean-coverage', function(){
return gulp.src(['.coverdebug', '.coverdata', '.coverrun', 'coverage.html'], { read: false })
.pipe(rimraf())
});
/*
* auto/watch gulp tasks that will trigger the tests on
* file changes
*/
gulp.task('autotest', function(){
gulp.watch(paths.src.concat(paths.tests), ['test']);
});