-
-
Notifications
You must be signed in to change notification settings - Fork 6.4k
/
raw-types.ts
355 lines (337 loc) · 11.5 KB
/
raw-types.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
/**
* Copyright (c) Meta Platforms, Inc. and affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
/* eslint-disable sort-keys */
import {type Static, Type} from '@sinclair/typebox';
export const RawSnapshotFormat = Type.Partial(
Type.Object({
callToJSON: Type.Boolean(),
compareKeys: Type.Null(),
escapeRegex: Type.Boolean(),
escapeString: Type.Boolean(),
highlight: Type.Boolean(),
indent: Type.Integer({minimum: 0}),
maxDepth: Type.Integer({minimum: 0}),
maxWidth: Type.Integer({minimum: 0}),
min: Type.Boolean(),
printBasicPrototype: Type.Boolean(),
printFunctionName: Type.Boolean(),
theme: Type.Partial(
Type.Object({
comment: Type.String(),
content: Type.String(),
prop: Type.String(),
tag: Type.String(),
value: Type.String(),
}),
),
}),
);
const RawCoverageProvider = Type.Union([
Type.Literal('babel'),
Type.Literal('v8'),
]);
const RawCoverageThresholdValue = Type.Partial(
Type.Object({
branches: Type.Number({minimum: 0, maximum: 100}),
functions: Type.Number({minimum: 0, maximum: 100}),
lines: Type.Number({minimum: 0, maximum: 100}),
statements: Type.Number({minimum: 0, maximum: 100}),
}),
);
const RawCoverageThresholdBase = Type.Object(
{global: RawCoverageThresholdValue},
{additionalProperties: RawCoverageThresholdValue},
);
const RawCoverageThreshold = Type.Unsafe<{
global: Static<typeof RawCoverageThresholdValue>;
[path: string]: Static<typeof RawCoverageThresholdValue>;
}>(RawCoverageThresholdBase);
// TODO: add type test that these are all the colors available in chalk.ForegroundColor
export const ChalkForegroundColors = Type.Union([
Type.Literal('black'),
Type.Literal('red'),
Type.Literal('green'),
Type.Literal('yellow'),
Type.Literal('blue'),
Type.Literal('magenta'),
Type.Literal('cyan'),
Type.Literal('white'),
Type.Literal('gray'),
Type.Literal('grey'),
Type.Literal('blackBright'),
Type.Literal('redBright'),
Type.Literal('greenBright'),
Type.Literal('yellowBright'),
Type.Literal('blueBright'),
Type.Literal('magentaBright'),
Type.Literal('cyanBright'),
Type.Literal('whiteBright'),
]);
const RawDisplayName = Type.Object({
name: Type.String(),
color: ChalkForegroundColors,
});
// TODO: verify these are the names of istanbulReport.ReportOptions
export const RawCoverageReporterNames = Type.Union([
Type.Literal('clover'),
Type.Literal('cobertura'),
Type.Literal('html-spa'),
Type.Literal('html'),
Type.Literal('json'),
Type.Literal('json-summary'),
Type.Literal('lcov'),
Type.Literal('lcovonly'),
Type.Literal('none'),
Type.Literal('teamcity'),
Type.Literal('text'),
Type.Literal('text-lcov'),
Type.Literal('text-summary'),
]);
const RawCoverageReporters = Type.Array(
Type.Union([
RawCoverageReporterNames,
Type.Tuple([
RawCoverageReporterNames,
Type.Record(Type.String(), Type.Unknown()),
]),
]),
);
const RawGlobalFakeTimersConfig = Type.Partial(
Type.Object({
enableGlobally: Type.Boolean({
description:
'Whether fake timers should be enabled globally for all test files.',
default: false,
}),
}),
);
const RawFakeableAPI = Type.Union([
Type.Literal('Date'),
Type.Literal('hrtime'),
Type.Literal('nextTick'),
Type.Literal('performance'),
Type.Literal('queueMicrotask'),
Type.Literal('requestAnimationFrame'),
Type.Literal('cancelAnimationFrame'),
Type.Literal('requestIdleCallback'),
Type.Literal('cancelIdleCallback'),
Type.Literal('setImmediate'),
Type.Literal('clearImmediate'),
Type.Literal('setInterval'),
Type.Literal('clearInterval'),
Type.Literal('setTimeout'),
Type.Literal('clearTimeout'),
]);
const RawFakeTimersConfig = Type.Partial(
Type.Object({
advanceTimers: Type.Union([Type.Boolean(), Type.Number({minimum: 0})], {
description:
'If set to `true` all timers will be advanced automatically by 20 milliseconds every 20 milliseconds. A custom ' +
'time delta may be provided by passing a number.',
default: false,
}),
doNotFake: Type.Array(RawFakeableAPI, {
description:
'List of names of APIs (e.g. `Date`, `nextTick()`, `setImmediate()`, `setTimeout()`) that should not be faked.' +
'\n\nThe default is `[]`, meaning all APIs are faked.',
default: [],
}),
now: Type.Integer({
minimum: 0,
description:
'Sets current system time to be used by fake timers.\n\nThe default is `Date.now()`.',
}),
timerLimit: Type.Number({
description:
'The maximum number of recursive timers that will be run when calling `jest.runAllTimers()`.',
default: 100_000,
minimum: 0,
}),
legacyFakeTimers: Type.Literal(false, {
description:
'Use the old fake timers implementation instead of one backed by `@sinonjs/fake-timers`.',
default: false,
}),
}),
);
const RawLegacyFakeTimersConfig = Type.Partial(
Type.Object({
legacyFakeTimers: Type.Literal(true, {
description:
'Use the old fake timers implementation instead of one backed by `@sinonjs/fake-timers`.',
default: true,
}),
}),
);
export const RawFakeTimers = Type.Intersect([
RawGlobalFakeTimersConfig,
Type.Union([RawFakeTimersConfig, RawLegacyFakeTimersConfig]),
]);
const RawHasteConfig = Type.Partial(
Type.Object({
computeSha1: Type.Boolean({
description: 'Whether to hash files using SHA-1.',
}),
defaultPlatform: Type.Union([Type.String(), Type.Null()], {
description: 'The platform to use as the default, e.g. `ios`.',
}),
forceNodeFilesystemAPI: Type.Boolean({
description:
"Whether to force the use of Node's `fs` API when reading files rather than shelling out to `find`.",
}),
enableSymlinks: Type.Boolean({
description:
'Whether to follow symlinks when crawling for files.' +
'\n\tThis options cannot be used in projects which use watchman.' +
'\n\tProjects with `watchman` set to true will error if this option is set to true.',
}),
hasteImplModulePath: Type.String({
description: 'Path to a custom implementation of Haste.',
}),
platforms: Type.Array(Type.String(), {
description: "All platforms to target, e.g ['ios', 'android'].",
}),
throwOnModuleCollision: Type.Boolean({
description: 'Whether to throw on error on module collision.',
}),
hasteMapModulePath: Type.String({
description: 'Custom HasteMap module',
}),
retainAllFiles: Type.Boolean({
description:
'Whether to retain all files, allowing e.g. search for tests in `node_modules`.',
}),
}),
);
export const RawInitialOptions = Type.Partial(
Type.Object({
automock: Type.Boolean(),
bail: Type.Union([Type.Boolean(), Type.Number()]),
cache: Type.Boolean(),
cacheDirectory: Type.String(),
ci: Type.Boolean(),
clearMocks: Type.Boolean(),
changedFilesWithAncestor: Type.Boolean(),
changedSince: Type.String(),
collectCoverage: Type.Boolean(),
collectCoverageFrom: Type.Array(Type.String()),
coverageDirectory: Type.String(),
coveragePathIgnorePatterns: Type.Array(Type.String()),
coverageProvider: RawCoverageProvider,
coverageReporters: RawCoverageReporters,
coverageThreshold: RawCoverageThreshold,
dependencyExtractor: Type.String(),
detectLeaks: Type.Boolean(),
detectOpenHandles: Type.Boolean(),
displayName: Type.Union([Type.String(), RawDisplayName]),
expand: Type.Boolean(),
extensionsToTreatAsEsm: Type.Array(Type.String()),
fakeTimers: RawFakeTimers,
filter: Type.String(),
findRelatedTests: Type.Boolean(),
forceCoverageMatch: Type.Array(Type.String()),
forceExit: Type.Boolean(),
json: Type.Boolean(),
globals: Type.Record(Type.String(), Type.Unknown()),
globalSetup: Type.Union([Type.String(), Type.Null()]),
globalTeardown: Type.Union([Type.String(), Type.Null()]),
haste: RawHasteConfig,
id: Type.String(),
injectGlobals: Type.Boolean(),
reporters: Type.Array(
Type.Union([
Type.String(),
Type.Tuple([Type.String(), Type.Record(Type.String(), Type.Unknown())]),
]),
),
logHeapUsage: Type.Boolean(),
lastCommit: Type.Boolean(),
listTests: Type.Boolean(),
maxConcurrency: Type.Integer(),
maxWorkers: Type.Union([Type.String(), Type.Integer()]),
moduleDirectories: Type.Array(Type.String()),
moduleFileExtensions: Type.Array(Type.String()),
moduleNameMapper: Type.Record(
Type.String(),
Type.Union([Type.String(), Type.Array(Type.String())]),
),
modulePathIgnorePatterns: Type.Array(Type.String()),
modulePaths: Type.Array(Type.String()),
noStackTrace: Type.Boolean(),
notify: Type.Boolean(),
notifyMode: Type.String(),
onlyChanged: Type.Boolean(),
onlyFailures: Type.Boolean(),
openHandlesTimeout: Type.Number(),
outputFile: Type.String(),
passWithNoTests: Type.Boolean(),
preset: Type.Union([Type.String(), Type.Null()]),
preserveLoadOrder: Type.Boolean(),
prettierPath: Type.Union([Type.String(), Type.Null()]),
projects: Type.Array(
Type.Union([
Type.String(),
// TODO: Make sure to type these correctly
Type.Record(Type.String(), Type.Unknown()),
]),
),
randomize: Type.Boolean(),
replname: Type.Union([Type.String(), Type.Null()]),
resetMocks: Type.Boolean(),
resetModules: Type.Boolean(),
resolver: Type.Union([Type.String(), Type.Null()]),
restoreMocks: Type.Boolean(),
rootDir: Type.String(),
roots: Type.Array(Type.String()),
runner: Type.String(),
runTestsByPath: Type.Boolean(),
runtime: Type.String(),
sandboxInjectedGlobals: Type.Array(Type.String()),
setupFiles: Type.Array(Type.String()),
setupFilesAfterEnv: Type.Array(Type.String()),
showSeed: Type.Boolean(),
silent: Type.Boolean(),
skipFilter: Type.Boolean(),
skipNodeResolution: Type.Boolean(),
slowTestThreshold: Type.Number(),
snapshotResolver: Type.String(),
snapshotSerializers: Type.Array(Type.String()),
snapshotFormat: RawSnapshotFormat,
errorOnDeprecated: Type.Boolean(),
testEnvironment: Type.String(),
testEnvironmentOptions: Type.Record(Type.String(), Type.Unknown()),
testFailureExitCode: Type.Union([Type.String(), Type.Integer()]),
testLocationInResults: Type.Boolean(),
testMatch: Type.Array(Type.String()),
testNamePattern: Type.String(),
testPathIgnorePatterns: Type.Array(Type.String()),
testRegex: Type.Union([Type.String(), Type.Array(Type.String())]),
testResultsProcessor: Type.String(),
testRunner: Type.String(),
testSequencer: Type.String(),
testTimeout: Type.Number(),
transform: Type.Record(
Type.String(),
Type.Union([Type.String(), Type.Tuple([Type.String(), Type.Unknown()])]),
),
transformIgnorePatterns: Type.Array(Type.String()),
watchPathIgnorePatterns: Type.Array(Type.String()),
unmockedModulePathPatterns: Type.Array(Type.String()),
updateSnapshot: Type.Boolean(),
useStderr: Type.Boolean(),
verbose: Type.Boolean(),
waitNextEventLoopTurnForUnhandledRejectionEvents: Type.Boolean(),
watch: Type.Boolean(),
watchAll: Type.Boolean(),
watchman: Type.Boolean(),
watchPlugins: Type.Array(
Type.Union([Type.String(), Type.Tuple([Type.String(), Type.Unknown()])]),
),
workerIdleMemoryLimit: Type.Union([Type.Number(), Type.String()]),
workerThreads: Type.Boolean(),
}),
);