-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathgulpfile.js
113 lines (98 loc) · 2.37 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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
'use strict';
var gulp = require('gulp');
var $ = require('gulp-load-plugins')();
var path = {
all: [
'lib/**/*.js',
'test/**/*.js',
'gulpfile.js'
],
code: [ 'lib/**/*.js' ],
test: [
'test/**/*.js',
'!test/setup.js',
'!test/resources/**/*.js'
],
testSetup: [ 'test/setup.js' ],
testResources: [ 'test/resources/**/*.js' ]
};
var watching = false;
gulp.task('lint', function () {
return lint(gulp.src(path.all));
});
gulp.task('test', function (cb) {
gulp.src(path.code)
.pipe($.istanbul({
includeUntested: true
}))
.on('finish', function () {
test(gulp.src(path.test))
.pipe($.istanbul.writeReports())
.on('end', cb);
});
});
gulp.task('watch', function () {
watching = true;
// Lints only changed files
lint($.watch(path.all));
// Tests using only changed test files
$.watch(path.test, test);
// Tests all on code and test resource changes
gulp.watch([
path.code,
path.testSetup,
path.testResources
], [ 'test' ]);
});
gulp.task('coveralls', [ 'lint', 'test' ], function () {
return gulp.src('coverage/lcov.info')
.pipe($.coveralls());
});
function lint(src) {
return src
.pipe($.jshint())
.pipe($.jshint.reporter('jshint-stylish'))
.pipe($.notify({
title: 'Lint',
message: function (file) {
if (file.jshint.success) {
return false;
}
var errors = file.jshint.results.map(function (data) {
if (data.error) {
return $.util.template(
'(<%= line %>:<%= character %>) <%= reason %>',
{
file: file,
line: data.error.line,
character: data.error.character,
reason: data.error.reason
}
);
}
}).join('\n');
return '<%= file.relative %> ' +
'(<%= file.jshint.results.length %> ' +
'error<% if (file.jshint.results.length > 1) { %>s<% } %>).\n' +
errors;
}
}))
.pipe($.jshint.reporter('fail'));
}
function test(src) {
require('./test/setup');
return src
.pipe($.mocha())
.on('error', $.notify.onError({
title: 'Mocha',
message: '<%= error.message %>'
}))
.on('error', function () {
if (watching) {
this.emit('end');
}
else {
process.exit(1);
}
});
}