-
Notifications
You must be signed in to change notification settings - Fork 3
/
gulpfile.js
101 lines (92 loc) · 2.53 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
'use strict';
var gulp = require('gulp'),
gutil = require('gulp-util'),
sync = require('gulp-sync')(gulp).sync,
jshint = require('gulp-jshint'),
jscs = require('gulp-jscs'),
mocha = require('gulp-mocha'),
path = require('path'),
fs = require('fs'),
mkdirp = require('mkdirp'),
del = require('del'),
istanbul = require('gulp-istanbul');
(function printBanner() {
var bannerPath = path.resolve(__dirname, '.banner');
if (fs.existsSync(bannerPath)) {
gutil.log('\n' + gutil.colors.green(fs.readFileSync(bannerPath, 'utf8')));
} else {
gutil.log(gutil.colors.gray('Could not load application banner :('));
}
})();
function initTestMode() {
global.testMode = 'unit';
global.requireLib = function(libmodule) {
return require(path.resolve(__dirname, 'lib', libmodule));
};
}
gulp.task('clean', function(done) {
del(['build'], done);
});
gulp.task('jshint', function() {
return gulp.src([
'**/*.js',
'!node_modules/**/*'
])
.pipe(jshint())
.pipe(jshint.reporter('jshint-stylish'))
.pipe(jshint.reporter('fail'));
});
gulp.task('jscsrc', function() {
return gulp.src([
'**/*.js',
'!node_modules/**/*'
])
.pipe(jscs());
});
gulp.task('test', function() {
var testSrc = gutil.env.file || 'test/**/*.unit.js';
initTestMode();
gutil.log('Running unit tests for:', testSrc);
return gulp.src(testSrc)
.pipe(mocha({
reporter: 'mocha-jenkins-reporter',
debug: gutil.env.debug
}))
.on('error', function(e) {
gutil.log('[mocha] ' + e.stack);
});
});
gulp.task('test-cov', function(done) {
mkdirp.sync('./build/test/results');
mkdirp.sync('./build/test/coverage');
global.testMode = 'unit';
process.env.JUNIT_REPORT_PATH = 'build/test/results/report.xml';
process.env.JUNIT_REPORT_STACK = true;
gulp.src('lib/**/*.js')
.pipe(istanbul({
includeUntested: true
}))
.pipe(istanbul.hookRequire())
.on('finish', function() {
var testSrc = gutil.env.file || 'test/**/*.unit.js';
initTestMode();
gutil.log('Running instrumented unit tests for:', testSrc);
gulp.src(testSrc)
.pipe(mocha({
reporter: 'mocha-jenkins-reporter',
debug: gutil.env.debug
}))
.pipe(istanbul.writeReports({
dir: './build/test/coverage',
reporters: ['lcov', 'json', 'text', 'text-summary', 'cobertura'],
reportOpts: { dir: './build/test/coverage' }
}))
.on('error', function(e) {
gutil.log('[mocha] ' + e.stack);
})
.on('end', done);
});
});
gulp.task('checkstyle', sync(['jshint', 'jscsrc']));
gulp.task('default', sync(['clean', 'checkstyle', 'test']));
gulp.task('ci', sync(['clean', 'checkstyle', 'test-cov']));