This repository has been archived by the owner on Dec 8, 2017. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 4
/
gulpfile.js
69 lines (57 loc) · 1.77 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
var gulp = require('gulp');
var yargs = require('yargs');
var mocha = require('gulp-mocha');
var eslint = require('gulp-eslint');
var istanbul = require('gulp-istanbul');
var TEST_DEPENDENCIES = getTestDependencies();
require('coffee-script/register');
function buildArgs(args) {
var argName, skipArgs = { _: true, '$0': true };
for (argName in yargs.argv) {
if (yargs.argv.hasOwnProperty(argName) && !skipArgs[argName]) {
args[argName] = yargs.argv[argName];
}
}
return args;
}
gulp.task('setup-coverage', function() {
return gulp.src(['scripts/**/*.js', 'lib/**/*.js'])
.pipe(istanbul({ includeUntested: true }))
.pipe(istanbul.hookRequire());
});
function getTestDependencies() {
var dependencies = [];
if (process.env.CI === 'true' || process.env.COVERAGE === 'true') {
dependencies.push('setup-coverage');
}
return dependencies;
}
function getCoverageReportOptions() {
var options;
if (process.env.CI === 'true') {
options = { reporters: ['text', 'lcovonly'] };
}
return options;
}
gulp.task('test', TEST_DEPENDENCIES, function() {
var tests = gulp.src(['./test/*.js'], {read: false}),
coverageEnabled = TEST_DEPENDENCIES.indexOf('setup-coverage') !== -1;
// Reporters:
// https://github.com/mochajs/mocha/blob/master/lib/reporters/index.js
return tests.pipe(mocha(buildArgs({ reporter: 'spec' })))
.on('error', function() {
coverageEnabled = false;
})
.on('end', function() {
if (coverageEnabled) {
return tests.pipe(istanbul.writeReports(getCoverageReportOptions()));
}
});
});
gulp.task('lint', function() {
return gulp.src([
'bin/*', '*.js', 'scripts/**/*.js', 'lib/**/*.js', 'test/**/*.js',
'config-validator/index.js'])
.pipe(eslint())
.pipe(eslint.format());
});