ava 5.3.1 → 6.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.
Files changed (40) hide show
  1. package/entrypoints/internal.d.mts +7 -0
  2. package/lib/api-event-iterator.js +12 -0
  3. package/lib/api.js +14 -23
  4. package/lib/assert.js +289 -444
  5. package/lib/cli.js +95 -61
  6. package/lib/code-excerpt.js +2 -2
  7. package/lib/eslint-plugin-helper-worker.js +3 -3
  8. package/lib/fork.js +3 -13
  9. package/lib/glob-helpers.cjs +1 -9
  10. package/lib/globs.js +7 -3
  11. package/lib/line-numbers.js +1 -1
  12. package/lib/load-config.js +3 -3
  13. package/lib/parse-test-args.js +3 -3
  14. package/lib/plugin-support/shared-workers.js +4 -4
  15. package/lib/provider-manager.js +11 -13
  16. package/lib/reporters/beautify-stack.js +0 -1
  17. package/lib/reporters/default.js +92 -45
  18. package/lib/reporters/format-serialized-error.js +6 -6
  19. package/lib/reporters/improper-usage-messages.js +5 -5
  20. package/lib/reporters/tap.js +30 -30
  21. package/lib/run-status.js +9 -0
  22. package/lib/runner.js +7 -7
  23. package/lib/scheduler.js +14 -1
  24. package/lib/serialize-error.js +44 -116
  25. package/lib/slash.cjs +1 -1
  26. package/lib/snapshot-manager.js +14 -8
  27. package/lib/test.js +90 -81
  28. package/lib/watcher.js +494 -365
  29. package/lib/worker/base.js +90 -51
  30. package/lib/worker/channel.cjs +9 -53
  31. package/license +1 -1
  32. package/package.json +36 -42
  33. package/readme.md +6 -12
  34. package/types/assertions.d.cts +107 -49
  35. package/types/shared-worker.d.cts +0 -2
  36. package/types/state-change-events.d.cts +143 -0
  37. package/types/test-fn.d.cts +10 -5
  38. package/lib/worker/dependency-tracker.js +0 -48
  39. /package/entrypoints/{main.d.ts → main.d.mts} +0 -0
  40. /package/entrypoints/{plugin.d.ts → plugin.d.mts} +0 -0
@@ -1,12 +1,15 @@
1
1
  export type ErrorConstructor<ErrorType extends Error = Error> = {
2
- new (...args: any[]): ErrorType;
3
2
  readonly prototype: ErrorType;
4
- }
3
+ new (...args: any[]): ErrorType;
4
+ };
5
5
 
6
6
  export type ThrownError<ErrorType extends ErrorConstructor | Error> = ErrorType extends ErrorConstructor ? ErrorType['prototype'] : ErrorType;
7
7
 
8
8
  /** Specify one or more expectations the thrown error must satisfy. */
