-
Notifications
You must be signed in to change notification settings - Fork 1
/
gulpfile.js
127 lines (107 loc) · 3.3 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
114
115
116
117
118
119
120
121
122
123
124
125
126
127
'use strict';
var gulp = require('gulp'),
mocha = require('gulp-mocha'),
argv = require('yargs').argv,
env = require('gulp-env'),
// lazypipe = require('lazypipe'),
jshint = require('gulp-jshint'),
gutil = require('gulp-util'),
istanbul = require('gulp-istanbul'),
del = require('rimraf'),
_ = require('lodash');
// utils = require('packages/system/server/config/util'),
// glob = require('glob');
//var util = require('util');
var pkg = argv.pkg || '*';
var paths = {
lib: ['lib/**/*.js'],
jsPublic: [],
jsTestuPkg: ['tests/**/*.js'],
jsTestiPkg: [],
scssPkg: [],
scssCommonPkg: [],
css : [],
html : []
};
var environment;
var beep = function(){
gutil.beep();
};
var setEnv = function (newEnv) {
env({
vars: {
NODE_ENV: newEnv,
NODE_PATH: process.env.NODE_PATH,
LOG4JS_CONFIG: 'log4js.json'
}
});
environment = newEnv;
};
gulp.task('env-dev', function (done) {
setEnv('development');
done();
});
gulp.task('env-test', function (done) {
setEnv('test');
done();
});
gulp.task('watchTestu', function () {
gulp.watch(_.union(paths.lib, paths.jsTestuPkg), { usePolling: true, interval: 100 }, gulp.series('jshintTestu', 'mochaTestu'));
});
gulp.task('watchCoverage', function () {
gulp.watch(_.union(paths.lib, paths.jsTestuPkg), { usePolling: true, interval: 100 }, gulp.series('jshintTestu', 'openCoverage'));
});
gulp.task('jshintServer', function(){
return gulp.src(paths.lib)
.pipe(jshint())
.pipe(jshint.reporter('default'))
.pipe(jshint.reporter('fail'))
.on('error', beep);
});
gulp.task('jshintTestu', function(){
return gulp.src(_.union(paths.lib, paths.jsTestuPkg))
.pipe(jshint())
.pipe(jshint.reporter('default'))
.pipe(jshint.reporter('fail'))
.on('error', beep);
});
gulp.task('mochaTestu', function () {
console.log('Starting testu for module : "%s"', pkg);
return gulp.src('./tests/**/*.js', {
read: false
})
.pipe(mocha({
reporter: 'spec',
// require: './server.js',
delay: false,
timeout: 10000
}))
.on('error', beep) ;
});
gulp.task('instanbul-pre-test', function(){
return gulp.src(paths.jsServer)
.pipe(istanbul({ includeUntested : true }))
.pipe(istanbul.hookRequire());
});
gulp.task('startCoverage', gulp.series('instanbul-pre-test', function(){
return gulp.src('./tests/**/*.js')
.pipe(mocha({timeout : 10000, delay : false, /*require: './server.js',*/ reporter: 'spec'}))
.on('error', beep)
.pipe(istanbul.writeReports({
dir : './coverage',
reporters : [ 'lcov' ],
reportOpts : { dir : './coverage' }
}));
}));
gulp.task('cleanCoverage', function(done){
del('./coverage/', done);
});
gulp.task('openCoverage', gulp.series('cleanCoverage', 'startCoverage', function(){
require('child_process').exec('start ./coverage/lcov-report/index.html', function (err, stdout, stderr) {
console.log(stdout);
console.log(stderr);
});
}));
gulp.task('testu', gulp.series('env-test', 'mochaTestu', 'watchTestu', function (done) { done(); }));
gulp.task('coverage', gulp.series('env-test', 'openCoverage', function(done) {done();}));
gulp.task('default', gulp.series('testu'));