forked from DevExpress/testcafe-hammerhead
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Gulpfile.js
315 lines (266 loc) · 8.99 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
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
const babel = require('@babel/core');
const gulpBabel = require('gulp-babel');
const gulpTypeScript = require('gulp-typescript');
const del = require('del');
const eslint = require('gulp-eslint');
const fs = require('fs');
const gulp = require('gulp');
const gulpStep = require('gulp-step');
const qunitHarness = require('gulp-qunit-harness');
const mocha = require('gulp-mocha-simple');
const mustache = require('gulp-mustache');
const rename = require('gulp-rename');
const webmake = require('@belym.a.2105/gulp-webmake');
const uglify = require('gulp-uglify');
const util = require('gulp-util');
const ll = require('gulp-ll-next');
const gulpRunCommand = require('gulp-run-command').default;
const clone = require('gulp-clone');
const mergeStreams = require('merge-stream');
const path = require('path');
gulpStep.install();
ll
.install()
.tasks('lint')
.onlyInDebug([
'server-scripts',
'client-scripts-bundle'
]);
const getClientTestSettings = () => {
return {
basePath: './test/client/fixtures',
port: 2000,
crossDomainPort: 2001,
scripts: [
{ src: '/hammerhead.js', path: util.env.dev ? './lib/client/hammerhead.js' : './lib/client/hammerhead.min.js' },
{ src: '/before-test.js', path: './test/client/before-test.js' }
],
configApp: require('./test/client/config-qunit-server-app')
};
};
const CLIENT_TESTS_BROWSERS = [
{
platform: 'Windows 10',
browserName: 'MicrosoftEdge'
},
{
platform: 'Windows 10',
browserName: 'chrome'
},
{
platform: 'Windows 10',
browserName: 'firefox'
},
{
platform: 'Windows 10',
browserName: 'internet explorer',
version: '11.0'
},
{
browserName: 'safari',
platform: 'macOS 10.14',
version: '12.0'
},
{
browserName: 'safari',
platform: 'macOS 10.15',
version: 'latest'
},
{
browserName: 'Safari',
deviceName: 'iPhone 7 Plus Simulator',
platformVersion: '11.3',
platformName: 'iOS'
},
{
deviceName: 'Android GoogleAPI Emulator',
browserName: 'Chrome',
platformVersion: '7.1',
platformName: 'Android'
},
{
browserName: 'chrome',
platform: 'OS X 10.11'
},
{
browserName: 'firefox',
platform: 'OS X 10.11'
}
];
const SAUCELABS_SETTINGS = {
username: process.env.SAUCE_USERNAME,
accessKey: process.env.SAUCE_ACCESS_KEY,
build: process.env.TRAVIS_JOB_ID || '',
tags: [process.env.TRAVIS_BRANCH || 'master'],
browsers: CLIENT_TESTS_BROWSERS,
name: 'testcafe-hammerhead client tests',
timeout: 360
};
function hang () {
return new Promise(() => {
// NOTE: Hang forever.
});
}
// Build
gulp.task('clean-lib', () => {
return del(['./lib']);
});
gulp.task('clean-outdated-js', () => {
// NOTE: It's necessary to prevent problems related to changing file structure in the 'src' folder
return del(['./src/**/*.js']);
});
gulp.step('client-scripts-transpile', () => {
const tsConfig = gulpTypeScript.createProject('tsconfig.json');
const sharedScripts = [
'./src/processing/**/*.ts',
'./src/request-pipeline/xhr/*.ts',
'./src/request-pipeline/*-header-names.ts',
'./src/shadow-ui/*.ts',
'./src/typings/*.ts',
'./src/upload/*.ts',
'./src/utils/*.ts',
'./src/session/*.ts'
];
return gulp.src(['./src/client/**/*.ts'].concat(sharedScripts))
.pipe(tsConfig())
.pipe(gulp.dest(file => file.base));
});
gulp.step('client-scripts-bundle', () => {
const transform = (filename, code) => {
const transformed = babel.transform(code, {
sourceMap: false,
filename: filename,
ast: false,
// NOTE: force usage of client .babelrc for all
// files, regardless of their location
babelrc: false,
extends: path.join(__dirname, './src/client/.babelrc')
});
// HACK: babel-plugin-transform-es2015-modules-commonjs forces
// 'use strict' insertion. We need to remove it manually because
// of https://github.com/DevExpress/testcafe/issues/258
return { code: transformed.code.replace(/^('|")use strict('|");?/, '') };
};
const hammerhead = gulp.src('./src/client/index.js')
.pipe(webmake({ sourceMap: false, transform }))
.pipe(rename('hammerhead.js'));
const transportWorker = gulp.src('./src/client/transport-worker/index.js')
.pipe(webmake({ sourceMap: false, transform }))
.pipe(rename('transport-worker.js'));
return mergeStreams(hammerhead, transportWorker)
.pipe(gulp.dest('./lib/client'));
});
gulp.step('client-scripts-processing', () => {
const script = gulp.src('./src/client/index.js.wrapper.mustache')
.pipe(mustache({ source: fs.readFileSync('./lib/client/hammerhead.js').toString() }))
.pipe(rename('hammerhead.js'));
const bundledScript = script.pipe(clone())
.pipe(uglify())
.pipe(rename('hammerhead.min.js'));
const bundledTransportWorker = gulp.src('./lib/client/transport-worker.js')
.pipe(uglify())
.pipe(rename('transport-worker.min.js'));
return mergeStreams(script, bundledScript, bundledTransportWorker)
.pipe(gulp.dest('./lib/client'));
});
gulp.step('client-scripts', gulp.series('client-scripts-transpile', 'client-scripts-bundle', 'client-scripts-processing'));
gulp.step('server-scripts', () => {
return gulp
.src([
'./src/**/*.ts',
'!src/client/**/*.ts'
])
.pipe(gulpBabel())
.pipe(gulp.dest('lib'));
});
gulp.step('templates', () => {
return gulp
.src('./src/client/task.js.mustache', { silent: false })
.pipe(gulp.dest('./lib/client'));
});
gulp.step('lint-js', () => {
return gulp
.src([
'./test/server/*.js',
'./test/client/fixtures/**/*.js',
'Gulpfile.js'
])
.pipe(eslint())
.pipe(eslint.format())
.pipe(eslint.failAfterError());
});
gulp.step('lint-ts', () => {
return gulp.src('./src/**/*.ts')
.pipe(eslint())
.pipe(eslint.format())
.pipe(eslint.failAfterError());
});
gulp.task('lint', gulp.parallel('lint-js', 'lint-ts'));
gulp.task('build',
gulp.series(
'clean-lib',
'clean-outdated-js',
'server-scripts',
gulp.parallel(
'client-scripts',
'templates',
'lint'
)
)
);
// Test
gulp.step('mocha', () => {
return gulp.src('./test/server/*-test.js', { read: false })
.pipe(mocha({
// NOTE: Disable timeouts in debug mode.
timeout: typeof v8debug !== 'undefined' || !!process.debugPort ? Infinity : 2000,
fullTrace: true
}));
});
gulp.task('test-server', gulp.series('build', 'mocha'));
gulp.step('qunit', () => {
gulp.watch('./src/**/*.ts', gulp.series('build'));
return gulp
.src('./test/client/fixtures/**/*-test.js')
.pipe(qunitHarness(getClientTestSettings()));
});
gulp.task('test-client', gulp.series('build', 'qunit'));
gulp.step('set-dev-mode', done => {
util.env.dev = true;
done();
});
gulp.task('test-client-dev', gulp.series('set-dev-mode', 'test-client'));
gulp.step('travis-saucelabs-qunit', () => {
return gulp
.src('./test/client/fixtures/**/*-test.js')
.pipe(qunitHarness(getClientTestSettings(), SAUCELABS_SETTINGS));
});
gulp.task('test-client-travis', gulp.series('build', 'travis-saucelabs-qunit'));
gulp.step('http-playground-server', () => {
require('./test/playground/server.js').start();
return hang();
});
gulp.step('set-multi-browser-mode', done => {
process.env.allowMultipleWindows = true;
done();
});
gulp.task('multi-window-http-playground', gulp.series('build', 'set-multi-browser-mode', 'http-playground-server'));
gulp.task('http-playground', gulp.series('build', 'http-playground-server'));
gulp.step('https-playground-server', () => {
const selfSignedCertificate = require('openssl-self-signed-certificate');
require('./test/playground/server.js').start({
key: selfSignedCertificate.key,
cert: selfSignedCertificate.cert
});
return hang();
});
gulp.task('https-playground', gulp.series('build', 'https-playground-server'));
gulp.task('test-functional-testcafe-travis',
gulp.series('build',
gulpRunCommand([
'chmod +x ./test/functional/run-testcafe-functional-tests.sh',
'./test/functional/run-testcafe-functional-tests.sh'
])
)
);
gulp.task('travis', process.env.GULP_TASK ? gulp.series(process.env.GULP_TASK) : () => {});