-
Notifications
You must be signed in to change notification settings - Fork 43
/
Gulpfile.js
110 lines (86 loc) · 3.09 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
const createTestCafe = require('testcafe');
const del = require('del');
const eslint = require('gulp-eslint-new');
const fs = require('fs');
const glob = require('glob');
const gulp = require('gulp');
const mustache = require('gulp-mustache');
const pathJoin = require('path').join;
const rename = require('gulp-rename');
const startTestServer = require('./test/server');
const { promisify } = require('util');
const nextBuild = require('next/dist/build').default;
const { createServer } = require('vite');
const listFiles = promisify(glob);
const deleteFiles = promisify(del);
let devServer = null;
gulp.task('clean', () => {
return deleteFiles([
'lib',
'test/data/lib'
]);
});
gulp.task('lint', () => {
return gulp
.src([
'src/**/*.js',
'test/**/*.js',
'!test/data/**',
'Gulpfile.js'
])
.pipe(eslint())
.pipe(eslint.format())
.pipe(eslint.failAfterError());
});
gulp.task('build-selectors-script', () => {
function loadModule (modulePath) {
return fs.readFileSync(modulePath).toString();
}
return gulp.src('./src/index.js.mustache')
.pipe(mustache({
getRootElsReact15: loadModule('./src/react-15/get-root-els.js'),
getRootElsReact16to18: loadModule('./src/react-16-18/get-root-els.js'),
selectorReact15: loadModule('./src/react-15/index.js'),
selectorReact16to18: loadModule('./src/react-16-18/index.js'),
react15Utils: loadModule('./src/react-15/react-utils.js'),
react16to18Utils: loadModule('./src/react-16-18/react-utils.js'),
waitForReact: loadModule('./src/wait-for-react.js')
}))
.pipe(rename('index.js'))
.pipe(gulp.dest('lib'));
});
gulp.task('clean-build-tmp-resources', () => {
return deleteFiles(['lib/tmp']);
});
gulp.task('build-nextjs-app', () => {
const appPath = pathJoin(__dirname, './test/data/server-render');
return nextBuild(appPath, require('./next.config.js'));
});
gulp.task('build', gulp.series('clean', 'lint', 'build-selectors-script', 'clean-build-tmp-resources'));
gulp.task('start-dev-server', async () => {
const src = 'test/data/app';
devServer = await createServer({
configFile: false,
root: src,
server: {
port: 3000
}
});
await devServer.listen();
});
gulp.task('run-tests', async cb => {
const files = await listFiles('test/fixtures/**/*.{js,ts}');
await startTestServer();
const testCafe = await createTestCafe('localhost', 1337, 1338);
await testCafe.createRunner()
.src(files)
.browsers(['chrome', 'firefox', 'edge'])
.reporter('list')
.run({ quarantineMode: true, debugOnFail: false })
.then(failed => {
devServer.close();
cb();
process.exit(failed);
});
});
gulp.task('test', gulp.series('build', 'start-dev-server', 'build-nextjs-app', 'run-tests'));