-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.js
142 lines (112 loc) · 3.56 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
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
'use strict';
let promisify = require('pify');
let del = require('del');
let extend = require('extend');
let git = require('nodegit');
let mkdirp = promisify(require('mkdirp'));
let path = require('path');
let semver = require('semver');
let gulp = require('gulp');
let gulp$ = extend(require('gulp-load-plugins')({ pattern: ['gulp-*', 'gulp.*', '!gulp-git'] }), {
git: promisify(require('gulp-git')),
runSequence: promisify(require('run-sequence'))
});
let coveragePath = path.resolve('test/coverage');
let expressTmpPath = path.resolve('tmp/express');
let expressSpecsPath = path.resolve('test/express/test');
gulp.task('test', () => gulp$.runSequence(
'test:express-install',
'test:express-prepare',
'test:express',
'test:package'
));
gulp.task('test:package', () => gulp$.runSequence(
'test:unit',
'test:acceptance'
));
gulp.task('test:acceptance', () => {
return gulp.src(['test/acceptance/**/*.spec.js'])
.pipe(gulp$.debug({ title: 'test:unit' }))
.pipe(gulp$.spawnMocha({
bail: false,
ignoreLeaks: false,
slow: 100,
require: ['env-test', path.resolve('test/prereqs-acceptance')]
}));
});
gulp.task('test:unit:clean', () => del([coveragePath]));
gulp.task('test:unit', ['test:unit:clean'], () => {
return gulp.src(['test/unit/**/*.spec.js'])
.pipe(gulp$.debug({ title: 'test:unit' }))
.pipe(gulp$.spawnMocha({
istanbul: {
dir: coveragePath
},
bail: false,
ignoreLeaks: false,
slow: 20,
require: [path.resolve('test/prereqs-unit')]
}));
});
gulp.task('test:express', () => {
let blacklisted = [
'req.query.js',
'res.download.js',
'res.sendFile.js'
]
.map((filename) => '!**/' + filename);
return gulp.src([path.join(expressSpecsPath, '*.js'), ...blacklisted])
.pipe(gulp$.debug({ title: 'test:express' }))
.pipe(gulp$.spawnMocha({
bail: false,
ignoreLeaks: false,
require: [path.join(expressSpecsPath, 'support/env')]
}));
});
gulp.task('test:express-prepare:clean', () => del([expressSpecsPath]));
gulp.task('test:express-prepare', ['test:express-prepare:clean'], () => {
return gulp.src([path.join(expressTmpPath, 'test/**/*')], { dot: true })
.pipe(gulp$.debug({ title: 'test:express-prepare' }))
.pipe(gulp.dest(expressSpecsPath));
});
gulp.task('test:express-install:clean', () => del(['./tmp']));
gulp.task('test:express-install', ['test:express-install:clean'], () => {
let expressSemver = require(path.resolve('package.json')).devDependencies.express;
return mkdirp(expressTmpPath)
.then(() => git.Clone('https://github.com/expressjs/express.git', expressTmpPath))
.then((repo) => {
return git.Tag.list(repo)
.then((tags) => {
let expressVersion = semver.maxSatisfying(tags, expressSemver, true);
if (!expressVersion) {
throw new Error(`No Express version suits semver '${expressSemver}'`);
}
// working alternative to Tag.lookup and Repository.getTagByName
return repo.getReferenceCommit(expressVersion);
})
.then((commit) => git.Checkout.tree(repo, commit, { checkoutStrategy: git.Checkout.STRATEGY.FORCE }));
})
});
gulp.task('lint', () => gulp$.runSequence(
'lint:lib',
'lint:test'
));
gulp.task('lint:lib', () => {
return gulp.src(['lib/**/*.js'])
.pipe(gulp$.debug({ title: 'lint:lib' }))
.pipe(gulp$.eslint())
.pipe(gulp$.eslint.format())
.pipe(gulp$.eslint.failAfterError());
});
gulp.task('lint:test', () => {
return gulp.src(['test/unit/**/*.js'])
.pipe(gulp$.debug({ title: 'lint:test' }))
.pipe(gulp$.eslint())
.pipe(gulp$.eslint.format())
.pipe(gulp$.eslint.failAfterError());
});
gulp.task('help', gulp$.taskListing);
gulp.task('default', () => gulp$.runSequence(
'lint',
'test'
));