ava 4.0.0-alpha.1 → 4.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/entrypoints/cli.mjs +4 -0
- package/{eslint-plugin-helper.js → entrypoints/eslint-plugin-helper.cjs} +20 -7
- package/entrypoints/main.cjs +2 -0
- package/entrypoints/main.mjs +1 -0
- package/entrypoints/plugin.cjs +2 -0
- package/entrypoints/plugin.mjs +4 -0
- package/index.d.ts +6 -709
- package/lib/api.js +95 -46
- package/lib/assert.js +122 -173
- package/lib/chalk.js +9 -14
- package/lib/cli.js +105 -97
- package/lib/code-excerpt.js +12 -17
- package/lib/concordance-options.js +30 -31
- package/lib/context-ref.js +3 -6
- package/lib/create-chain.js +32 -4
- package/lib/environment-variables.js +1 -4
- package/lib/eslint-plugin-helper-worker.js +16 -26
- package/lib/extensions.js +2 -2
- package/lib/fork.js +42 -83
- package/lib/glob-helpers.cjs +140 -0
- package/lib/globs.js +136 -163
- package/lib/{ipc-flow-control.js → ipc-flow-control.cjs} +1 -0
- package/lib/is-ci.js +4 -2
- package/lib/like-selector.js +7 -13
- package/lib/line-numbers.js +10 -17
- package/lib/load-config.js +62 -56
- package/lib/module-types.js +3 -3
- package/lib/node-arguments.js +4 -5
- package/lib/{now-and-timers.js → now-and-timers.cjs} +0 -0
- package/lib/parse-test-args.js +22 -11
- package/lib/pkg.cjs +2 -0
- package/lib/plugin-support/shared-worker-loader.js +45 -48
- package/lib/plugin-support/shared-workers.js +24 -43
- package/lib/provider-manager.js +20 -14
- package/lib/reporters/beautify-stack.js +6 -11
- package/lib/reporters/colors.js +40 -15
- package/lib/reporters/default.js +115 -350
- package/lib/reporters/format-serialized-error.js +7 -18
- package/lib/reporters/improper-usage-messages.js +8 -9
- package/lib/reporters/prefix-title.js +17 -15
- package/lib/reporters/tap.js +15 -16
- package/lib/run-status.js +25 -23
- package/lib/runner.js +138 -127
- package/lib/scheduler.js +42 -36
- package/lib/serialize-error.js +34 -34
- package/lib/snapshot-manager.js +83 -76
- package/lib/test.js +114 -195
- package/lib/watcher.js +65 -40
- package/lib/worker/base.js +48 -99
- package/lib/worker/channel.cjs +290 -0
- package/lib/worker/dependency-tracker.js +22 -22
- package/lib/worker/guard-environment.cjs +19 -0
- package/lib/worker/line-numbers.js +57 -19
- package/lib/worker/main.cjs +12 -0
- package/lib/worker/{options.js → options.cjs} +0 -0
- package/lib/worker/{plugin.js → plugin.cjs} +31 -16
- package/lib/worker/state.cjs +5 -0
- package/lib/worker/{utils.js → utils.cjs} +1 -1
- package/package.json +60 -68
- package/plugin.d.ts +51 -53
- package/readme.md +5 -12
- package/types/assertions.d.ts +327 -0
- package/types/subscribable.ts +6 -0
- package/types/test-fn.d.ts +231 -0
- package/types/try-fn.d.ts +58 -0
- package/cli.js +0 -11
- package/index.js +0 -8
- package/lib/worker/channel.js +0 -218
- package/lib/worker/main.js +0 -20
- package/plugin.js +0 -9
package/index.d.ts
CHANGED
|
@@ -1,715 +1,12 @@
|
|
|
1
|
-
|
|
2
|
-
subscribe(observer: {
|
|
3
|
-
error(error: any): void;
|
|
4
|
-
complete(): void;
|
|
5
|
-
}): void;
|
|
6
|
-
}
|
|
1
|
+
import type {TestFn} from './types/test-fn';
|
|
7
2
|
|
|
8
|
-
export
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
export
|
|
12
|
-
/** The thrown error must have a code that equals the given string or number. */
|
|
13
|
-
code?: string | number;
|
|
14
|
-
|
|
15
|
-
/** The thrown error must be an instance of this constructor. */
|
|
16
|
-
instanceOf?: Constructor;
|
|
17
|
-
|
|
18
|
-
/** The thrown error must be strictly equal to this value. */
|
|
19
|
-
is?: Error;
|
|
20
|
-
|
|
21
|
-
/** The thrown error must have a message that equals the given string, or matches the regular expression. */
|
|
22
|
-
message?: string | RegExp;
|
|
23
|
-
|
|
24
|
-
/** The thrown error must have a name that equals the given string. */
|
|
25
|
-
name?: string;
|
|
26
|
-
};
|
|
27
|
-
|
|
28
|
-
export type CommitDiscardOptions = {
|
|
29
|
-
/**
|
|
30
|
-
* Whether the logs should be included in those of the parent test.
|
|
31
|
-
*/
|
|
32
|
-
retainLogs?: boolean;
|
|
33
|
-
};
|
|
34
|
-
|
|
35
|
-
export interface Assertions {
|
|
36
|
-
/**
|
|
37
|
-
* Assert that `actual` is [truthy](https://developer.mozilla.org/en-US/docs/Glossary/Truthy), returning a boolean
|
|
38
|
-
* indicating whether the assertion passed. Comes with power-assert.
|
|
39
|
-
*/
|
|
40
|
-
assert: AssertAssertion;
|
|
41
|
-
|
|
42
|
-
/**
|
|
43
|
-
* Assert that `actual` is [deeply equal](https://github.com/concordancejs/concordance#comparison-details) to
|
|
44
|
-
* `expected`, returning a boolean indicating whether the assertion passed.
|
|
45
|
-
*/
|
|
46
|
-
deepEqual: DeepEqualAssertion;
|
|
47
|
-
|
|
48
|
-
/**
|
|
49
|
-
* Assert that `value` is like `selector`, returning a boolean indicating whether the assertion passed.
|
|
50
|
-
*/
|
|
51
|
-
like: LikeAssertion;
|
|
52
|
-
|
|
53
|
-
/** Fail the test, always returning `false`. */
|
|
54
|
-
fail: FailAssertion;
|
|
55
|
-
|
|
56
|
-
/**
|
|
57
|
-
* Assert that `actual` is strictly false, returning a boolean indicating whether the assertion passed.
|
|
58
|
-
*/
|
|
59
|
-
false: FalseAssertion;
|
|
60
|
-
|
|
61
|
-
/**
|
|
62
|
-
* Assert that `actual` is [falsy](https://developer.mozilla.org/en-US/docs/Glossary/Falsy), returning a boolean
|
|
63
|
-
* indicating whether the assertion passed.
|
|
64
|
-
*/
|
|
65
|
-
falsy: FalsyAssertion;
|
|
66
|
-
|
|
67
|
-
/**
|
|
68
|
-
* Assert that `actual` is [the same
|
|
69
|
-
* value](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/is) as `expected`,
|
|
70
|
-
* returning a boolean indicating whether the assertion passed.
|
|
71
|
-
*/
|
|
72
|
-
is: IsAssertion;
|
|
73
|
-
|
|
74
|
-
/**
|
|
75
|
-
* Assert that `actual` is not [the same
|
|
76
|
-
* value](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/is) as `expected`,
|
|
77
|
-
* returning a boolean indicating whether the assertion passed.
|
|
78
|
-
*/
|
|
79
|
-
not: NotAssertion;
|
|
80
|
-
|
|
81
|
-
/**
|
|
82
|
-
* Assert that `actual` is not [deeply equal](https://github.com/concordancejs/concordance#comparison-details) to
|
|
83
|
-
* `expected`, returning a boolean indicating whether the assertion passed.
|
|
84
|
-
*/
|
|
85
|
-
notDeepEqual: NotDeepEqualAssertion;
|
|
86
|
-
|
|
87
|
-
/**
|
|
88
|
-
* Assert that `string` does not match the regular expression, returning a boolean indicating whether the assertion
|
|
89
|
-
* passed.
|
|
90
|
-
*/
|
|
91
|
-
notRegex: NotRegexAssertion;
|
|
92
|
-
|
|
93
|
-
/** Assert that the function does not throw. */
|
|
94
|
-
notThrows: NotThrowsAssertion;
|
|
95
|
-
|
|
96
|
-
/** Assert that the async function does not throw, or that the promise does not reject. Must be awaited. */
|
|
97
|
-
notThrowsAsync: NotThrowsAsyncAssertion;
|
|
98
|
-
|
|
99
|
-
/** Count a passing assertion, always returning `true`. */
|
|
100
|
-
pass: PassAssertion;
|
|
101
|
-
|
|
102
|
-
/**
|
|
103
|
-
* Assert that `string` matches the regular expression, returning a boolean indicating whether the assertion passed.
|
|
104
|
-
*/
|
|
105
|
-
regex: RegexAssertion;
|
|
106
|
-
|
|
107
|
-
/**
|
|
108
|
-
* Assert that `expected` is [deeply equal](https://github.com/concordancejs/concordance#comparison-details) to a
|
|
109
|
-
* previously recorded [snapshot](https://github.com/concordancejs/concordance#serialization-details), or if
|
|
110
|
-
* necessary record a new snapshot.
|
|
111
|
-
*/
|
|
112
|
-
snapshot: SnapshotAssertion;
|
|
113
|
-
|
|
114
|
-
/**
|
|
115
|
-
* Assert that the function throws [an error](https://www.npmjs.com/package/is-error). If so, returns the error value.
|
|
116
|
-
*/
|
|
117
|
-
throws: ThrowsAssertion;
|
|
118
|
-
|
|
119
|
-
/**
|
|
120
|
-
* Assert that the async function throws [an error](https://www.npmjs.com/package/is-error), or the promise rejects
|
|
121
|
-
* with one. If so, returns a promise for the error value, which must be awaited.
|
|
122
|
-
*/
|
|
123
|
-
throwsAsync: ThrowsAsyncAssertion;
|
|
124
|
-
|
|
125
|
-
/**
|
|
126
|
-
* Assert that `actual` is strictly true, returning a boolean indicating whether the assertion passed.
|
|
127
|
-
*/
|
|
128
|
-
true: TrueAssertion;
|
|
129
|
-
|
|
130
|
-
/**
|
|
131
|
-
* Assert that `actual` is [truthy](https://developer.mozilla.org/en-US/docs/Glossary/Truthy), returning a boolean
|
|
132
|
-
* indicating whether the assertion passed.
|
|
133
|
-
*/
|
|
134
|
-
truthy: TruthyAssertion;
|
|
135
|
-
}
|
|
136
|
-
|
|
137
|
-
export interface AssertAssertion {
|
|
138
|
-
/**
|
|
139
|
-
* Assert that `actual` is [truthy](https://developer.mozilla.org/en-US/docs/Glossary/Truthy), returning a boolean
|
|
140
|
-
* indicating whether the assertion passed. Comes with power-assert.
|
|
141
|
-
*/
|
|
142
|
-
(actual: any, message?: string): boolean;
|
|
143
|
-
|
|
144
|
-
/** Skip this assertion. */
|
|
145
|
-
skip(actual: any, message?: string): void;
|
|
146
|
-
}
|
|
147
|
-
|
|
148
|
-
export interface DeepEqualAssertion {
|
|
149
|
-
/**
|
|
150
|
-
* Assert that `actual` is [deeply equal](https://github.com/concordancejs/concordance#comparison-details) to
|
|
151
|
-
* `expected`, returning a boolean indicating whether the assertion passed.
|
|
152
|
-
*/
|
|
153
|
-
<Actual, Expected extends Actual>(actual: Actual, expected: Expected, message?: string): actual is Expected;
|
|
154
|
-
|
|
155
|
-
/** Skip this assertion. */
|
|
156
|
-
skip(actual: any, expected: any, message?: string): void;
|
|
157
|
-
}
|
|
158
|
-
|
|
159
|
-
export interface LikeAssertion {
|
|
160
|
-
/**
|
|
161
|
-
* Assert that `value` is like `selector`, returning a boolean indicating whether the assertion passed.
|
|
162
|
-
*/
|
|
163
|
-
<Expected extends Record<string, any>>(value: any, selector: Expected, message?: string): value is Expected;
|
|
164
|
-
|
|
165
|
-
/** Skip this assertion. */
|
|
166
|
-
skip(value: any, selector: any, message?: string): void;
|
|
167
|
-
}
|
|
168
|
-
|
|
169
|
-
export interface FailAssertion {
|
|
170
|
-
/** Fail the test, always returning `false`. */
|
|
171
|
-
(message?: string): boolean;
|
|
172
|
-
|
|
173
|
-
/** Skip this assertion. */
|
|
174
|
-
skip(message?: string): void;
|
|
175
|
-
}
|
|
176
|
-
|
|
177
|
-
export interface FalseAssertion {
|
|
178
|
-
/**
|
|
179
|
-
* Assert that `actual` is strictly false, returning a boolean indicating whether the assertion passed.
|
|
180
|
-
*/
|
|
181
|
-
(actual: any, message?: string): actual is false;
|
|
182
|
-
|
|
183
|
-
/** Skip this assertion. */
|
|
184
|
-
skip(actual: any, message?: string): void;
|
|
185
|
-
}
|
|
186
|
-
|
|
187
|
-
export interface FalsyAssertion {
|
|
188
|
-
/**
|
|
189
|
-
* Assert that `actual` is [falsy](https://developer.mozilla.org/en-US/docs/Glossary/Falsy), returning a boolean
|
|
190
|
-
* indicating whether the assertion passed.
|
|
191
|
-
*/
|
|
192
|
-
(actual: any, message?: string): boolean;
|
|
193
|
-
|
|
194
|
-
/** Skip this assertion. */
|
|
195
|
-
skip(actual: any, message?: string): void;
|
|
196
|
-
}
|
|
197
|
-
|
|
198
|
-
export interface IsAssertion {
|
|
199
|
-
/**
|
|
200
|
-
* Assert that `actual` is [the same
|
|
201
|
-
* value](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/is) as `expected`,
|
|
202
|
-
* returning a boolean indicating whether the assertion passed.
|
|
203
|
-
*/
|
|
204
|
-
<Actual, Expected extends Actual>(actual: Actual, expected: Expected, message?: string): actual is Expected;
|
|
205
|
-
|
|
206
|
-
/** Skip this assertion. */
|
|
207
|
-
skip(actual: any, expected: any, message?: string): void;
|
|
208
|
-
}
|
|
209
|
-
|
|
210
|
-
export interface NotAssertion {
|
|
211
|
-
/**
|
|
212
|
-
* Assert that `actual` is not [the same
|
|
213
|
-
* value](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/is) as `expected`,
|
|
214
|
-
* returning a boolean indicating whether the assertion passed.
|
|
215
|
-
*/
|
|
216
|
-
<Actual, Expected>(actual: Actual, expected: Expected, message?: string): boolean;
|
|
217
|
-
|
|
218
|
-
/** Skip this assertion. */
|
|
219
|
-
skip(actual: any, expected: any, message?: string): void;
|
|
220
|
-
}
|
|
221
|
-
|
|
222
|
-
export interface NotDeepEqualAssertion {
|
|
223
|
-
/**
|
|
224
|
-
* Assert that `actual` is not [deeply equal](https://github.com/concordancejs/concordance#comparison-details) to
|
|
225
|
-
* `expected`, returning a boolean indicating whether the assertion passed.
|
|
226
|
-
*/
|
|
227
|
-
<Actual, Expected>(actual: Actual, expected: Expected, message?: string): boolean;
|
|
228
|
-
|
|
229
|
-
/** Skip this assertion. */
|
|
230
|
-
skip(actual: any, expected: any, message?: string): void;
|
|
231
|
-
}
|
|
232
|
-
|
|
233
|
-
export interface NotRegexAssertion {
|
|
234
|
-
/**
|
|
235
|
-
* Assert that `string` does not match the regular expression, returning a boolean indicating whether the assertion
|
|
236
|
-
* passed.
|
|
237
|
-
*/
|
|
238
|
-
(string: string, regex: RegExp, message?: string): boolean;
|
|
239
|
-
|
|
240
|
-
/** Skip this assertion. */
|
|
241
|
-
skip(string: string, regex: RegExp, message?: string): void;
|
|
242
|
-
}
|
|
243
|
-
|
|
244
|
-
export interface NotThrowsAssertion {
|
|
245
|
-
/** Assert that the function does not throw. */
|
|
246
|
-
(fn: () => any, message?: string): void;
|
|
247
|
-
|
|
248
|
-
/** Skip this assertion. */
|
|
249
|
-
skip(fn: () => any, message?: string): void;
|
|
250
|
-
}
|
|
251
|
-
|
|
252
|
-
export interface NotThrowsAsyncAssertion {
|
|
253
|
-
/** Assert that the async function does not throw. You must await the result. */
|
|
254
|
-
(fn: () => PromiseLike<any>, message?: string): Promise<void>;
|
|
255
|
-
|
|
256
|
-
/** Assert that the promise does not reject. You must await the result. */
|
|
257
|
-
(promise: PromiseLike<any>, message?: string): Promise<void>;
|
|
258
|
-
|
|
259
|
-
/** Skip this assertion. */
|
|
260
|
-
skip(nonThrower: any, message?: string): void;
|
|
261
|
-
}
|
|
262
|
-
|
|
263
|
-
export interface PassAssertion {
|
|
264
|
-
/** Count a passing assertion, always returning `true`. */
|
|
265
|
-
(message?: string): boolean;
|
|
266
|
-
|
|
267
|
-
/** Skip this assertion. */
|
|
268
|
-
skip(message?: string): void;
|
|
269
|
-
}
|
|
270
|
-
|
|
271
|
-
export interface RegexAssertion {
|
|
272
|
-
/**
|
|
273
|
-
* Assert that `string` matches the regular expression, returning a boolean indicating whether the assertion passed.
|
|
274
|
-
*/
|
|
275
|
-
(string: string, regex: RegExp, message?: string): boolean;
|
|
276
|
-
|
|
277
|
-
/** Skip this assertion. */
|
|
278
|
-
skip(string: string, regex: RegExp, message?: string): void;
|
|
279
|
-
}
|
|
280
|
-
|
|
281
|
-
export interface SnapshotAssertion {
|
|
282
|
-
/**
|
|
283
|
-
* Assert that `expected` is [deeply equal](https://github.com/concordancejs/concordance#comparison-details) to a
|
|
284
|
-
* previously recorded [snapshot](https://github.com/concordancejs/concordance#serialization-details), or if
|
|
285
|
-
* necessary record a new snapshot.
|
|
286
|
-
*/
|
|
287
|
-
(expected: any, message?: string): void;
|
|
288
|
-
|
|
289
|
-
/** Skip this assertion. */
|
|
290
|
-
skip(expected: any, message?: string): void;
|
|
291
|
-
}
|
|
292
|
-
|
|
293
|
-
export interface ThrowsAssertion {
|
|
294
|
-
/**
|
|
295
|
-
* Assert that the function throws [an error](https://www.npmjs.com/package/is-error). If so, returns the error value.
|
|
296
|
-
* The error must satisfy all expectations.
|
|
297
|
-
*/
|
|
298
|
-
<ThrownError extends Error>(fn: () => any, expectations?: ThrowsExpectation | null, message?: string): ThrownError;
|
|
299
|
-
|
|
300
|
-
/** Skip this assertion. */
|
|
301
|
-
skip(fn: () => any, expectations?: any, message?: string): void;
|
|
302
|
-
}
|
|
303
|
-
|
|
304
|
-
export interface ThrowsAsyncAssertion {
|
|
305
|
-
/**
|
|
306
|
-
* Assert that the async function throws [an error](https://www.npmjs.com/package/is-error). If so, returns the error
|
|
307
|
-
* value. You must await the result.
|
|
308
|
-
*/
|
|
309
|
-
<ThrownError extends Error>(fn: () => PromiseLike<any>, expectations?: null, message?: string): Promise<ThrownError>;
|
|
310
|
-
|
|
311
|
-
/**
|
|
312
|
-
* Assert that the async function throws [an error](https://www.npmjs.com/package/is-error). If so, returns the error
|
|
313
|
-
* value. You must await the result. The error must satisfy all expectations.
|
|
314
|
-
*/
|
|
315
|
-
<ThrownError extends Error>(fn: () => PromiseLike<any>, expectations: ThrowsExpectation, message?: string): Promise<ThrownError>;
|
|
316
|
-
|
|
317
|
-
/**
|
|
318
|
-
* Assert that the promise rejects with [an error](https://www.npmjs.com/package/is-error). If so, returns the
|
|
319
|
-
* rejection reason. You must await the result.
|
|
320
|
-
*/
|
|
321
|
-
<ThrownError extends Error>(promise: PromiseLike<any>, expectations?: null, message?: string): Promise<ThrownError>;
|
|
322
|
-
|
|
323
|
-
/**
|
|
324
|
-
* Assert that the promise rejects with [an error](https://www.npmjs.com/package/is-error). If so, returns the
|
|
325
|
-
* rejection reason. You must await the result. The error must satisfy all expectations.
|
|
326
|
-
*/
|
|
327
|
-
<ThrownError extends Error>(promise: PromiseLike<any>, expectations: ThrowsExpectation, message?: string): Promise<ThrownError>;
|
|
328
|
-
|
|
329
|
-
/** Skip this assertion. */
|
|
330
|
-
skip(thrower: any, expectations?: any, message?: string): void;
|
|
331
|
-
}
|
|
332
|
-
|
|
333
|
-
export interface TrueAssertion {
|
|
334
|
-
/**
|
|
335
|
-
* Assert that `actual` is strictly true, returning a boolean indicating whether the assertion passed.
|
|
336
|
-
*/
|
|
337
|
-
(actual: any, message?: string): actual is true;
|
|
338
|
-
|
|
339
|
-
/** Skip this assertion. */
|
|
340
|
-
skip(actual: any, message?: string): void;
|
|
341
|
-
}
|
|
342
|
-
|
|
343
|
-
export interface TruthyAssertion {
|
|
344
|
-
/**
|
|
345
|
-
* Assert that `actual` is [truthy](https://developer.mozilla.org/en-US/docs/Glossary/Truthy), returning a boolean
|
|
346
|
-
* indicating whether the assertion passed.
|
|
347
|
-
*/
|
|
348
|
-
(actual: any, message?: string): boolean;
|
|
349
|
-
|
|
350
|
-
/** Skip this assertion. */
|
|
351
|
-
skip(actual: any, message?: string): void;
|
|
352
|
-
}
|
|
353
|
-
|
|
354
|
-
/** The `t` value passed to test & hook implementations. */
|
|
355
|
-
export interface ExecutionContext<Context = unknown> extends Assertions {
|
|
356
|
-
/** Test context, shared with hooks. */
|
|
357
|
-
context: Context;
|
|
358
|
-
|
|
359
|
-
/** Title of the test or hook. */
|
|
360
|
-
readonly title: string;
|
|
361
|
-
|
|
362
|
-
/** Whether the test has passed. Only accurate in afterEach hooks. */
|
|
363
|
-
readonly passed: boolean;
|
|
364
|
-
|
|
365
|
-
log: LogFn;
|
|
366
|
-
plan: PlanFn;
|
|
367
|
-
teardown: TeardownFn;
|
|
368
|
-
timeout: TimeoutFn;
|
|
369
|
-
try: TryFn<Context>;
|
|
370
|
-
}
|
|
371
|
-
|
|
372
|
-
export interface LogFn {
|
|
373
|
-
/** Log one or more values. */
|
|
374
|
-
(...values: any[]): void;
|
|
375
|
-
|
|
376
|
-
/** Skip logging. */
|
|
377
|
-
skip(...values: any[]): void;
|
|
378
|
-
}
|
|
379
|
-
|
|
380
|
-
export interface PlanFn {
|
|
381
|
-
/**
|
|
382
|
-
* Plan how many assertion there are in the test. The test will fail if the actual assertion count doesn't match the
|
|
383
|
-
* number of planned assertions. See [assertion planning](https://github.com/avajs/ava#assertion-planning).
|
|
384
|
-
*/
|
|
385
|
-
(count: number): void;
|
|
386
|
-
|
|
387
|
-
/** Don't plan assertions. */
|
|
388
|
-
skip(count: number): void;
|
|
389
|
-
}
|
|
390
|
-
|
|
391
|
-
export interface TimeoutFn {
|
|
392
|
-
/**
|
|
393
|
-
* Set a timeout for the test, in milliseconds. The test will fail if the timeout is exceeded.
|
|
394
|
-
* The timeout is reset each time an assertion is made.
|
|
395
|
-
*/
|
|
396
|
-
(ms: number, message?: string): void;
|
|
397
|
-
}
|
|
398
|
-
|
|
399
|
-
export interface TeardownFn {
|
|
400
|
-
/** Declare a function to be run after the test has ended. */
|
|
401
|
-
(fn: () => void): void;
|
|
402
|
-
}
|
|
403
|
-
|
|
404
|
-
export interface TryFn<Context = unknown> {
|
|
405
|
-
/**
|
|
406
|
-
* Attempt to run some assertions. The result must be explicitly committed or discarded or else
|
|
407
|
-
* the test will fail. A macro may be provided. The title may help distinguish attempts from
|
|
408
|
-
* one another.
|
|
409
|
-
*/
|
|
410
|
-
<Args extends any[]>(title: string, fn: EitherMacro<Args, Context>, ...args: Args): Promise<TryResult>;
|
|
411
|
-
|
|
412
|
-
/**
|
|
413
|
-
* Attempt to run some assertions. The result must be explicitly committed or discarded or else
|
|
414
|
-
* the test will fail. A macro may be provided. The title may help distinguish attempts from
|
|
415
|
-
* one another.
|
|
416
|
-
*/
|
|
417
|
-
<Args extends any[]>(title: string, fn: [EitherMacro<Args, Context>, ...Array<EitherMacro<Args, Context>>], ...args: Args): Promise<TryResult[]>;
|
|
418
|
-
|
|
419
|
-
/**
|
|
420
|
-
* Attempt to run some assertions. The result must be explicitly committed or discarded or else
|
|
421
|
-
* the test will fail. A macro may be provided.
|
|
422
|
-
*/
|
|
423
|
-
<Args extends any[]>(fn: EitherMacro<Args, Context>, ...args: Args): Promise<TryResult>;
|
|
424
|
-
|
|
425
|
-
/**
|
|
426
|
-
* Attempt to run some assertions. The result must be explicitly committed or discarded or else
|
|
427
|
-
* the test will fail. A macro may be provided.
|
|
428
|
-
*/
|
|
429
|
-
<Args extends any[]>(fn: [EitherMacro<Args, Context>, ...Array<EitherMacro<Args, Context>>], ...args: Args): Promise<TryResult[]>;
|
|
430
|
-
}
|
|
431
|
-
|
|
432
|
-
export interface AssertionError extends Error {}
|
|
433
|
-
|
|
434
|
-
export interface TryResult {
|
|
435
|
-
/**
|
|
436
|
-
* Title of the attempt, helping you tell attempts aparts.
|
|
437
|
-
*/
|
|
438
|
-
title: string;
|
|
439
|
-
|
|
440
|
-
/**
|
|
441
|
-
* Indicates whether all assertions passed, or at least one failed.
|
|
442
|
-
*/
|
|
443
|
-
passed: boolean;
|
|
444
|
-
|
|
445
|
-
/**
|
|
446
|
-
* Errors raised for each failed assertion.
|
|
447
|
-
*/
|
|
448
|
-
errors: AssertionError[];
|
|
449
|
-
|
|
450
|
-
/**
|
|
451
|
-
* Logs created during the attempt using `t.log()`. Contains formatted values.
|
|
452
|
-
*/
|
|
453
|
-
logs: string[];
|
|
454
|
-
|
|
455
|
-
/**
|
|
456
|
-
* Commit the attempt. Counts as one assertion for the plan count. If the
|
|
457
|
-
* attempt failed, calling this will also cause your test to fail.
|
|
458
|
-
*/
|
|
459
|
-
commit(options?: CommitDiscardOptions): void;
|
|
460
|
-
|
|
461
|
-
/**
|
|
462
|
-
* Discard the attempt.
|
|
463
|
-
*/
|
|
464
|
-
discard(options?: CommitDiscardOptions): void;
|
|
465
|
-
}
|
|
466
|
-
|
|
467
|
-
// FIXME(novemberborn) Refactor implementations to be different types returning a promise,, subscribable, or void, not a
|
|
468
|
-
// single type returning a union. A union with void as a return type doesn't make sense.
|
|
469
|
-
export type ImplementationResult = PromiseLike<void> | Subscribable | boolean | void;
|
|
470
|
-
export type Implementation<Context = unknown> = (t: ExecutionContext<Context>) => ImplementationResult;
|
|
471
|
-
|
|
472
|
-
/** A reusable test or hook implementation. */
|
|
473
|
-
export type UntitledMacro<Args extends any[], Context = unknown> = (t: ExecutionContext<Context>, ...args: Args) => ImplementationResult;
|
|
474
|
-
|
|
475
|
-
/** A reusable test or hook implementation. */
|
|
476
|
-
export type Macro<Args extends any[], Context = unknown> = UntitledMacro<Args, Context> & {
|
|
477
|
-
/**
|
|
478
|
-
* Implement this function to generate a test (or hook) title whenever this macro is used. `providedTitle` contains
|
|
479
|
-
* the title provided when the test or hook was declared. Also receives the remaining test arguments.
|
|
480
|
-
*/
|
|
481
|
-
title?: (providedTitle: string | undefined, ...args: Args) => string;
|
|
482
|
-
};
|
|
483
|
-
|
|
484
|
-
export type EitherMacro<Args extends any[], Context> = Macro<Args, Context> | UntitledMacro<Args, Context>;
|
|
485
|
-
|
|
486
|
-
/** Alias for a single macro, or an array of macros. */
|
|
487
|
-
export type OneOrMoreMacros<Args extends any[], Context> = EitherMacro<Args, Context> | [EitherMacro<Args, Context>, ...Array<EitherMacro<Args, Context>>];
|
|
488
|
-
|
|
489
|
-
export interface TestInterface<Context = unknown> {
|
|
490
|
-
/** Declare a concurrent test. */
|
|
491
|
-
(title: string, implementation: Implementation<Context>): void;
|
|
492
|
-
|
|
493
|
-
/** Declare a concurrent test that uses one or more macros. Additional arguments are passed to the macro. */
|
|
494
|
-
<T extends any[]>(title: string, macros: OneOrMoreMacros<T, Context>, ...rest: T): void;
|
|
495
|
-
|
|
496
|
-
/** Declare a concurrent test that uses one or more macros. The macro is responsible for generating a unique test title. */
|
|
497
|
-
<T extends any[]>(macros: OneOrMoreMacros<T, Context>, ...rest: T): void;
|
|
498
|
-
|
|
499
|
-
/** Declare a hook that is run once, after all tests have passed. */
|
|
500
|
-
after: AfterInterface<Context>;
|
|
501
|
-
|
|
502
|
-
/** Declare a hook that is run after each passing test. */
|
|
503
|
-
afterEach: AfterInterface<Context>;
|
|
504
|
-
|
|
505
|
-
/** Declare a hook that is run once, before all tests. */
|
|
506
|
-
before: BeforeInterface<Context>;
|
|
507
|
-
|
|
508
|
-
/** Declare a hook that is run before each test. */
|
|
509
|
-
beforeEach: BeforeInterface<Context>;
|
|
510
|
-
|
|
511
|
-
/** Declare a test that is expected to fail. */
|
|
512
|
-
failing: FailingInterface<Context>;
|
|
513
|
-
|
|
514
|
-
/** Declare tests and hooks that are run serially. */
|
|
515
|
-
serial: SerialInterface<Context>;
|
|
516
|
-
|
|
517
|
-
only: OnlyInterface<Context>;
|
|
518
|
-
skip: SkipInterface<Context>;
|
|
519
|
-
todo: TodoDeclaration;
|
|
520
|
-
meta: MetaInterface;
|
|
521
|
-
}
|
|
522
|
-
|
|
523
|
-
export interface AfterInterface<Context = unknown> {
|
|
524
|
-
/** Declare a hook that is run once, after all tests have passed. */
|
|
525
|
-
(implementation: Implementation<Context>): void;
|
|
526
|
-
|
|
527
|
-
/** Declare a hook that is run once, after all tests have passed. */
|
|
528
|
-
(title: string, implementation: Implementation<Context>): void;
|
|
529
|
-
|
|
530
|
-
/** Declare a hook that is run once, after all tests have passed. Additional arguments are passed to the macro. */
|
|
531
|
-
<T extends any[]>(title: string, macros: OneOrMoreMacros<T, Context>, ...rest: T): void;
|
|
532
|
-
|
|
533
|
-
/** Declare a hook that is run once, after all tests have passed. */
|
|
534
|
-
<T extends any[]>(macros: OneOrMoreMacros<T, Context>, ...rest: T): void;
|
|
535
|
-
|
|
536
|
-
/** Declare a hook that is run once, after all tests are done. */
|
|
537
|
-
always: AlwaysInterface<Context>;
|
|
538
|
-
|
|
539
|
-
skip: HookSkipInterface<Context>;
|
|
540
|
-
}
|
|
541
|
-
|
|
542
|
-
export interface AlwaysInterface<Context = unknown> {
|
|
543
|
-
/** Declare a hook that is run once, after all tests are done. */
|
|
544
|
-
(implementation: Implementation<Context>): void;
|
|
545
|
-
|
|
546
|
-
/** Declare a hook that is run once, after all tests are done. */
|
|
547
|
-
(title: string, implementation: Implementation<Context>): void;
|
|
548
|
-
|
|
549
|
-
/** Declare a hook that is run once, after all tests are done. Additional arguments are passed to the macro. */
|
|
550
|
-
<T extends any[]>(title: string, macros: OneOrMoreMacros<T, Context>, ...rest: T): void;
|
|
551
|
-
|
|
552
|
-
/** Declare a hook that is run once, after all tests are done. */
|
|
553
|
-
<T extends any[]>(macros: OneOrMoreMacros<T, Context>, ...rest: T): void;
|
|
554
|
-
|
|
555
|
-
skip: HookSkipInterface<Context>;
|
|
556
|
-
}
|
|
557
|
-
|
|
558
|
-
export interface BeforeInterface<Context = unknown> {
|
|
559
|
-
/** Declare a hook that is run once, before all tests. */
|
|
560
|
-
(implementation: Implementation<Context>): void;
|
|
561
|
-
|
|
562
|
-
/** Declare a hook that is run once, before all tests. */
|
|
563
|
-
(title: string, implementation: Implementation<Context>): void;
|
|
564
|
-
|
|
565
|
-
/** Declare a hook that is run once, before all tests. Additional arguments are passed to the macro. */
|
|
566
|
-
<T extends any[]>(title: string, macros: OneOrMoreMacros<T, Context>, ...rest: T): void;
|
|
567
|
-
|
|
568
|
-
/** Declare a hook that is run once, before all tests. */
|
|
569
|
-
<T extends any[]>(macros: OneOrMoreMacros<T, Context>, ...rest: T): void;
|
|
570
|
-
|
|
571
|
-
skip: HookSkipInterface<Context>;
|
|
572
|
-
}
|
|
573
|
-
|
|
574
|
-
export interface FailingInterface<Context = unknown> {
|
|
575
|
-
/** Declare a concurrent test. The test is expected to fail. */
|
|
576
|
-
(title: string, implementation: Implementation<Context>): void;
|
|
577
|
-
|
|
578
|
-
/**
|
|
579
|
-
* Declare a concurrent test that uses one or more macros. Additional arguments are passed to the macro.
|
|
580
|
-
* The test is expected to fail.
|
|
581
|
-
*/
|
|
582
|
-
<T extends any[]>(title: string, macros: OneOrMoreMacros<T, Context>, ...rest: T): void;
|
|
583
|
-
|
|
584
|
-
/**
|
|
585
|
-
* Declare a concurrent test that uses one or more macros. The macro is responsible for generating a unique test title.
|
|
586
|
-
* The test is expected to fail.
|
|
587
|
-
*/
|
|
588
|
-
<T extends any[]>(macros: OneOrMoreMacros<T, Context>, ...rest: T): void;
|
|
589
|
-
|
|
590
|
-
only: OnlyInterface<Context>;
|
|
591
|
-
skip: SkipInterface<Context>;
|
|
592
|
-
}
|
|
593
|
-
|
|
594
|
-
export interface HookSkipInterface<Context = unknown> {
|
|
595
|
-
/** Skip this hook. */
|
|
596
|
-
(implementation: Implementation<Context>): void;
|
|
597
|
-
|
|
598
|
-
/** Skip this hook. */
|
|
599
|
-
(title: string, implementation: Implementation<Context>): void;
|
|
600
|
-
|
|
601
|
-
/** Skip this hook. */
|
|
602
|
-
<T extends any[]>(title: string, macros: OneOrMoreMacros<T, Context>, ...rest: T): void;
|
|
603
|
-
|
|
604
|
-
/** Skip this hook. */
|
|
605
|
-
<T extends any[]>(macros: OneOrMoreMacros<T, Context>, ...rest: T): void;
|
|
606
|
-
}
|
|
607
|
-
|
|
608
|
-
export interface OnlyInterface<Context = unknown> {
|
|
609
|
-
/** Declare a test. Only this test and others declared with `.only()` are run. */
|
|
610
|
-
(title: string, implementation: Implementation<Context>): void;
|
|
611
|
-
|
|
612
|
-
/**
|
|
613
|
-
* Declare a test that uses one or more macros. Additional arguments are passed to the macro.
|
|
614
|
-
* Only this test and others declared with `.only()` are run.
|
|
615
|
-
*/
|
|
616
|
-
<T extends any[]>(title: string, macros: OneOrMoreMacros<T, Context>, ...rest: T): void;
|
|
617
|
-
|
|
618
|
-
/**
|
|
619
|
-
* Declare a test that uses one or more macros. The macro is responsible for generating a unique test title.
|
|
620
|
-
* Only this test and others declared with `.only()` are run.
|
|
621
|
-
*/
|
|
622
|
-
<T extends any[]>(macros: OneOrMoreMacros<T, Context>, ...rest: T): void;
|
|
623
|
-
}
|
|
624
|
-
|
|
625
|
-
export interface SerialInterface<Context = unknown> {
|
|
626
|
-
/** Declare a serial test. */
|
|
627
|
-
(title: string, implementation: Implementation<Context>): void;
|
|
628
|
-
|
|
629
|
-
/** Declare a serial test that uses one or more macros. Additional arguments are passed to the macro. */
|
|
630
|
-
<T extends any[]>(title: string, macros: OneOrMoreMacros<T, Context>, ...rest: T): void;
|
|
631
|
-
|
|
632
|
-
/**
|
|
633
|
-
* Declare a serial test that uses one or more macros. The macro is responsible for generating a unique test title.
|
|
634
|
-
*/
|
|
635
|
-
<T extends any[]>(macros: OneOrMoreMacros<T, Context>, ...rest: T): void;
|
|
636
|
-
|
|
637
|
-
/** Declare a serial hook that is run once, after all tests have passed. */
|
|
638
|
-
after: AfterInterface<Context>;
|
|
639
|
-
|
|
640
|
-
/** Declare a serial hook that is run after each passing test. */
|
|
641
|
-
afterEach: AfterInterface<Context>;
|
|
642
|
-
|
|
643
|
-
/** Declare a serial hook that is run once, before all tests. */
|
|
644
|
-
before: BeforeInterface<Context>;
|
|
645
|
-
|
|
646
|
-
/** Declare a serial hook that is run before each test. */
|
|
647
|
-
beforeEach: BeforeInterface<Context>;
|
|
648
|
-
|
|
649
|
-
/** Declare a serial test that is expected to fail. */
|
|
650
|
-
failing: FailingInterface<Context>;
|
|
651
|
-
|
|
652
|
-
only: OnlyInterface<Context>;
|
|
653
|
-
skip: SkipInterface<Context>;
|
|
654
|
-
todo: TodoDeclaration;
|
|
655
|
-
}
|
|
656
|
-
|
|
657
|
-
export interface SkipInterface<Context = unknown> {
|
|
658
|
-
/** Skip this test. */
|
|
659
|
-
(title: string, implementation: Implementation<Context>): void;
|
|
660
|
-
|
|
661
|
-
/** Skip this test. */
|
|
662
|
-
<T extends any[]>(title: string, macros: OneOrMoreMacros<T, Context>, ...rest: T): void;
|
|
663
|
-
|
|
664
|
-
/** Skip this test. */
|
|
665
|
-
<T extends any[]>(macros: OneOrMoreMacros<T, Context>, ...rest: T): void;
|
|
666
|
-
}
|
|
667
|
-
|
|
668
|
-
export interface TodoDeclaration {
|
|
669
|
-
/** Declare a test that should be implemented later. */
|
|
670
|
-
(title: string): void;
|
|
671
|
-
}
|
|
672
|
-
|
|
673
|
-
export interface MetaInterface {
|
|
674
|
-
/** Path to the test file being executed. */
|
|
675
|
-
file: string;
|
|
676
|
-
|
|
677
|
-
/** Directory where snapshots are stored. */
|
|
678
|
-
snapshotDirectory: string;
|
|
679
|
-
}
|
|
3
|
+
export * from './types/assertions';
|
|
4
|
+
export * from './types/try-fn';
|
|
5
|
+
export * from './types/test-fn';
|
|
6
|
+
export * from './types/subscribable';
|
|
680
7
|
|
|
681
8
|
/** Call to declare a test, or chain to declare hooks or test modifiers */
|
|
682
|
-
declare const test:
|
|
9
|
+
declare const test: TestFn;
|
|
683
10
|
|
|
684
11
|
/** Call to declare a test, or chain to declare hooks or test modifiers */
|
|
685
12
|
export default test;
|
|
686
|
-
|
|
687
|
-
/** Call to declare a hook that is run once, after all tests have passed, or chain to declare modifiers. */
|
|
688
|
-
export const after: AfterInterface;
|
|
689
|
-
|
|
690
|
-
/** Call to declare a hook that is run after each passing test, or chain to declare modifiers. */
|
|
691
|
-
export const afterEach: AfterInterface;
|
|
692
|
-
|
|
693
|
-
/** Call to declare a hook that is run once, before all tests, or chain to declare modifiers. */
|
|
694
|
-
export const before: BeforeInterface;
|
|
695
|
-
|
|
696
|
-
/** Call to declare a hook that is run before each test, or chain to declare modifiers. */
|
|
697
|
-
export const beforeEach: BeforeInterface;
|
|
698
|
-
|
|
699
|
-
/** Call to declare a test that is expected to fail, or chain to declare modifiers. */
|
|
700
|
-
export const failing: FailingInterface;
|
|
701
|
-
|
|
702
|
-
/** Call to declare a test that is run exclusively, along with other tests declared with `.only()`. */
|
|
703
|
-
export const only: OnlyInterface;
|
|
704
|
-
|
|
705
|
-
/** Call to declare a serial test, or chain to declare serial hooks or test modifiers. */
|
|
706
|
-
export const serial: SerialInterface;
|
|
707
|
-
|
|
708
|
-
/** Skip this test. */
|
|
709
|
-
export const skip: SkipInterface;
|
|
710
|
-
|
|
711
|
-
/** Declare a test that should be implemented later. */
|
|
712
|
-
export const todo: TodoDeclaration;
|
|
713
|
-
|
|
714
|
-
/** Meta data associated with the current process. */
|
|
715
|
-
export const meta: MetaInterface;
|