-
Notifications
You must be signed in to change notification settings - Fork 42
/
gulpfile.js
72 lines (62 loc) · 2.13 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
'use strict';
var gulp = require('gulp'),
browserify = require('gulp-browserify'),
replace = require('gulp-replace'),
mochaPhantomJS = require('gulp-mocha-phantomjs'),
istanbul = require('gulp-istanbul'),
istanbulReport = require('gulp-istanbul-report'),
coveralls = require('gulp-coveralls'),
clean = require('gulp-clean');
// Build task, to generate the bundled browserify file
gulp.task('build', function() {
return gulp.src('lib/jsonpipe.js')
.pipe(browserify({
standalone: "jsonpipe"
}))
.pipe(gulp.dest('.'));
});
// The watch task
gulp.task('watch', function() {
gulp.watch('lib/**/*.js', ['build']);
});
gulp.task('test', ['build'], function() {
return gulp.src('test/jsonpipe.html')
.pipe(mochaPhantomJS());
});
// Add a task to instrument src files
gulp.task('instrument', ['build'], function() {
return gulp.src('./jsonpipe.js')
.pipe(istanbul({coverageVariable: "__coverage__"}))
.pipe(gulp.dest('lib-cov/'));
});
// Add the test coverage task task
gulp.task('test-cov', ['instrument'], function() {
var htmlFile = 'test/jsonpipe.html',
replaceStrs = ['../jsonpipe.js', '../lib-cov/jsonpipe.js'],
coverageJSON = 'coverage/coverage.json';
return gulp.src(htmlFile)
.pipe(replace.apply(null, replaceStrs))
.pipe(gulp.dest('test')) // Override the same file
.pipe(mochaPhantomJS({
reporter: 'spec',
phantomjs: {
hooks: 'mocha-phantomjs-istanbul',
coverageFile: coverageJSON
}
}))
.on('finish', function() {
// generate coverage.json after finish
gulp.src(coverageJSON)
.pipe(istanbulReport({reporters: ['lcov']}));
// Revert the html file
gulp.src(htmlFile)
.pipe(replace.apply(null, replaceStrs.reverse()))
.pipe(gulp.dest('test'));
});
});
gulp.task('report-coveralls', function() {
return gulp.src('./coverage/lcov.info')
.pipe(coveralls());
});
// Make the default task as test
gulp.task('default', ['test']);