forked from mapbox/mapbox-gl-js
-
Notifications
You must be signed in to change notification settings - Fork 0
/
vitest.config.base.js
122 lines (113 loc) · 3.19 KB
/
vitest.config.base.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
/* eslint-disable flowtype/require-valid-file-annotation */
import {readFile} from 'node:fs/promises';
import {fileURLToPath} from 'node:url';
import {join as pathJoin} from 'node:path';
import {defineConfig} from 'vite';
import {createFilter} from '@rollup/pluginutils';
import alias from '@rollup/plugin-alias';
import flowRemoveTypes from '@mapbox/flow-remove-types';
import arraybuffer from 'vite-plugin-arraybuffer';
const TYPING_DIRS = [
'3d-style',
'src'
];
// Borrowed from flow-esbuild-plugin
function flowEsbuildPlugin(regexp = /$^/) {
return {
name: 'flow',
setup(build) {
build.onLoad({filter: regexp}, async (args) => {
const source = await readFile(args.path, 'utf8');
let output = source;
if (source.slice(0, 200).includes('@flow')) {
output = flowRemoveTypes(source, {pretty: true});
}
return {
contents: output.toString(),
loader: 'jsx',
};
});
},
};
}
function flow() {
return {
enforce: 'pre',
name: 'flow-remove-types',
transform: (code) => ({
code: flowRemoveTypes(code).toString(),
map: null
})
};
}
function glsl(include) {
const filter = createFilter(include);
return {
name: 'glsl',
transform(code, id) {
if (!filter(id)) return;
return {
code: `export default ${JSON.stringify(code)};`,
map: {mappings: ''}
};
}
};
}
function fixAssertUtil(regexp = /node_modules\/assert/) {
return {
name: 'fix-assert-util',
setup(build) {
build.onLoad({filter: regexp}, async (args) => {
const source = await readFile(args.path, 'utf8');
return {
contents: source.replace(/util\/'/g, 'util\'').toString(),
loader: 'jsx',
};
});
},
};
}
export default defineConfig({
pool: 'threads',
poolOptions: {
threads: {
isolate: false,
useAtomics: true,
singleThread: true
}
},
test: {
testTimeout: 5_000,
browser: {
name: 'chromium',
provider: 'playwright',
enabled: true,
headless: true,
slowHijackESM: false,
fileParallelism: false,
},
restoreMocks: true,
unstubGlobals: true
},
optimizeDeps: {
esbuildOptions: {
plugins: [
flowEsbuildPlugin(new RegExp(`^${pathJoin(process.cwd(), `(${TYPING_DIRS.join('|')})/`)}.*\.js`)),
fixAssertUtil()
]
},
include: [
'assert'
]
},
plugins: [
flow(),
glsl(['./src/shaders/*.glsl', './3d-style/shaders/*.glsl']),
arraybuffer(),
alias({
entries: [
{find: 'tracked_parameters_proxy', replacement: fileURLToPath(new URL('src/tracked-parameters/internal/tracked_parameters_mock.js', import.meta.url))}
]
}),
],
});