/
config.ts
430 lines (367 loc) · 8.83 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
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
import type { CommonServerOptions } from 'vite'
import type { PrettyFormatOptions } from 'pretty-format'
import type { FakeTimerInstallOpts } from '@sinonjs/fake-timers'
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[]
/**
* Include globs for in-source test files
*
* @default []
*/
includeSource?: 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).
*
* If `true`, every dependency will be inlined
*/
inline?: (string | RegExp)[] | true
/**
* 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 false
*/
fallbackCJS?: boolean
}
/**
* Base directory to scan for the test files
*
* @default `config.root`
*/
dir?: string
/**
* Register apis globally
*
* @default false
*/
globals?: 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. Can contain one or more built-in report names, reporter instances,
* and/or paths to custom reporters
*/
reporters?: Arrayable<BuiltinReporters | Reporter | Omit<string, BuiltinReporters>>
/**
* diff output length
*/
outputTruncateLength?: number
/**
* number of diff output lines
*/
outputDiffLines?: number
/**
* Write test results to a file when the --reporter=json` or `--reporter=junit` option is also specified.
* Also definable individually per reporter by using an object instead.
*/
outputFile?: string | (Partial<Record<BuiltinReporters, string>> & Record<string, 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[]
/**
* Glob pattern of file paths to be ignore from triggering watch rerun
*/
watchExclude?: string[]
/**
* Glob patter of file paths that will trigger the whole suite rerun
*
* Useful if you are testing calling CLI commands
*
* @default []
*/
forceRerunTriggers?: string[]
/**
* 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
/**
* Resolve custom snapshot path
*/
resolveSnapshotPath?: (path: string, extension: string) => string
/**
* Pass with no tests
*/
passWithNoTests?: boolean
/**
* Allow tests and suites that are marked as only
*/
allowOnly?: boolean
/**
* Show heap usage after each test. Usefull for debugging memory leaks.
*/
logHeapUsage?: boolean
/**
* Custom environment variables assigned to `process.env` before running tests.
*/
env?: Record<string, string>
/**
* Options for @sinon/fake-timers
*/
fakeTimers?: FakeTimerInstallOpts
/**
* Custom handler for console.log in tests.
*
* Return `false` to ignore the log.
*/
onConsoleLog?: (log: string, type: 'stdout' | 'stderr') => false | void
/**
* Indicates if CSS files should be processed.
*
* When excluded, the CSS files will be replaced with empty strings to bypass the subsequent processing.
*
* @default { include: [/\.module\./] }
*/
css?: boolean | {
include?: RegExp | RegExp[]
exclude?: RegExp | RegExp[]
}
/**
* A number of tests that are allowed to run at the same time marked with `test.concurrent`.
* @default 5
*/
maxConcurrency?: number
}
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
/**
* Run tests that cover a list of source files
*/
related?: string[] | string
/**
* Overrides Vite mode
* @default 'test'
*/
mode?: string
/**
* Runs tests that are affected by the changes in the repository, or between specified branch or commit hash
* Requires initialized git repository
* @default false
*/
changed?: boolean | string
/**
* Test suite shard to execute in a format of <index>/<count>.
* Will divide tests into a `count` numbers, and run only the `indexed` part.
* Cannot be used with enabled watch.
* @example --shard=2/3
*/
shard?: string
}
export interface ResolvedConfig extends Omit<Required<UserConfig>, 'config' | 'filters' | 'coverage' | 'testNamePattern' | 'related' | 'api' | 'reporters' | 'resolveSnapshotPath' | 'shard'> {
base?: string
config?: string
filters?: string[]
testNamePattern?: RegExp
related?: string[]
coverage: ResolvedC8Options
snapshotOptions: SnapshotStateOptions
reporters: (Reporter | BuiltinReporters)[]
defines: Record<string, any>
api?: ApiConfig
shard?: {
index: number
count: number
}
}