forked from cironunes/angular-testing-recipes
-
Notifications
You must be signed in to change notification settings - Fork 7
/
gulpfile.js
63 lines (56 loc) · 1.6 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
var gulp = require('gulp');
var gutil = require('gulp-util');
var jshint = require('gulp-jshint');
var stylish = require('jshint-stylish');
var _ = require('lodash');
var Server = require('karma').Server;
var karmaConf = require('./karma.conf.js');
var map = require('map-stream');
var exitCode = 0;
var totalLintErrors = 0;
var coveralls = require('gulp-coveralls');
function lintOnEnd() {
var errString = totalLintErrors + '';
if (exitCode) {
console.log(gutil.colors.magenta(errString), 'errors\n');
gutil.beep();
}
}
gulp.task('test', function(done) {
var server = new Server(_.assign({}, karmaConf, { singleRun: true }), done);
server.start();
});
gulp.task('tdd', function(done) {
var server = new Server(karmaConf, done);
server.start();
});
gulp.task('jshint', function() {
return gulp.src('./{controllers,decorators,directives,filters,services,routes}/*.js')
.pipe(jshint('.jshintrc'))
.pipe(jshint.reporter(stylish))
.pipe(map(function (file, cb) {
if (!file.jshint.success) {
totalLintErrors += file.jshint.results.length;
exitCode = 1;
}
cb(null, file);
}))
.on('end', function () {
lintOnEnd();
if (exitCode) {
process.emit('exit');
}
});
});
gulp.task('test-coverage', ['test'], function() {
gulp.src('./coverage/report-lcov/lcov.info')
.pipe(coveralls());
});
process.on('exit', function () {
process.nextTick(function () {
var msg = "gulp '" + gulp.seq + "' failed";
console.log(gutil.colors.red(msg));
process.exit(exitCode);
});
});
gulp.task('default', ['jshint', 'test-coverage']);