/
index.d.ts
429 lines (429 loc) · 15.4 KB
/
index.d.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
import { PromiseWithSubtest, TapPlugin, TestBase, TestBaseOpts } from '@tapjs/core';
import * as Plugin_after from "@tapjs/after";
import * as Plugin_afterEach from "@tapjs/after-each";
import * as Plugin_asserts from "@tapjs/asserts";
import * as Plugin_before from "@tapjs/before";
import * as Plugin_beforeEach from "@tapjs/before-each";
import * as Plugin_filter from "@tapjs/filter";
import * as Plugin_fixture from "@tapjs/fixture";
import * as Plugin_intercept from "@tapjs/intercept";
import * as Plugin_mock from "@tapjs/mock";
import * as Plugin_nodeSerialize from "@tapjs/node-serialize";
import * as Plugin_snapshot from "@tapjs/snapshot";
import * as Plugin_spawn from "@tapjs/spawn";
import * as Plugin_stdin from "@tapjs/stdin";
import * as Plugin_typescript from "@tapjs/typescript";
import * as Plugin_worker from "@tapjs/worker";
import type { ConfigSet, Jack } from 'jackspeak';
/**
* The set of file extensions that the tap runner will load
* by default. Expaned into the `include` config values if they
* contain the token `__EXTENSIONS__`.
*
* If plugins export a `testFileExtensions` string array, then the
* entries will be added to this set.
*/
export declare const testFileExtensions: Set<string>;
/**
* Utility type to combine the array of plugins into a single combined
* return type.
*/
export type PluginResult<P extends ((t: TestBase, opts: any) => any)[]> = P extends [
infer H extends (t: TestBase, opts: any) => any,
...infer T extends ((t: TestBase, opts: any) => any)[]
] ? ReturnType<H> & PluginResult<T> : {};
/**
* Utility type to get the second parameter of a function, used to
* get the types of all plugin options.
*/
export type SecondParam<T extends [any] | [any, any]> = T extends [
any,
infer S
] ? S : unknown;
/**
* The union of the second parameters of all loaded plugin methods
*/
export type PluginOpts<P extends ((t: TestBase, opts: any) => any)[]> = P extends [
infer H extends (t: TestBase, opts: any) => any,
...infer T extends ((t: TestBase, opts: any) => any)[]
] ? SecondParam<Parameters<H>> & PluginOpts<T> : {};
/**
* Options that may be provided to `t.test()`. Extends
* {@link @tapjs/core!index.Extra}, {@link @tapjs/core!base.BaseOpts},
* {@link @tapjs/core!test-base.TestBaseOpts}, and the second argument to all
* plugin methods currently in use.
*/
export type TestOpts = TestBaseOpts & PluginOpts<PluginSet>;
/**
* Type that is the array of all plugin functions loaded
*/
export type PluginSet = [
typeof Plugin_after.plugin,
typeof Plugin_afterEach.plugin,
typeof Plugin_asserts.plugin,
typeof Plugin_before.plugin,
typeof Plugin_beforeEach.plugin,
typeof Plugin_filter.plugin,
typeof Plugin_fixture.plugin,
typeof Plugin_intercept.plugin,
typeof Plugin_mock.plugin,
typeof Plugin_nodeSerialize.plugin,
typeof Plugin_snapshot.plugin,
typeof Plugin_spawn.plugin,
typeof Plugin_stdin.plugin,
typeof Plugin_typescript.plugin,
typeof Plugin_worker.plugin
];
/**
* The combined configuration object generated by the `config`
* objects exported by plugins.
*/
export declare const execArgv: (values: ReturnType<ReturnType<typeof config>['parse']>['values']) => string[];
export declare const config: <C extends ConfigSet>(jack: Jack<C>) => Jack<C & import("jackspeak").ConfigSetFromMetaSet<"boolean", false, {
only: {
type: string;
short: string;
description: string;
nodeArgs: (v: boolean) => string[];
} & {
type: "boolean";
short?: string | undefined;
default?: boolean | undefined;
description?: string | undefined;
hint?: undefined;
validate?: ((v: any) => v is boolean) | undefined;
} & {
multiple?: false | undefined;
delim?: undefined;
};
}> & import("jackspeak").ConfigSetFromMetaSet<"string", true, {
grep: {
type: string;
multiple: boolean;
hint: string;
short: string;
description: string;
nodeArgs: (value: string[]) => string[];
} & {
type: "string";
short?: string | undefined;
default?: string[] | undefined;
description?: string | undefined;
hint?: string | undefined;
validate?: ((v: any) => v is string[]) | undefined;
} & {
multiple: true;
delim?: string | undefined;
};
}> & import("jackspeak").ConfigSetFromMetaSet<"boolean", false, {
invert: {
type: string;
short: string;
description: string;
} & {
type: "boolean";
short?: string | undefined;
default?: boolean | undefined;
description?: string | undefined;
hint?: undefined;
validate?: ((v: any) => v is boolean) | undefined;
} & {
multiple?: false | undefined;
delim?: undefined;
};
}> & import("jackspeak").ConfigSetFromMetaSet<"boolean", false, {
"no-invert": {
type: string;
short: string;
description: string;
} & {
type: "boolean";
short?: string | undefined;
default?: boolean | undefined;
description?: string | undefined;
hint?: undefined;
validate?: ((v: any) => v is boolean) | undefined;
} & {
multiple?: false | undefined;
delim?: undefined;
};
}> & import("jackspeak").ConfigSetFromMetaSet<"boolean", false, {
"filter-quietly": {
type: string;
description: string;
} & {
type: "boolean";
short?: string | undefined;
default?: boolean | undefined;
description?: string | undefined;
hint?: undefined;
validate?: ((v: any) => v is boolean) | undefined;
} & {
multiple?: false | undefined;
delim?: undefined;
};
}> & import("jackspeak").ConfigSetFromMetaSet<"boolean", false, {
"no-filter-quietly": {
type: string;
description: string;
} & {
type: "boolean";
short?: string | undefined;
default?: boolean | undefined;
description?: string | undefined;
hint?: undefined;
validate?: ((v: any) => v is boolean) | undefined;
} & {
multiple?: false | undefined;
delim?: undefined;
};
}> & import("jackspeak").ConfigSetFromMetaSet<"boolean", false, {
"save-fixture": {
type: string;
short: string;
description: string;
} & {
type: "boolean";
short?: string | undefined;
default?: boolean | undefined;
description?: string | undefined;
hint?: undefined;
validate?: ((v: any) => v is boolean) | undefined;
} & {
multiple?: false | undefined;
delim?: undefined;
};
}> & import("jackspeak").ConfigSetFromMetaSet<"boolean", false, {
snapshot: {
type: string;
short: string;
description: string;
} & {
type: "boolean";
short?: string | undefined;
default?: boolean | undefined;
description?: string | undefined;
hint?: undefined;
validate?: ((v: any) => v is boolean) | undefined;
} & {
multiple?: false | undefined;
delim?: undefined;
};
}> & import("jackspeak").ConfigSetFromMetaSet<"boolean", false, {
"snapshot-clean-cwd": {
type: string;
default: boolean;
description: string;
} & {
type: "boolean";
short?: string | undefined;
default?: boolean | undefined;
description?: string | undefined;
hint?: undefined;
validate?: ((v: any) => v is boolean) | undefined;
} & {
multiple?: false | undefined;
delim?: undefined;
};
}> & import("jackspeak").ConfigSetFromMetaSet<"boolean", false, {
"no-snapshot-clean-cwd": {
type: string;
description: string;
} & {
type: "boolean";
short?: string | undefined;
default?: boolean | undefined;
description?: string | undefined;
hint?: undefined;
validate?: ((v: any) => v is boolean) | undefined;
} & {
multiple?: false | undefined;
delim?: undefined;
};
}> & import("jackspeak").ConfigSetFromMetaSet<"boolean", false, {
typecheck: {
type: string;
description: string;
} & {
type: "boolean";
short?: string | undefined;
default?: boolean | undefined;
description?: string | undefined;
hint?: undefined;
validate?: ((v: any) => v is boolean) | undefined;
} & {
multiple?: false | undefined;
delim?: undefined;
};
}> & import("jackspeak").ConfigSetFromMetaSet<"string", false, {
tsconfig: {
type: string;
description: string;
} & {
type: "string";
short?: string | undefined;
default?: string | undefined;
description?: string | undefined;
hint?: string | undefined;
validate?: ((v: any) => v is string) | undefined;
} & {
multiple?: false | undefined;
delim?: undefined;
};
}>>;
/**
* The set of `loader` strings exported by plugins. If a plugin exports
* `preload = true`, then it will be sorted to the start of this list, so
* that Node loads it before other loaders.
*/
export declare const loaders: string[];
/**
* The set of `importLoader` strings exported by plugins, for use with
* `Module.register` in node v20.6 and higher.
*/
export declare const importLoaders: string[];
/**
* All `loader` strings exported by plugins, including fallbacks provided
* for those that also export an `importLoader`
*/
export declare const loaderFallbacks: string[];
/**
* The string signature that lists all loaded plugins alphabetically, used
* to determine whether a rebuild is necessary by comparing it to the `plugin`
* config value.
*/
export declare const signature = "@tapjs/after\n@tapjs/after-each\n@tapjs/asserts\n@tapjs/before\n@tapjs/before-each\n@tapjs/filter\n@tapjs/fixture\n@tapjs/intercept\n@tapjs/mock\n@tapjs/node-serialize\n@tapjs/snapshot\n@tapjs/spawn\n@tapjs/stdin\n@tapjs/typescript\n@tapjs/worker";
/**
* Union of {@link @tapjs/core!test-base.TestBase} plus all plugin
* return values
*/
export type TTest<P extends PluginSet = PluginSet> = TestBase & PluginResult<P>;
/**
* Interface that is the assembled result of every loaded plugin.
*
* This is extended into an interface because otherwise the code
* hinting is overwhelmingly extravagant.
*/
export interface BuiltPlugins extends PluginResult<PluginSet> {
}
declare const kPluginSet: unique symbol;
declare const kClass: unique symbol;
/**
* Option object used when extending the `Test` class via
* {@link @tapjs/test!index.Test.applyPlugin}
*
* @internal
*/
export type PluginExtensionOption<E extends BuiltPlugins = BuiltPlugins, O extends TestOpts = TestOpts> = {
[kPluginSet]: TapPlugin<any, O>[];
[kClass]?: typeof Test<E, O>;
};
/**
* interface defining the fully extended {@link @tapjs/test!index.Test} class.
*/
export interface Test<Ext extends BuiltPlugins = BuiltPlugins, Opts extends TestOpts = TestOpts> extends TTest {
/**
* Explicitly mark the test as completed, outputting the TAP plan line if
* needed.
*
* This is not required to be called if the test function returns a promise,
* or if a plan is explicitly declared and eventually fulfilled.
*
* @group Test Lifecycle Management
*/
end(): this;
/**
* Specify the number of Test Points expected by this test.
* Outputs a TAP plan line.
*
* @group Test Lifecycle Management
*/
plan(n: number, comment?: string): void;
}
/**
* This is the class that is extended for the root {@link @tapjs/core!tap.TAP}
* test, and used to instantiate test objects in its child tests. It extends
* {@link @tapjs/core!test-base.TestBase}, and implements the union of return
* values of all loaded plugins via a Proxy.
*/
export declare class Test<Ext extends BuiltPlugins = BuiltPlugins, Opts extends TestOpts = TestOpts> extends TestBase implements TTest {
#private;
/**
* @param opts Test options for this instance
*
* @param __INTERNAL Extension option used by the subclasses created in
* {@link @tapjs/test!index.Test#applyPlugin}.
*
* @internal
*/
constructor(opts: Opts, __INTERNAL?: PluginExtensionOption<Ext, Opts>);
/**
* The string signature of the plugins built into this Test class
*/
get pluginSignature(): string;
/**
* Add a plugin at run-time.
*
* Creates a subclass of {@link @tapjs/test!index.Test} which has the
* specified plugin, and which applies the plugin to all child tests it
* creates.
*
* Typically, it's best to load plugins using configuration, set via the
* `tap plugin <add|rm>` command.
*
* However, in some cases, for example while developing plugins or if a
* certain plugin is only needed in a small number of tests, it can be
* useful to apply it after the fact.
*
* This is best used sparingly, as it may result in poor typescript
* compilation performance, which can manifest in slower test start-up times
* and lag loading autocomplete in editors. If you find yourself calling
* applyPlugin often, consider whether it'd be better to just add the plugin
* to the entire test suite, so that it can be built up front.
*
* @group Plugin Management
*/
applyPlugin<B extends Object, O extends unknown = unknown>(plugin: TapPlugin<B, O>): Test<Ext & B, Opts & O> & Ext & B;
/**
* Return true if the specified plugin is loaded. Asserts that the
* test object in question implements the return value of the plugin.
*
* @group Plugin Management
*/
pluginLoaded<T extends any = any>(plugin: (t: any, opts?: any) => T): this is TestBase & T;
/**
* Return the set of plugins loaded by this Test
*
* @group Plugin Management
*/
get plugins(): TapPlugin<any, Opts>[];
/**
* Create a child Test object and parse its output as a subtest
*
* @group Subtest Methods
*/
test(name: string, extra: Opts, cb: (t: Test<Ext, Opts> & Ext) => any): PromiseWithSubtest<Test<Ext, Opts> & Ext>;
test(name: string, cb: (t: Test<Ext, Opts> & Ext) => any): PromiseWithSubtest<Test<Ext, Opts> & Ext>;
test(extra: Opts, cb: (t: Test<Ext, Opts> & Ext) => any): PromiseWithSubtest<Test<Ext, Opts> & Ext>;
test(cb: (t: Test<Ext, Opts> & Ext) => any): PromiseWithSubtest<Test<Ext, Opts> & Ext>;
/**
* Create a subtest which is marked as `todo`
*
* @group Subtest Methods
*/
todo(name: string, extra: Opts, cb: (t: Test<Ext, Opts> & Ext) => any): PromiseWithSubtest<Test<Ext, Opts> & Ext>;
todo(name: string, cb: (t: Test<Ext, Opts> & Ext) => any): PromiseWithSubtest<Test<Ext, Opts> & Ext>;
todo(extra: Opts, cb: (t: Test<Ext, Opts> & Ext) => any): PromiseWithSubtest<Test<Ext, Opts> & Ext>;
todo(cb: (t: Test<Ext, Opts> & Ext) => any): PromiseWithSubtest<Test<Ext, Opts> & Ext>;
/**
* Create a subtest which is marked as `skip`
*
* @group Subtest Methods
*/
skip(name: string, extra: Opts, cb: (t: Test<Ext, Opts> & Ext) => any): PromiseWithSubtest<Test<Ext, Opts> & Ext>;
skip(name: string, cb: (t: Test<Ext, Opts> & Ext) => any): PromiseWithSubtest<Test<Ext, Opts> & Ext>;
skip(extra: Opts, cb: (t: Test<Ext, Opts> & Ext) => any): PromiseWithSubtest<Test<Ext, Opts> & Ext>;
skip(cb: (t: Test<Ext, Opts> & Ext) => any): PromiseWithSubtest<Test<Ext, Opts> & Ext>;
}
export {};
//# sourceMappingURL=index.d.ts.map