-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathgulpfile.js
63 lines (53 loc) · 2 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
'use strict';
var gulp = require('gulp');
var gutil = require('gulp-util');
var mocha = require('gulp-mocha');
var istanbul = require('gulp-istanbul');
var coveralls = require('gulp-coveralls');
var isparta = require('isparta');
var runSequence = require('run-sequence');
// Transform all required files with Babel
require('babel-core/register');
var TEST_FILES = 'test/*.spec.js';
var SRC_FILES = 'src/*.js';
gulp.task('test', function () {
// gulp-mocha V4x is not compatible with this approach to code coverage.
// Using gulp-mocha V4x and adding {compilers: 'js:babel-core/register'} will
// enable tests to run but coverage will not work.
// https://github.com/sindresorhus/gulp-mocha/releases/tag/v4.0.0
return gulp.src(TEST_FILES, { read: false })
.pipe(mocha({
require: [__dirname + '/scripts/jsdom'] // Prepare jsdom environement
}));
});
gulp.task('coverage:instrument', function () {
return gulp.src(SRC_FILES)
.pipe(istanbul({
instrumenter: isparta.Instrumenter // Use the isparta instrumenter (code coverage for ES6)
// https://github.com/SBoudrias/gulp-istanbul#istanbulopt
}))
.pipe(istanbul.hookRequire()); // Force `require` to return covered files
// https://github.com/SBoudrias/gulp-istanbul#istanbulhookrequire
});
gulp.task('coverage:report', function () {
return gulp.src(SRC_FILES, { read: false })
.pipe(istanbul.writeReports({
// https://github.com/SBoudrias/gulp-istanbul#istanbulwritereportsopt
}));
});
gulp.task('test:coverage', function (done) {
runSequence('coverage:instrument', 'test', 'coverage:report', done);
});
gulp.task('coveralls', function() {
return gulp.src('./coverage/lcov.info')
.pipe(coveralls());
});
gulp.task('test:coveralls', function (done) {
runSequence('test:coverage', 'coveralls', done);
});
gulp.task('tdd', function () {
gulp.watch([
TEST_FILES,
SRC_FILES
], ['test']).on('error', gutil.log);
});