forked from orionhealth/ytemplater
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgulpfile.js
64 lines (53 loc) · 1.35 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
var growl = require('growl'),
gulp = require('gulp'),
jshint = require('gulp-jshint-cached'),
mocha = require('gulp-mocha'),
through = require('through'),
paths = {
scripts: './lib/*.js',
tests: './test/*.test.js'
};
// Require the test setup module as the --require option can only be used via commandline execution of mocha
require('./test/setup.js');
function test(notifyOnFail) {
var stream = gulp.src(paths.tests, { read: false })
.pipe(mocha({
reporter: 'nyan'
}));
if (notifyOnFail) {
stream.on('error', function() {
growl('Tests failed!', { name: 'Mocha' });
});
}
return stream;
}
function notifyOnJshintFail() {
var failDetected = false;
return through(function write(file) {
if (!file.jshint.success) {
failDetected = true;
}
this.queue(file);
}, function end() {
if (failDetected) {
growl('JSHint failed!', { name: 'JSHint' });
}
this.queue(null);
});
}
gulp.task('lint', function() {
return gulp.src([paths.scripts, paths.tests])
.pipe(jshint.cached())
.pipe(notifyOnJshintFail())
.pipe(jshint.reporter('default'));
});
gulp.task('test', function() {
return test();
});
gulp.task('on-watch', ['lint'], function() {
// Don't return, otherwise failed tests will kill the watch
test(true);
});
gulp.task('default', ['on-watch'], function() {
gulp.watch('{lib,test}/*', ['on-watch']);
});