This repository has been archived by the owner on Feb 2, 2023. It is now read-only.
forked from Modernizr/Modernizr
-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.babel.js
156 lines (139 loc) · 3.56 KB
/
gulpfile.babel.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
143
144
145
146
147
148
149
150
151
152
153
154
155
156
'use strict';
import gulp from 'gulp';
import connect from 'gulp-connect';
import eslint from 'gulp-eslint';
import pug from 'gulp-pug';
import del from 'del';
import fs from 'fs-extra';
import globby from 'globby';
import Mocha from 'mocha';
import Mochaheadless from 'mocha-headless-chrome';
import modernizr from './lib/cli';
import config from './lib/config-all';
const directories = {
browserTests: globby.sync([
'test/universal/**/*.js',
'test/browser/**/*.js',
'!test/browser/setup.js',
'!test/browser/integration/*.js'
]),
integrationTests: globby.sync([
'test/browser/integration/*.js'
]),
nodeTests: globby.sync([
'test/universal/**/*.js',
'test/node/**/*.js'
])
};
let failures = 0;
gulp.task('clean', () => {
return del([
'dist',
'gh-pages',
'test/coverage',
'test/*.html',
'tmp'
]);
});
gulp.task('copy:gh-pages', () => {
return gulp.src([
'./dist/**/*',
'./lib/**/*',
'./node_modules/chai/**/*',
'./node_modules/jquery/**/*',
'./node_modules/json3/**/*',
'./node_modules/lodash/**/*',
'./node_modules/mocha/**/*',
'./node_modules/requirejs/**/*',
'./node_modules/sinon/**/*',
'./node_modules/ua-parser-js/**/*',
'./src/**/*',
'./test/**/*',
'!./test/coverage/**/*'
], { 'base' : '.' })
.pipe(gulp.dest('gh-pages/'))
});
gulp.task('eslint', () => {
return gulp.src([
...directories.browserTests,
...directories.integrationTests,
...directories.nodeTests,
'feature-detects/**/*.js',
'lib/*.js',
'src/*.js',
'test/**/*.js',
'!src/html5shiv.js',
'!src/html5printshiv.js',
'!test/coverage/**/*.js'
])
.pipe(eslint({
fix: true,
configFile: '.eslintrc'
}))
.pipe(eslint.format())
.pipe(eslint.failOnError());
});
gulp.task('generate', (done) => {
modernizr.build(config, function(output) {
fs.outputFile('dist/modernizr-build.js', output).then(() => {
done();
})
});
});
gulp.task('mocha:browser', (done) => {
const options = {
reporter: 'dot',
timeout: 5000,
args: ['disable-web-security']
};
Mochaheadless.runner({
...options,
file: 'test/integration.html',
})
.then(result => {
failures += result.result.failures.length;
return Mochaheadless.runner({
...options,
file: 'test/unit.html'
});
})
.then(result => {
failures += result.result.failures.length;
process.exitCode = failures; // exit with non-zero status if there were failures
done();
});
});
gulp.task('mocha:node', (done) => {
const mocha = new Mocha({
reporter: 'dot',
timeout: 5000
});
directories.nodeTests.forEach(file => {
mocha.addFile(file);
});
// Run the tests.
mocha.run(fails => {
failures += fails;
done();
});
});
gulp.task('pug', () => {
return gulp.src('test/browser/*.pug')
.pipe(pug({
data: {
browserTests: directories.browserTests,
integrationTests: directories.integrationTests
}
}))
.pipe(gulp.dest('test/'))
});
gulp.task('serve:gh-pages', gulp.series('clean', 'generate', 'pug', 'copy:gh-pages', (done) => {
connect.server({
host: '0.0.0.0',
root: 'gh-pages/',
});
done();
}));
gulp.task('test', gulp.series('clean', 'eslint', 'generate', 'pug', 'mocha:node', 'mocha:browser'));
gulp.task('gh-pages', gulp.series('clean', 'pug', 'generate', 'copy:gh-pages'));
gulp.task('default', gulp.series('clean', 'eslint', 'generate'));