9
9
  export type ThrowsExpectation<ErrorType extends ErrorConstructor | Error> = {
10
+ /** If true, the thrown error is not required to be a native error. */
11
+ any?: false;
12
+
10
13
  /** The thrown error must have a code that equals the given string or number. */
11
14
  code?: string | number;
12
15
 
@@ -23,10 +26,23 @@ export type ThrowsExpectation<ErrorType extends ErrorConstructor | Error> = {
23
26
  name?: string;
24
27
  };
25
28
 
29
+ export type ThrowsAnyExpectation = Omit<ThrowsExpectation<any>, 'any' | 'instanceOf' | 'is'> & {
30
+ /** If true, the thrown error is not required to be a native error. */
31
+ any: true;
32
+
33
+ /** The thrown error must be an instance of this constructor. */
34
+ instanceOf?: new (...args: any[]) => any;
35
+
36
+ /** The thrown error must be strictly equal to this value. */
37
+ is?: any;
38
+ };
39
+
26
40
  export type Assertions = {
27
41
  /**
28
42
  * Assert that `actual` is [truthy](https://developer.mozilla.org/en-US/docs/Glossary/Truthy), returning a boolean
29
43
  * indicating whether the assertion passed.
44
+ *
45
+ * Note: An `else` clause using this as a type guard will be subtly incorrect for `string` and `number` types and will not give `0` or `''` as a potential value in an `else` clause.
30
46
  */
31
47
  assert: AssertAssertion;
32
48
 
@@ -103,12 +119,12 @@ export type Assertions = {
103
119
  snapshot: SnapshotAssertion;
104
120
 
105
121
  /**
106
- * Assert that the function throws [an error](https://www.npmjs.com/package/is-error). If so, returns the error value.
122
+ * Assert that the function throws a native error. If so, returns the error value.
107
123
  */
108
124
  throws: ThrowsAssertion;
109
125
 
110
126
  /**
111
- * Assert that the async function throws [an error](https://www.npmjs.com/package/is-error), or the promise rejects
127
+ * Assert that the async function throws a native error, or the promise rejects
112
128
  * with one. If so, returns a promise for the error value, which must be awaited.
113
129
  */
114
130
  throwsAsync: ThrowsAsyncAssertion;
@@ -121,16 +137,24 @@ export type Assertions = {
121
137
  /**
122
138
  * Assert that `actual` is [truthy](https://developer.mozilla.org/en-US/docs/Glossary/Truthy), returning a boolean
123
139
  * indicating whether the assertion passed.
140
+ *
141
+ * Note: An `else` clause using this as a type guard will be subtly incorrect for `string` and `number` types and will not give `0` or `''` as a potential value in an `else` clause.
124
142
  */
125
143
  truthy: TruthyAssertion;
126
144
  };
127
145
 
146
+ type FalsyValue = false | 0 | 0n | '' | null | undefined; // eslint-disable-line @typescript-eslint/ban-types
147
+ type Falsy<T> = T extends Exclude<T, FalsyValue> ? (T extends number | string | bigint ? T & FalsyValue : never) : T;
148
+
128
149
  export type AssertAssertion = {
129
150
  /**
130
- * Assert that `actual` is [truthy](https://developer.mozilla.org/en-US/docs/Glossary/Truthy), returning a boolean
131
- * indicating whether the assertion passed.
151
+ * Assert that `actual` is [truthy](https://developer.mozilla.org/en-US/docs/Glossary/Truthy), returning `true` if the
152
+ * assertion passed and throwing otherwise.
153
+ *
154
+ * Note: An `else` clause using this as a type guard will be subtly incorrect for `string` and `number` types and will
155
+ * not give `0` or `''` as a potential value in an `else` clause.
132
156
  */
133
- (actual: any, message?: string): boolean;
157
+ <T>(actual: T, message?: string): actual is T extends Falsy<T> ? never : T;
134
158
 
135
159
  /** Skip this assertion. */
136
160
  skip(actual: any, message?: string): void;
@@ -139,19 +163,19 @@ export type AssertAssertion = {
139
163
  export type DeepEqualAssertion = {
140
164
  /**
141
165
  * Assert that `actual` is [deeply equal](https://github.com/concordancejs/concordance#comparison-details) to
142
- * `expected`, returning a boolean indicating whether the assertion passed.
166
+ * `expected`, returning `true` if the assertion passed and throwing otherwise.
143
167
  */
144
168
  <Actual, Expected extends Actual>(actual: Actual, expected: Expected, message?: string): actual is Expected;
145
169
 
146
170
  /**
147
171
  * Assert that `actual` is [deeply equal](https://github.com/concordancejs/concordance#comparison-details) to
148
- * `expected`, returning a boolean indicating whether the assertion passed.
172
+ * `expected`, returning `true` if the assertion passed and throwing otherwise.
149
173
  */
150
174
  <Actual extends Expected, Expected>(actual: Actual, expected: Expected, message?: string): expected is Actual;
151
175
 
152
176
  /**
153
177
  * Assert that `actual` is [deeply equal](https://github.com/concordancejs/concordance#comparison-details) to
154
- * `expected`, returning a boolean indicating whether the assertion passed.
178
+ * `expected`, returning `true` if the assertion passed and throwing otherwise.
155
179
  */
156
180
  <Actual, Expected>(actual: Actual, expected: Expected, message?: string): boolean;
157
181
 
@@ -161,7 +185,7 @@ export type DeepEqualAssertion = {
161
185
 
162
186
  export type LikeAssertion = {
163
187
  /**
164
- * Assert that `value` is like `selector`, returning a boolean indicating whether the assertion passed.
188
+ * Assert that `value` is like `selector`, returning `true` if the assertion passed and throwing otherwise.
165
189
  */
166
190
  <Expected extends Record<string, any>>(value: any, selector: Expected, message?: string): value is Expected;
167
191
 
@@ -170,8 +194,8 @@ export type LikeAssertion = {
170
194
  };
171
195
 
172
196
  export type FailAssertion = {
173
- /** Fail the test, always returning `false`. */
174
- (message?: string): boolean;
197
+ /** Fail the test. */
198
+ (message?: string): never;
175
199
 
176
200
  /** Skip this assertion. */
177
201
  skip(message?: string): void;
@@ -179,7 +203,7 @@ export type FailAssertion = {
179
203
 
180
204
  export type FalseAssertion = {
181
205
  /**
182
- * Assert that `actual` is strictly false, returning a boolean indicating whether the assertion passed.
206
+ * Assert that `actual` is strictly false, returning `true` if the assertion passed and throwing otherwise.
183
207
  */
184
208
  (actual: any, message?: string): actual is false;
185
209
 
@@ -189,10 +213,10 @@ export type FalseAssertion = {
189
213
 
190
214
  export type FalsyAssertion = {
191
215
  /**
192
- * Assert that `actual` is [falsy](https://developer.mozilla.org/en-US/docs/Glossary/Falsy), returning a boolean
193
- * indicating whether the assertion passed.
216
+ * Assert that `actual` is [falsy](https://developer.mozilla.org/en-US/docs/Glossary/Falsy), returning `true` if the
217
+ * assertion passed and throwing otherwise.
194
218
  */
195
- (actual: any, message?: string): boolean;
219
+ <T>(actual: T, message?: string): actual is Falsy<T>;
196
220
 
197
221
  /** Skip this assertion. */
198
222
  skip(actual: any, message?: string): void;
@@ -202,7 +226,7 @@ export type IsAssertion = {
202
226
  /**
203
227
  * Assert that `actual` is [the same
204
228
  * value](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/is) as `expected`,
205
- * returning a boolean indicating whether the assertion passed.
229
+ * returning `true` if the assertion passed and throwing otherwise.
206
230
  */
207
231
  <Actual, Expected extends Actual>(actual: Actual, expected: Expected, message?: string): actual is Expected;
208
232
 
@@ -214,9 +238,9 @@ export type NotAssertion = {
214
238
  /**
215
239
  * Assert that `actual` is not [the same
216
240
  * value](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/is) as `expected`,
217
- * returning a boolean indicating whether the assertion passed.
241
+ * returning `true` if the assertion passed and throwing otherwise.
218
242
  */
219
- <Actual, Expected>(actual: Actual, expected: Expected, message?: string): boolean;
243
+ <Actual, Expected>(actual: Actual, expected: Expected, message?: string): true;
220
244
 
221
245
  /** Skip this assertion. */
222
246
  skip(actual: any, expected: any, message?: string): void;
@@ -225,9 +249,9 @@ export type NotAssertion = {
225
249
  export type NotDeepEqualAssertion = {
226
250
  /**
227
251
  * Assert that `actual` is not [deeply equal](https://github.com/concordancejs/concordance#comparison-details) to
228
- * `expected`, returning a boolean indicating whether the assertion passed.
252
+ * `expected`, returning `true` if the assertion passed and throwing otherwise.
229
253
  */
230
- <Actual, Expected>(actual: Actual, expected: Expected, message?: string): boolean;
254
+ <Actual, Expected>(actual: Actual, expected: Expected, message?: string): true;
231
255
 
232
256
  /** Skip this assertion. */
233
257
  skip(actual: any, expected: any, message?: string): void;
@@ -235,29 +259,40 @@ export type NotDeepEqualAssertion = {
235
259
 
236
260
  export type NotRegexAssertion = {
237
261
  /**
238
- * Assert that `string` does not match the regular expression, returning a boolean indicating whether the assertion
239
- * passed.
262
+ * Assert that `string` does not match the regular expression, returning `true` if the assertion passed and throwing
263
+ * otherwise.
240
264
  */
241
- (string: string, regex: RegExp, message?: string): boolean;
265
+ (string: string, regex: RegExp, message?: string): true;
242
266
 
243
267
  /** Skip this assertion. */
244
268
  skip(string: string, regex: RegExp, message?: string): void;
245
269
  };
246
270
 
247
271
  export type NotThrowsAssertion = {
248
- /** Assert that the function does not throw. */
249
- (fn: () => any, message?: string): void;
272
+ /**
273
+ * Assert that the function does not throw, returning `true` if the assertion passed and throwing otherwise.
274
+ */
275
+ (fn: () => any, message?: string): true;
250
276
 
251
277
  /** Skip this assertion. */
252
278
  skip(fn: () => any, message?: string): void;
253
279
  };
254
280
 
255
281
  export type NotThrowsAsyncAssertion = {
256
- /** Assert that the async function does not throw. You must await the result. */
257
- (fn: () => PromiseLike<any>, message?: string): Promise<void>;
282
+ /**
283
+ * Assert that the async function does not throw, returning a promise for `true` if the assertion passesd and a
284
+ * rejected promise otherwise.
285
+ *
286
+ * You must await the result.
287
+ */
288
+ (fn: () => PromiseLike<any>, message?: string): Promise<true>;
258
289
 
259
- /** Assert that the promise does not reject. You must await the result. */
260
- (promise: PromiseLike<any>, message?: string): Promise<void>;
290
+ /** Assert that the promise does not reject, returning a promise for `true` if the assertion passesd and a
291
+ * rejected promise otherwise.
292
+ *
293
+ * You must await the result.
294
+ */
295
+ (promise: PromiseLike<any>, message?: string): Promise<true>;
261
296
 
262
297
  /** Skip this assertion. */
263
298
  skip(nonThrower: any, message?: string): void;
@@ -265,7 +300,7 @@ export type NotThrowsAsyncAssertion = {
265
300
 
266
301
  export type PassAssertion = {
267
302
  /** Count a passing assertion, always returning `true`. */
268
- (message?: string): boolean;
303
+ (message?: string): true;
269
304
 
270
305
  /** Skip this assertion. */
271
306
  skip(message?: string): void;
@@ -273,9 +308,10 @@ export type PassAssertion = {
273
308
 
274
309
  export type RegexAssertion = {
275
310
  /**
276
- * Assert that `string` matches the regular expression, returning a boolean indicating whether the assertion passed.
311
+ * Assert that `string` matches the regular expression, returning `true` if the assertion passed and throwing
312
+ * otherwise.
277
313
  */
278
- (string: string, regex: RegExp, message?: string): boolean;
314
+ (string: string, regex: RegExp, message?: string): true;
279
315
 
280
316
  /** Skip this assertion. */
281
317
  skip(string: string, regex: RegExp, message?: string): void;
@@ -286,8 +322,10 @@ export type SnapshotAssertion = {
286
322
  * Assert that `expected` is [deeply equal](https://github.com/concordancejs/concordance#comparison-details) to a
287
323
  * previously recorded [snapshot](https://github.com/concordancejs/concordance#serialization-details), or if
288
324
  * necessary record a new snapshot.
325
+ *
326
+ * Returns `true` if the assertion passed and throws otherwise.
289
327
  */
290
- (expected: any, message?: string): void;
328
+ (expected: any, message?: string): true;
291
329
 
292
330
  /** Skip this assertion. */
293
331
  skip(expected: any, message?: string): void;
@@ -295,10 +333,16 @@ export type SnapshotAssertion = {
295
333
 
296
334
  export type ThrowsAssertion = {
297
335
  /**
298
- * Assert that the function throws [an error](https://www.npmjs.com/package/is-error). If so, returns the error value.
299
- * The error must satisfy all expectations. Returns undefined when the assertion fails.
336
+ * Assert that the function throws a native error. The error must satisfy all expectations. Returns the error value if
337
+ * the assertion passes and throws otherwise.
300
338
  */
301
- <ErrorType extends ErrorConstructor | Error>(fn: () => any, expectations?: ThrowsExpectation<ErrorType>, message?: string): ThrownError<ErrorType> | undefined;
339
+ <ErrorType extends ErrorConstructor | Error>(fn: () => any, expectations?: ThrowsExpectation<ErrorType>, message?: string): ThrownError<ErrorType>;
340
+
341
+ /**
342
+ * Assert that the function throws. The error must satisfy all expectations. Returns the error value if the assertion
343
+ * passes and throws otherwise.
344
+ */
345
+ (fn: () => any, expectations?: ThrowsAnyExpectation, message?: string): unknown;
302
346
 
303
347
  /** Skip this assertion. */
304
348
  skip(fn: () => any, expectations?: any, message?: string): void;
@@ -306,17 +350,28 @@ export type ThrowsAssertion = {
306
350
 
307
351
  export type ThrowsAsyncAssertion = {
308
352
  /**
309
- * Assert that the async function throws [an error](https://www.npmjs.com/package/is-error). If so, returns the error
310
- * value. Returns undefined when the assertion fails. You must await the result. The error must satisfy all expectations.
353
+ * Assert that the async function throws a native error. You must await the result. The error must satisfy all
354
+ * expectations. Returns a promise for the error value if the assertion passes and a rejected promise otherwise.
355
+ */
356
+ <ErrorType extends ErrorConstructor | Error>(fn: () => PromiseLike<any>, expectations?: ThrowsExpectation<ErrorType>, message?: string): Promise<ThrownError<ErrorType>>;
357
+
358
+ /**
359
+ * Assert that the promise rejects with a native error. You must await the result. The error must satisfy all
360
+ * expectations. Returns a promise for the error value if the assertion passes and a rejected promise otherwise.
311
361
  */
312
- <ErrorType extends ErrorConstructor | Error>(fn: () => PromiseLike<any>, expectations?: ThrowsExpectation<ErrorType>, message?: string): Promise<ThrownError<ErrorType> | undefined>;
362
+ <ErrorType extends ErrorConstructor | Error>(promise: PromiseLike<any>, expectations?: ThrowsExpectation<ErrorType>, message?: string): Promise<ThrownError<ErrorType>>;
313
363
 
314
364
  /**
315
- * Assert that the promise rejects with [an error](https://www.npmjs.com/package/is-error). If so, returns the
316
- * rejection reason. Returns undefined when the assertion fails. You must await the result. The error must satisfy all
317
- * expectations.
365
+ * Assert that the async function throws. You must await the result. The error must satisfy all expectations. Returns
366
+ * a promise for the error value if the assertion passes and a rejected promise otherwise.
318
367
  */
319
- <ErrorType extends ErrorConstructor | Error>(promise: PromiseLike<any>, expectations?: ThrowsExpectation<ErrorType>, message?: string): Promise<ThrownError<ErrorType> | undefined>;
368
+ (fn: () => PromiseLike<any>, expectations?: ThrowsAnyExpectation, message?: string): Promise<unknown>;
369
+
370
+ /**
371
+ * Assert that the promise rejects. You must await the result. The error must satisfy all expectations. Returns a
372
+ * promise for the error value if the assertion passes and a rejected promise otherwise.
373
+ */
374
+ (promise: PromiseLike<any>, expectations?: ThrowsAnyExpectation, message?: string): Promise<unknown>;
320
375
 
321
376
  /** Skip this assertion. */
322
377
  skip(thrower: any, expectations?: any, message?: string): void;
@@ -324,7 +379,7 @@ export type ThrowsAsyncAssertion = {
324
379
 
325
380
  export type TrueAssertion = {
326
381
  /**
327
- * Assert that `actual` is strictly true, returning a boolean indicating whether the assertion passed.
382
+ * Assert that `actual` is strictly true, returning `true` if the assertion passed and throwing otherwise.
328
383
  */
329
384
  (actual: any, message?: string): actual is true;
330
385
 
@@ -334,10 +389,13 @@ export type TrueAssertion = {
334
389
 
335
390
  export type TruthyAssertion = {
336
391
  /**
337
- * Assert that `actual` is [truthy](https://developer.mozilla.org/en-US/docs/Glossary/Truthy), returning a boolean
338
- * indicating whether the assertion passed.
392
+ * Assert that `actual` is [truthy](https://developer.mozilla.org/en-US/docs/Glossary/Truthy), returning `true` if the
393
+ * assertion passed and throwing otherwise.
394
+ *
395
+ * Note: An `else` clause using this as a type guard will be subtly incorrect for `string` and `number` types and will
396
+ * not give `0` or `''` as a potential value in an `else` clause.
339
397
  */
340
- (actual: any, message?: string): boolean;
398
+ <T>(actual: T, message?: string): actual is T extends Falsy<T> ? never : T;
341
399
 
342
400
  /** Skip this assertion. */
343
401
  skip(actual: any, message?: string): void;
@@ -1,5 +1,3 @@
1
- import type {URL} from 'node:url';
2
-
3
1
  export namespace SharedWorker {
4
2
  export type ProtocolIdentifier = 'ava-4';
5
3
 
@@ -0,0 +1,143 @@
1
+ type ErrorSource = {
2
+ isDependency: boolean;
3
+ isWithinProject: boolean;
4
+ file: string;
5
+ line: number;
6
+ };
7
+
8
+ type SerializedErrorBase = {
9
+ message: string;
10
+ name: string;
11
+ originalError: unknown;
12
+ stack: string;
13
+ };
14
+
15
+ type AggregateSerializedError = SerializedErrorBase & {
16
+ type: 'aggregate';
17
+ errors: SerializedError[];
18
+ };
19
+
20
+ type NativeSerializedError = SerializedErrorBase & {
21
+ type: 'native';
22
+ source: ErrorSource | undefined;
23
+ };
24
+
25
+ type AvaSerializedError = SerializedErrorBase & {
26
+ type: 'ava';
27
+ assertion: string;
28
+ improperUsage: unknown | undefined;
29
+ formattedCause: unknown | undefined;
30
+ formattedDetails: unknown | unknown[];
31
+ source: ErrorSource | undefined;
32
+ };
33
+
34
+ type SerializedError = AggregateSerializedError | NativeSerializedError | AvaSerializedError;
35
+
36
+ export type StateChangeEvent = {
37
+ type: 'starting';
38
+ testFile: string;
39
+ } | {
40
+ type: 'stats';
41
+ stats: {
42
+ byFile: Map<string, {
43
+ declaredTests: number;
44
+ failedHooks: number;
45
+ failedTests: number;
46
+ internalErrors: number;
47
+ remainingTests: number;
48
+ passedKnownFailingTests: number;
49
+ passedTests: number;
50
+ selectedTests: number;
51
+ selectingLines: boolean;
52
+ skippedTests: number;
53
+ todoTests: number;
54
+ uncaughtExceptions: number;
55
+ unhandledRejections: number;
56
+ }>;
57
+ declaredTests: number;
58
+ failedHooks: number;
59
+ failedTests: number;
60
+ failedWorkers: number;
61
+ files: number;
62
+ parallelRuns: {
63
+ currentIndex: number;
64
+ totalRuns: number;
65
+ } | undefined;
66
+ finishedWorkers: number;
67
+ internalErrors: number;
68
+ remainingTests: number;
69
+ passedKnownFailingTests: number;
70
+ passedTests: number;
71
+ selectedTests: number;
72
+ sharedWorkerErrors: number;
73
+ skippedTests: number;
74
+ timedOutTests: number;
75
+ timeouts: number;
76
+ todoTests: number;
77
+ uncaughtExceptions: number;
78
+ unhandledRejections: number;
79
+ };
80
+ } | {
81
+ type: 'declared-test';
82
+ title: string;
83
+ knownFailing: boolean;
84
+ todo: boolean;
85
+ testFile: string;
86
+ } | {
87
+ type: 'selected-test';
88
+ title: string;
89
+ knownFailing: boolean;
90
+ skip: boolean;
91
+ todo: boolean;
92
+ testFile: string;
93
+ } | {
94
+ type: 'test-register-log-reference';
95
+ title: string;
96
+ logs: string[];
97
+ testFile: string;
98
+ } | {
99
+ type: 'test-passed';
100
+ title: string;
101
+ duration: number;
102
+ knownFailing: boolean;
103
+ logs: string[];
104
+ testFile: string;
105
+ } | {
106
+ type: 'test-failed';
107
+ title: string;
108
+ err: SerializedError;
109
+ duration: number;
110
+ knownFailing: boolean;
111
+ logs: string[];
112
+ testFile: string;
113
+ } | {
114
+ type: 'worker-finished';
115
+ forcedExit: boolean;
116
+ testFile: string;
117
+ } | {
118
+ type: 'worker-failed';
119
+ nonZeroExitCode?: boolean;
120
+ signal?: string;
121
+ err?: SerializedError;
122
+ } | {
123
+ type: 'touched-files';
124
+ files: {
125
+ changedFiles: string[];
126
+ temporaryFiles: string[];
127
+ };
128
+ } | {
129
+ type: 'worker-stdout';
130
+ chunk: Uint8Array;
131
+ testFile: string;
132
+ } | {
133
+ type: 'worker-stderr';
134
+ chunk: Uint8Array;
135
+ testFile: string;
136
+ } | {
137
+ type: 'timeout';
138
+ period: number;
139
+ pendingTests: Map<string, Set<string>>;
140
+ }
141
+ | {
142
+ type: 'end';
143
+ };
@@ -39,11 +39,16 @@ export type PlanFn = {
39
39
  skip(count: number): void;
40
40
  };
41
41
 
42
- /**
43
- * Set a timeout for the test, in milliseconds. The test will fail if the timeout is exceeded.
44
- * The timeout is reset each time an assertion is made.
45
- */
46
- export type TimeoutFn = (ms: number, message?: string) => void;
42
+ export type TimeoutFn = {
43
+ /**
44
+ * Set a timeout for the test, in milliseconds. The test will fail if the timeout is exceeded.
45
+ * The timeout is reset each time an assertion is made.
46
+ */
47
+ (ms: number, message?: string): void;
48
+
49
+ /** Clear the timeout and restore the default behavior. */
50
+ clear(): void;
51
+ };
47
52
 
48
53
  /** Declare a function to be run after the test has ended. */
49
54
  export type TeardownFn = (fn: (() => Promise<void>) | (() => void)) => void;
@@ -1,48 +0,0 @@
1
- import process from 'node:process';
2
-
3
- import channel from './channel.cjs';
4
-
5
- const seenDependencies = new Set();
6
- let newDependencies = [];
7
-
8
- function flush() {
9
- if (newDependencies.length === 0) {
10
- return;
11
- }
12
-
13
- channel.send({type: 'dependencies', dependencies: newDependencies});
14
- newDependencies = [];
15
- }
16
-
17
- function track(filename) {
18
- if (seenDependencies.has(filename)) {
19
- return;
20
- }
21
-
22
- if (newDependencies.length === 0) {
23
- process.nextTick(flush);
24
- }
25
-
26
- seenDependencies.add(filename);
27
- newDependencies.push(filename);
28
- }
29
-
30
- const tracker = {
31
- flush,
32
- track,
33
- install(extensions, testPath) {
34
- for (const ext of Object.keys(extensions)) {
35
- const wrappedHandler = extensions[ext];
36
-
37
- extensions[ext] = (module, filename) => {
38
- if (filename !== testPath) {
39
- track(filename);
40
- }
41
-
42
- wrappedHandler(module, filename);
43
- };
44
- }
45
- },
46
- };
47
-
48
- export default tracker;
File without changes
File without changes