forked from vitest-dev/vitest
-
Notifications
You must be signed in to change notification settings - Fork 0
/
config.ts
330 lines (280 loc) · 6.32 KB
/
config.ts
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
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
import type { CommonServerOptions } from 'vite'
import type { PrettyFormatOptions } from 'pretty-format'
import type { BuiltinReporters } from '../node/reporters'
import type { C8Options, ResolvedC8Options } from './coverage'
import type { JSDOMOptions } from './jsdom-options'
import type { Reporter } from './reporter'
import type { SnapshotStateOptions } from './snapshot'
import type { Arrayable } from './general'
export type BuiltinEnvironment = 'node' | 'jsdom' | 'happy-dom'
export type ApiConfig = Pick<CommonServerOptions, 'port' | 'strictPort' | 'host'>
export { JSDOMOptions }
export interface EnvironmentOptions {
/**
* jsdom options.
*/
jsdom?: JSDOMOptions
}
export interface InlineConfig {
/**
* Include globs for test files
*
* @default ['**\/*.{test,spec}.{js,mjs,cjs,ts,mts,cts,jsx,tsx}']
*/
include?: string[]
/**
* Exclude globs for test files
* @default ['node_modules', 'dist', '.idea', '.git', '.cache']
*/
exclude?: string[]
/**
* Handling for dependencies inlining or externalizing
*/
deps?: {
/**
* Externalize means that Vite will bypass the package to native Node.
*
* Externalized dependencies will not be applied Vite's transformers and resolvers.
* And does not support HMR on reload.
*
* Typically, packages under `node_modules` are externalized.
*/
external?: (string | RegExp)[]
/**
* Vite will process inlined modules.
*
* This could be helpful to handle packages that ship `.js` in ESM format (that Node can't handle).
*/
inline?: (string | RegExp)[]
/**
* Interpret CJS module's default as named exports
*
* @default true
*/
interopDefault?: boolean
/**
* When a dependency is a valid ESM package, try to guess the cjs version based on the path.
* This will significantly improve the performance in huge repo, but might potentially
* cause some misalignment if a package have different logic in ESM and CJS mode.
*
* @default true
*/
fallbackCJS?: boolean
}
/**
* Register apis globally
*
* @default false
*/
globals?: boolean
/**
* @deprecated
*/
global?: boolean
/**
* Running environment
*
* Supports 'node', 'jsdom', 'happy-dom'
*
* @default 'node'
*/
environment?: BuiltinEnvironment
/**
* Environment options.
*/
environmentOptions?: EnvironmentOptions
/**
* Update snapshot
*
* @default false
*/
update?: boolean
/**
* Watch mode
*
* @default true
*/
watch?: boolean
/**
* Project root
*
* @default process.cwd()
*/
root?: string
/**
* Custom reporter for output
*/
reporters?: Arrayable<BuiltinReporters | Reporter>
/**
* Write test results to a file when the --reporter=json option is also specified
*/
outputFile?: string
/**
* Enable multi-threading
*
* @default true
*/
threads?: boolean
/**
* Maximum number of threads
*
* @default available CPUs
*/
maxThreads?: number
/**
* Minimum number of threads
*
* @default available CPUs
*/
minThreads?: number
/**
* Default timeout of a test in milliseconds
*
* @default 5000
*/
testTimeout?: number
/**
* Default timeout of a hook in milliseconds
*
* @default 10000
*/
hookTimeout?: number
/**
* Silent mode
*
* @default false
*/
silent?: boolean
/**
* Path to setup files
*/
setupFiles?: string | string[]
/**
* Path to global setup files
*/
globalSetup?: string | string[]
/**
* Pattern of file paths to be ignore from triggering watch rerun
*
* @default ['**\/node_modules\/**', '**\/dist/**']
*/
watchIgnore?: (string | RegExp)[]
/**
* Isolate environment for each test file
*
* @default true
*/
isolate?: boolean
/**
* Coverage options
*/
coverage?: C8Options
/**
* run test names with the specified pattern
*/
testNamePattern?: string | RegExp
/**
* Will call `.mockClear()` on all spies before each test
* @default false
*/
clearMocks?: boolean
/**
* Will call `.mockReset()` on all spies before each test
* @default false
*/
mockReset?: boolean
/**
* Will call `.mockRestore()` on all spies before each test
* @default false
*/
restoreMocks?: boolean
/**
* Serve API options.
*
* When set to true, the default port is 51204.
*
* @default false
*/
api?: boolean | number | ApiConfig
/**
* Enable Vitest UI
* @internal WIP
*/
ui?: boolean
/**
* Open UI automatically.
*
* @default true
*/
open?: boolean
/**
* Base url for the UI
*
* @default '/__vitest__/'
*/
uiBase?: string
/**
* Determine the transform method of modules
*/
transformMode?: {
/**
* Use SSR transform pipeline for the specified files.
* Vite plugins will receive `ssr: true` flag when processing those files.
*
* @default [/\.([cm]?[jt]sx?|json)$/]
*/
ssr?: RegExp[]
/**
* First do a normal transform pipeline (targeting browser),
* then then do a SSR rewrite to run the code in Node.
* Vite plugins will receive `ssr: false` flag when processing those files.
*
* @default other than `ssr`
*/
web?: RegExp[]
}
/**
* Format options for snapshot testing.
*/
snapshotFormat?: PrettyFormatOptions
}
export interface UserConfig extends InlineConfig {
/**
* Path to the config file.
*
* Default resolving to one of:
* - `vitest.config.js`
* - `vitest.config.ts`
* - `vite.config.js`
* - `vite.config.ts`
*/
config?: string | undefined
/**
* Use happy-dom
*/
dom?: boolean
/**
* Pass with no tests
*/
passWithNoTests?: boolean
/**
* Allow tests and suites that are marked as only
*/
allowOnly?: boolean
/**
* Run tests that cover a list of source files
*/
related?: string[] | string
}
export interface ResolvedConfig extends Omit<Required<UserConfig>, 'config' | 'filters' | 'coverage' | 'testNamePattern' | 'related' | 'api' | 'reporters'> {
base?: string
config?: string
filters?: string[]
testNamePattern?: RegExp
related?: string[]
coverage: ResolvedC8Options
snapshotOptions: SnapshotStateOptions
reporters: (Reporter | BuiltinReporters)[]
api?: ApiConfig
define?: Record<string, any>
}