This repository has been archived by the owner on Aug 31, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 52
/
gulpfile.js
81 lines (73 loc) · 2.73 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
/* (c) 2015 Ari Porad (@ariporad) <ari@ariporad.com>. MIT Licensed */
'use strict';
/**
* Module dependencies.
*/
var gulp = require('gulp');
var plugins = require('load-plugins')('gulp-*');
var SRC_JS = ['lib/**/*.js'];
var TESTS = ['test/**/*.test.js'];
var JS_OTHER = ['test/**/*.js', '!test/**/*.test.js'];
gulp.task('lint', function lint() {
return gulp.src(SRC_JS.concat(TESTS))
.pipe(plugins.eslint())
.pipe(plugins.eslint.format())
.pipe(plugins.eslint.failAfterError());
});
function test() {
return gulp.src(TESTS)
.pipe(plugins.mocha());
}
gulp.task('test', ['lint'], function testTask() {
// We need this because gulp-mocha won't exit if any connections are left open. We close all of ours (I think), so I blame socket.io
return test()
.pipe(plugins.exit());
});
gulp.task('test-cov', ['lint'], function testcov(cb) {
gulp.src(SRC_JS)
.pipe(plugins.istanbul()) // Covering files
.pipe(plugins.istanbul.hookRequire()) // Force `require` to return covered files
.on('finish', function () {
test()
.pipe(plugins.istanbul.writeReports()) // Creating the reports after tests ran
.pipe(plugins.istanbul.enforceThresholds({thresholds: {global: 75}})) // Min CC
.on('end', function uploadCoverage(err) {
if (err) {
console.log(err.message);
console.log(err.stack);
process.exit(1);
}
console.log('Uploading to Coveralls');
gulp.src('coverage/**/lcov.info')
.pipe(plugins.debug({title: 'in: '}))
.pipe(plugins.coveralls())
.pipe(plugins.debug({title: 'out: '}))
.on('error', function ignoreNoProjectFoundErrors(err) {
console.log('Error Found:', err);
if (err.message.indexOf('find') > -1 &&
err.message.indexOf('repo') > -1) {
console.log(
'Hey, it looks like you haven\'t setup coveralls yet, or you\'re not ' +
'on Travis! No problem, but I\'m not going to upload code coverage.'
);
// See above comment, but we need this due to gulp-mocha and socket.io
process.exit();
} else {
console.log('Error Uploading to Coveralls:');
process.nextTick(function () {
process.exit(1);
});
throw err;
}
})
// See above comment, but we need this due to gulp-mocha and socket.io
.on('finish', function kill() {
console.log('Uploaded to Coveralls');
process.exit();
})
});
});
});
gulp.task('watch', function watch() {
gulp.watch(SRC_JS, ['test']);
});