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.
Files changed (70) hide show
  1. package/entrypoints/cli.mjs +4 -0
  2. package/{eslint-plugin-helper.js → entrypoints/eslint-plugin-helper.cjs} +20 -7
  3. package/entrypoints/main.cjs +2 -0
  4. package/entrypoints/main.mjs +1 -0
  5. package/entrypoints/plugin.cjs +2 -0
  6. package/entrypoints/plugin.mjs +4 -0
  7. package/index.d.ts +6 -709
  8. package/lib/api.js +95 -46
  9. package/lib/assert.js +122 -173
  10. package/lib/chalk.js +9 -14
  11. package/lib/cli.js +105 -97
  12. package/lib/code-excerpt.js +12 -17
  13. package/lib/concordance-options.js +30 -31
  14. package/lib/context-ref.js +3 -6
  15. package/lib/create-chain.js +32 -4
  16. package/lib/environment-variables.js +1 -4
  17. package/lib/eslint-plugin-helper-worker.js +16 -26
  18. package/lib/extensions.js +2 -2
  19. package/lib/fork.js +42 -83
  20. package/lib/glob-helpers.cjs +140 -0
  21. package/lib/globs.js +136 -163
  22. package/lib/{ipc-flow-control.js → ipc-flow-control.cjs} +1 -0
  23. package/lib/is-ci.js +4 -2
  24. package/lib/like-selector.js +7 -13
  25. package/lib/line-numbers.js +10 -17
  26. package/lib/load-config.js +62 -56
  27. package/lib/module-types.js +3 -3
  28. package/lib/node-arguments.js +4 -5
  29. package/lib/{now-and-timers.js → now-and-timers.cjs} +0 -0
  30. package/lib/parse-test-args.js +22 -11
  31. package/lib/pkg.cjs +2 -0
  32. package/lib/plugin-support/shared-worker-loader.js +45 -48
  33. package/lib/plugin-support/shared-workers.js +24 -43
  34. package/lib/provider-manager.js +20 -14
  35. package/lib/reporters/beautify-stack.js +6 -11
  36. package/lib/reporters/colors.js +40 -15
  37. package/lib/reporters/default.js +115 -350
  38. package/lib/reporters/format-serialized-error.js +7 -18
  39. package/lib/reporters/improper-usage-messages.js +8 -9
  40. package/lib/reporters/prefix-title.js +17 -15
  41. package/lib/reporters/tap.js +15 -16
  42. package/lib/run-status.js +25 -23
  43. package/lib/runner.js +138 -127
  44. package/lib/scheduler.js +42 -36
  45. package/lib/serialize-error.js +34 -34
  46. package/lib/snapshot-manager.js +83 -76
  47. package/lib/test.js +114 -195
  48. package/lib/watcher.js +65 -40
  49. package/lib/worker/base.js +48 -99
  50. package/lib/worker/channel.cjs +290 -0
  51. package/lib/worker/dependency-tracker.js +22 -22
  52. package/lib/worker/guard-environment.cjs +19 -0
  53. package/lib/worker/line-numbers.js +57 -19
  54. package/lib/worker/main.cjs +12 -0
  55. package/lib/worker/{options.js → options.cjs} +0 -0
  56. package/lib/worker/{plugin.js → plugin.cjs} +31 -16
  57. package/lib/worker/state.cjs +5 -0
  58. package/lib/worker/{utils.js → utils.cjs} +1 -1
  59. package/package.json +60 -68
  60. package/plugin.d.ts +51 -53
  61. package/readme.md +5 -12
  62. package/types/assertions.d.ts +327 -0
  63. package/types/subscribable.ts +6 -0
  64. package/types/test-fn.d.ts +231 -0
  65. package/types/try-fn.d.ts +58 -0
  66. package/cli.js +0 -11
  67. package/index.js +0 -8
  68. package/lib/worker/channel.js +0 -218
  69. package/lib/worker/main.js +0 -20
  70. package/plugin.js +0 -9
@@ -0,0 +1,327 @@
1
+ export type ErrorConstructor = new (...args: any[]) => Error;
2
+
3
+ /** Specify one or more expectations the thrown error must satisfy. */
4
+ export type ThrowsExpectation = {
5
+ /** The thrown error must have a code that equals the given string or number. */
6
+ code?: string | number;
7
+
8
+ /** The thrown error must be an instance of this constructor. */
9
+ instanceOf?: ErrorConstructor;
10
+
11
+ /** The thrown error must be strictly equal to this value. */
12
+ is?: Error;
13
+
14
+ /** The thrown error must have a message that equals the given string, or matches the regular expression. */
15
+ message?: string | RegExp;
16
+
17
+ /** The thrown error must have a name that equals the given string. */
18
+ name?: string;
19
+ };
20
+
21
+ export interface Assertions {
22
+ /**
23
+ * Assert that `actual` is [truthy](https://developer.mozilla.org/en-US/docs/Glossary/Truthy), returning a boolean
24
+ * indicating whether the assertion passed.
25
+ */
26
+ assert: AssertAssertion;
27
+
28
+ /**
29
+ * Assert that `actual` is [deeply equal](https://github.com/concordancejs/concordance#comparison-details) to
30
+ * `expected`, returning a boolean indicating whether the assertion passed.
31
+ */
32
+ deepEqual: DeepEqualAssertion;
33
+
34
+ /**
35
+ * Assert that `value` is like `selector`, returning a boolean indicating whether the assertion passed.
36
+ */
37
+ like: LikeAssertion;
38
+
39
+ /** Fail the test, always returning `false`. */
40
+ fail: FailAssertion;
41
+
42
+ /**
43
+ * Assert that `actual` is strictly false, returning a boolean indicating whether the assertion passed.
44
+ */
45
+ false: FalseAssertion;
46
+
47
+ /**
48
+ * Assert that `actual` is [falsy](https://developer.mozilla.org/en-US/docs/Glossary/Falsy), returning a boolean
49
+ * indicating whether the assertion passed.
50
+ */
51
+ falsy: FalsyAssertion;
52
+
53
+ /**
54
+ * Assert that `actual` is [the same
55
+ * value](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/is) as `expected`,
56
+ * returning a boolean indicating whether the assertion passed.
57
+ */
58
+ is: IsAssertion;
59
+
60
+ /**
61
+ * Assert that `actual` is not [the same
62
+ * value](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/is) as `expected`,
63
+ * returning a boolean indicating whether the assertion passed.
64
+ */
65
+ not: NotAssertion;
66
+
67
+ /**
68
+ * Assert that `actual` is not [deeply equal](https://github.com/concordancejs/concordance#comparison-details) to
69
+ * `expected`, returning a boolean indicating whether the assertion passed.
70
+ */
71
+ notDeepEqual: NotDeepEqualAssertion;
72
+
73
+ /**
74
+ * Assert that `string` does not match the regular expression, returning a boolean indicating whether the assertion
75
+ * passed.
76
+ */
77
+ notRegex: NotRegexAssertion;
78
+
79
+ /** Assert that the function does not throw. */
80
+ notThrows: NotThrowsAssertion;
81
+
82
+ /** Assert that the async function does not throw, or that the promise does not reject. Must be awaited. */
83
+ notThrowsAsync: NotThrowsAsyncAssertion;
84
+
85
+ /** Count a passing assertion, always returning `true`. */
86
+ pass: PassAssertion;
87
+
88
+ /**
89
+ * Assert that `string` matches the regular expression, returning a boolean indicating whether the assertion passed.
90
+ */
91
+ regex: RegexAssertion;
92
+
93
+ /**
94
+ * Assert that `expected` is [deeply equal](https://github.com/concordancejs/concordance#comparison-details) to a
95
+ * previously recorded [snapshot](https://github.com/concordancejs/concordance#serialization-details), or if
96
+ * necessary record a new snapshot.
97
+ */
98
+ snapshot: SnapshotAssertion;
99
+
100
+ /**
101
+ * Assert that the function throws [an error](https://www.npmjs.com/package/is-error). If so, returns the error value.
102
+ */
103
+ throws: ThrowsAssertion;
104
+
105
+ /**
106
+ * Assert that the async function throws [an error](https://www.npmjs.com/package/is-error), or the promise rejects
107
+ * with one. If so, returns a promise for the error value, which must be awaited.
108
+ */
109
+ throwsAsync: ThrowsAsyncAssertion;
110
+
111
+ /**
112
+ * Assert that `actual` is strictly true, returning a boolean indicating whether the assertion passed.
113
+ */
114
+ true: TrueAssertion;
115
+
116
+ /**
117
+ * Assert that `actual` is [truthy](https://developer.mozilla.org/en-US/docs/Glossary/Truthy), returning a boolean
118
+ * indicating whether the assertion passed.
119
+ */
120
+ truthy: TruthyAssertion;
121
+ }
122
+
123
+ export interface AssertAssertion {
124
+ /**
125
+ * Assert that `actual` is [truthy](https://developer.mozilla.org/en-US/docs/Glossary/Truthy), returning a boolean
126
+ * indicating whether the assertion passed.
127
+ */
128
+ (actual: any, message?: string): boolean;
129
+
130
+ /** Skip this assertion. */
131
+ skip(actual: any, message?: string): void;
132
+ }
133
+
134
+ export interface DeepEqualAssertion {
135
+ /**
136
+ * Assert that `actual` is [deeply equal](https://github.com/concordancejs/concordance#comparison-details) to
137
+ * `expected`, returning a boolean indicating whether the assertion passed.
138
+ */
139
+ <Actual, Expected extends Actual>(actual: Actual, expected: Expected, message?: string): actual is Expected;
140
+
141
+ /** Skip this assertion. */
142
+ skip(actual: any, expected: any, message?: string): void;
143
+ }
144
+
145
+ export interface LikeAssertion {
146
+ /**
147
+ * Assert that `value` is like `selector`, returning a boolean indicating whether the assertion passed.
148
+ */
149
+ <Expected extends Record<string, any>>(value: any, selector: Expected, message?: string): value is Expected;
150
+
151
+ /** Skip this assertion. */
152
+ skip(value: any, selector: any, message?: string): void;
153
+ }
154
+
155
+ export interface FailAssertion {
156
+ /** Fail the test, always returning `false`. */
157
+ (message?: string): boolean;
158
+
159
+ /** Skip this assertion. */
160
+ skip(message?: string): void;
161
+ }
162
+
163
+ export interface FalseAssertion {
164
+ /**
165
+ * Assert that `actual` is strictly false, returning a boolean indicating whether the assertion passed.
166
+ */
167
+ (actual: any, message?: string): actual is false;
168
+
169
+ /** Skip this assertion. */
170
+ skip(actual: any, message?: string): void;
171
+ }
172
+
173
+ export interface FalsyAssertion {
174
+ /**
175
+ * Assert that `actual` is [falsy](https://developer.mozilla.org/en-US/docs/Glossary/Falsy), returning a boolean
176
+ * indicating whether the assertion passed.
177
+ */
178
+ (actual: any, message?: string): boolean;
179
+
180
+ /** Skip this assertion. */
181
+ skip(actual: any, message?: string): void;
182
+ }
183
+
184
+ export interface IsAssertion {
185
+ /**
186
+ * Assert that `actual` is [the same
187
+ * value](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/is) as `expected`,
188
+ * returning a boolean indicating whether the assertion passed.
189
+ */
190
+ <Actual, Expected extends Actual>(actual: Actual, expected: Expected, message?: string): actual is Expected;
191
+
192
+ /** Skip this assertion. */
193
+ skip(actual: any, expected: any, message?: string): void;
194
+ }
195
+
196
+ export interface NotAssertion {
197
+ /**
198
+ * Assert that `actual` is not [the same
199
+ * value](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/is) as `expected`,
200
+ * returning a boolean indicating whether the assertion passed.
201
+ */
202
+ <Actual, Expected>(actual: Actual, expected: Expected, message?: string): boolean;
203
+
204
+ /** Skip this assertion. */
205
+ skip(actual: any, expected: any, message?: string): void;
206
+ }
207
+
208
+ export interface NotDeepEqualAssertion {
209
+ /**
210
+ * Assert that `actual` is not [deeply equal](https://github.com/concordancejs/concordance#comparison-details) to
211
+ * `expected`, returning a boolean indicating whether the assertion passed.
212
+ */
213
+ <Actual, Expected>(actual: Actual, expected: Expected, message?: string): boolean;
214
+
215
+ /** Skip this assertion. */
216
+ skip(actual: any, expected: any, message?: string): void;
217
+ }
218
+
219
+ export interface NotRegexAssertion {
220
+ /**
221
+ * Assert that `string` does not match the regular expression, returning a boolean indicating whether the assertion
222
+ * passed.
223
+ */
224
+ (string: string, regex: RegExp, message?: string): boolean;
225
+
226
+ /** Skip this assertion. */
227
+ skip(string: string, regex: RegExp, message?: string): void;
228
+ }
229
+
230
+ export interface NotThrowsAssertion {
231
+ /** Assert that the function does not throw. */
232
+ (fn: () => any, message?: string): void;
233
+
234
+ /** Skip this assertion. */
235
+ skip(fn: () => any, message?: string): void;
236
+ }
237
+
238
+ export interface NotThrowsAsyncAssertion {
239
+ /** Assert that the async function does not throw. You must await the result. */
240
+ (fn: () => PromiseLike<any>, message?: string): Promise<void>;
241
+
242
+ /** Assert that the promise does not reject. You must await the result. */
243
+ (promise: PromiseLike<any>, message?: string): Promise<void>; // eslint-disable-line @typescript-eslint/unified-signatures
244
+
245
+ /** Skip this assertion. */
246
+ skip(nonThrower: any, message?: string): void;
247
+ }
248
+
249
+ export interface PassAssertion {
250
+ /** Count a passing assertion, always returning `true`. */
251
+ (message?: string): boolean;
252
+
253
+ /** Skip this assertion. */
254
+ skip(message?: string): void;
255
+ }
256
+
257
+ export interface RegexAssertion {
258
+ /**
259
+ * Assert that `string` matches the regular expression, returning a boolean indicating whether the assertion passed.
260
+ */
261
+ (string: string, regex: RegExp, message?: string): boolean;
262
+
263
+ /** Skip this assertion. */
264
+ skip(string: string, regex: RegExp, message?: string): void;
265
+ }
266
+
267
+ export interface SnapshotAssertion {
268
+ /**
269
+ * Assert that `expected` is [deeply equal](https://github.com/concordancejs/concordance#comparison-details) to a
270
+ * previously recorded [snapshot](https://github.com/concordancejs/concordance#serialization-details), or if
271
+ * necessary record a new snapshot.
272
+ */
273
+ (expected: any, message?: string): void;
274
+
275
+ /** Skip this assertion. */
276
+ skip(expected: any, message?: string): void;
277
+ }
278
+
279
+ export interface ThrowsAssertion {
280
+ /**
281
+ * Assert that the function throws [an error](https://www.npmjs.com/package/is-error). If so, returns the error value.
282
+ * The error must satisfy all expectations. Returns undefined when the assertion fails.
283
+ */
284
+ <ThrownError extends Error>(fn: () => any, expectations?: ThrowsExpectation, message?: string): ThrownError | undefined;
285
+
286
+ /** Skip this assertion. */
287
+ skip(fn: () => any, expectations?: any, message?: string): void;
288
+ }
289
+
290
+ export interface ThrowsAsyncAssertion {
291
+ /**
292
+ * Assert that the async function throws [an error](https://www.npmjs.com/package/is-error). If so, returns the error
293
+ * value. Returns undefined when the assertion fails. You must await the result. The error must satisfy all expectations.
294
+ */
295
+ <ThrownError extends Error>(fn: () => PromiseLike<any>, expectations?: ThrowsExpectation, message?: string): Promise<ThrownError | undefined>;
296
+
297
+ /**
298
+ * Assert that the promise rejects with [an error](https://www.npmjs.com/package/is-error). If so, returns the
299
+ * rejection reason. Returns undefined when the assertion fails. You must await the result. The error must satisfy all
300
+ * expectations.
301
+ */
302
+ <ThrownError extends Error>(promise: PromiseLike<any>, expectations?: ThrowsExpectation, message?: string): Promise<ThrownError | undefined>; // eslint-disable-line @typescript-eslint/unified-signatures
303
+
304
+ /** Skip this assertion. */
305
+ skip(thrower: any, expectations?: any, message?: string): void;
306
+ }
307
+
308
+ export interface TrueAssertion {
309
+ /**
310
+ * Assert that `actual` is strictly true, returning a boolean indicating whether the assertion passed.
311
+ */
312
+ (actual: any, message?: string): actual is true;
313
+
314
+ /** Skip this assertion. */
315
+ skip(actual: any, message?: string): void;
316
+ }
317
+
318
+ export interface TruthyAssertion {
319
+ /**
320
+ * Assert that `actual` is [truthy](https://developer.mozilla.org/en-US/docs/Glossary/Truthy), returning a boolean
321
+ * indicating whether the assertion passed.
322
+ */
323
+ (actual: any, message?: string): boolean;
324
+
325
+ /** Skip this assertion. */
326
+ skip(actual: any, message?: string): void;
327
+ }
@@ -0,0 +1,6 @@
1
+ export interface Subscribable {
2
+ subscribe(observer: {
3
+ error(error: any): void;
4
+ complete(): void;
5
+ }): void;
6
+ }
@@ -0,0 +1,231 @@
1
+ import type {Assertions} from './assertions';
2
+ import type {Subscribable} from './subscribable';
3
+ import type {TryFn} from './try-fn';
4
+
5
+ /** The `t` value passed to test & hook implementations. */
6
+ export interface ExecutionContext<Context = unknown> extends Assertions {
7
+ /** Test context, shared with hooks. */
8
+ context: Context;
9
+
10
+ /** Title of the test or hook. */
11
+ readonly title: string;
12
+
13
+ /** Whether the test has passed. Only accurate in afterEach hooks. */
14
+ readonly passed: boolean;
15
+
16
+ readonly log: LogFn;
17
+ readonly plan: PlanFn;
18
+ readonly teardown: TeardownFn;
19
+ readonly timeout: TimeoutFn;
20
+ readonly try: TryFn<Context>;
21
+ }
22
+
23
+ export interface LogFn {
24
+ /** Log one or more values. */
25
+ (...values: any[]): void;
26
+
27
+ /** Skip logging. */
28
+ skip(...values: any[]): void;
29
+ }
30
+
31
+ export interface PlanFn {
32
+ /**
33
+ * Plan how many assertion there are in the test. The test will fail if the actual assertion count doesn't match the
34
+ * number of planned assertions. See [assertion planning](https://github.com/avajs/ava#assertion-planning).
35
+ */
36
+ (count: number): void;
37
+
38
+ /** Don't plan assertions. */
39
+ skip(count: number): void;
40
+ }
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;
47
+
48
+ /** Declare a function to be run after the test has ended. */
49
+ export type TeardownFn = (fn: () => void) => void;
50
+
51
+ export type ImplementationFn<Args extends unknown[], Context = unknown> =
52
+ ((t: ExecutionContext<Context>, ...args: Args) => PromiseLike<void>) |
53
+ ((t: ExecutionContext<Context>, ...args: Args) => Subscribable) |
54
+ ((t: ExecutionContext<Context>, ...args: Args) => void);
55
+
56
+ export type TitleFn<Args extends unknown[]> = (providedTitle: string | undefined, ...args: Args) => string;
57
+
58
+ /** A reusable test or hook implementation. */
59
+ export type Macro<Args extends unknown[], Context = unknown> = {
60
+ /** The function that is executed when the macro is used. */
61
+ readonly exec: ImplementationFn<Args, Context>;
62
+
63
+ /** Generates a test title when this macro is used. */
64
+ readonly title?: TitleFn<Args>;
65
+ };
66
+
67
+ /** A test or hook implementation. */
68
+ export type Implementation<Args extends unknown[], Context = unknown> = ImplementationFn<Args, Context> | Macro<Args, Context>;
69
+
70
+ export interface TestFn<Context = unknown> {
71
+ /** Declare a concurrent test. Additional arguments are passed to the implementation or macro. */
72
+ <Args extends unknown[]>(title: string, implementation: Implementation<Args, Context>, ...args: Args): void;
73
+
74
+ /**
75
+ * Declare a concurrent test that uses a macro. Additional arguments are passed to the macro.
76
+ * The macro is responsible for generating a unique test title.
77
+ */
78
+ <Args extends unknown[]>(macro: Macro<Args, Context>, ...args: Args): void;
79
+
80
+ after: AfterFn<Context>;
81
+ afterEach: AfterFn<Context>;
82
+ before: BeforeFn<Context>;
83
+ beforeEach: BeforeFn<Context>;
84
+ failing: FailingFn<Context>;
85
+ macro: MacroFn<Context>;
86
+ meta: Meta;
87
+ only: OnlyFn<Context>;
88
+ serial: SerialFn<Context>;
89
+ skip: SkipFn<Context>;
90
+ todo: TodoFn;
91
+ }
92
+
93
+ export interface AfterFn<Context = unknown> {
94
+ /**
95
+ * Declare a hook that is run once, after all tests have passed.
96
+ * Additional arguments are passed to the implementation or macro.
97
+ */
98
+ <Args extends unknown[]>(title: string, implementation: Implementation<Args, Context>, ...args: Args): void;
99
+
100
+ /**
101
+ * Declare a hook that is run once, after all tests have passed.
102
+ * Additional arguments are passed to the implementation or macro.
103
+ */
104
+ <Args extends unknown[]>(implementation: Implementation<Args, Context>, ...args: Args): void;
105
+
106
+ always: AlwaysInterface<Context>;
107
+ skip: HookSkipFn<Context>;
108
+ }
109
+
110
+ export interface AlwaysInterface<Context = unknown> {
111
+ /**
112
+ * Declare a hook that is run once, after all tests are done.
113
+ * Additional arguments are passed to the implementation or macro.
114
+ */
115
+ <Args extends unknown[]>(title: string, implementation: Implementation<Args, Context>, ...args: Args): void;
116
+
117
+ /**
118
+ * Declare a hook that is run once, after all tests are done.
119
+ * Additional arguments are passed to the implementation or macro.
120
+ */
121
+ <Args extends unknown[]>(implementation: Implementation<Args, Context>, ...args: Args): void;
122
+
123
+ skip: HookSkipFn<Context>;
124
+ }
125
+
126
+ export interface BeforeFn<Context = unknown> {
127
+ /**
128
+ * Declare a hook that is run once, before all tests.
129
+ * Additional arguments are passed to the implementation or macro.
130
+ */
131
+ <Args extends unknown[]>(title: string, implementation: Implementation<Args, Context>, ...args: Args): void;
132
+
133
+ /**
134
+ * Declare a hook that is run once, before all tests.
135
+ * Additional arguments are passed to the implementation or macro.
136
+ */
137
+ <Args extends unknown[]>(implementation: Implementation<Args, Context>, ...args: Args): void;
138
+
139
+ skip: HookSkipFn<Context>;
140
+ }
141
+
142
+ export interface FailingFn<Context = unknown> {
143
+ /**
144
+ * Declare a concurrent test that is expected to fail.
145
+ * Additional arguments are passed to the implementation or macro.
146
+ */
147
+ <Args extends unknown[]>(title: string, implementation: Implementation<Args, Context>, ...args: Args): void;
148
+
149
+ /**
150
+ * Declare a concurrent test, using a macro, that is expected to fail.
151
+ * Additional arguments are passed to the macro. The macro is responsible for generating a unique test title.
152
+ */
153
+ <Args extends unknown[]>(macro: Macro<Args, Context>, ...args: Args): void;
154
+
155
+ only: OnlyFn<Context>;
156
+ skip: SkipFn<Context>;
157
+ }
158
+
159
+ export interface HookSkipFn<Context = unknown> {
160
+ /** Skip this hook. */
161
+ <Args extends unknown[]>(title: string, implementation: Implementation<Args, Context>, ...args: Args): void;
162
+
163
+ /** Skip this hook. */
164
+ <Args extends unknown[]>(implementation: Implementation<Args, Context>, ...args: Args): void;
165
+ }
166
+
167
+ export interface OnlyFn<Context = unknown> {
168
+ /**
169
+ * Declare a test. Only this test and others declared with `.only()` are run.
170
+ * Additional arguments are passed to the implementation or macro.
171
+ */
172
+ <Args extends unknown[]>(title: string, implementation: Implementation<Args, Context>, ...args: Args): void;
173
+
174
+ /**
175
+ * Declare a test that uses a macro. Only this test and others declared with `.only()` are run.
176
+ * Additional arguments are passed to the macro. The macro is responsible for generating a unique test title.
177
+ */
178
+ <Args extends unknown[]>(macro: Macro<Args, Context>, ...args: Args): void;
179
+ }
180
+
181
+ export interface SerialFn<Context = unknown> {
182
+ /** Declare a serial test. Additional arguments are passed to the implementation or macro. */
183
+ <Args extends unknown[]>(title: string, implementation: Implementation<Args, Context>, ...args: Args): void;
184
+
185
+ /**
186
+ * Declare a serial test that uses a macro. The macro is responsible for generating a unique test title.
187
+ */
188
+ <Args extends unknown[]>(macro: Macro<Args, Context>, ...args: Args): void;
189
+
190
+ after: AfterFn<Context>;
191
+ afterEach: AfterFn<Context>;
192
+ before: BeforeFn<Context>;
193
+ beforeEach: BeforeFn<Context>;
194
+ failing: FailingFn<Context>;
195
+ only: OnlyFn<Context>;
196
+ skip: SkipFn<Context>;
197
+ todo: TodoFn;
198
+ }
199
+
200
+ export interface SkipFn<Context = unknown> {
201
+ /** Skip this test. */
202
+ <Args extends unknown[]>(title: string, implementation: Implementation<Args, Context>, ...args: Args): void;
203
+
204
+ /** Skip this test. */
205
+ <Args extends unknown[]>(macro: Macro<Args, Context>, ...args: Args): void;
206
+ }
207
+
208
+ /** Declare a test that should be implemented later. */
209
+ export type TodoFn = (title: string) => void;
210
+
211
+ export type MacroDeclarationOptions<Args extends unknown[], Context = unknown> = {
212
+ /** The function that is executed when the macro is used. */
213
+ exec: ImplementationFn<Args, Context>;
214
+
215
+ /** The function responsible for generating a unique title when the macro is used. */
216
+ title: TitleFn<Args>;
217
+ };
218
+
219
+ export interface MacroFn<Context = unknown> {
220
+ /** Declare a reusable test implementation. */
221
+ <Args extends unknown[]>(/** The function that is executed when the macro is used. */ exec: ImplementationFn<Args, Context>): Macro<Args, Context>;
222
+ <Args extends unknown[]>(declaration: MacroDeclarationOptions<Args, Context>): Macro<Args, Context>; // eslint-disable-line @typescript-eslint/unified-signatures
223
+ }
224
+
225
+ export interface Meta {
226
+ /** Path to the test file being executed. */
227
+ file: string;
228
+
229
+ /** Directory where snapshots are stored. */
230
+ snapshotDirectory: string;
231
+ }
@@ -0,0 +1,58 @@
1
+ import type {Implementation} from './test-fn';
2
+
3
+ export type CommitDiscardOptions = {
4
+ /**
5
+ * Whether the logs should be included in those of the parent test.
6
+ */
7
+ retainLogs?: boolean;
8
+ };
9
+
10
+ export interface AssertionError extends Error {}
11
+
12
+ export interface TryResult {
13
+ /**
14
+ * Title of the attempt, helping you tell attempts aparts.
15
+ */
16
+ title: string;
17
+
18
+ /**
19
+ * Indicates whether all assertions passed, or at least one failed.
20
+ */
21
+ passed: boolean;
22
+
23
+ /**
24
+ * Errors raised for each failed assertion.
25
+ */
26
+ errors: AssertionError[];
27
+
28
+ /**
29
+ * Logs created during the attempt using `t.log()`. Contains formatted values.
30
+ */
31
+ logs: string[];
32
+
33
+ /**
34
+ * Commit the attempt. Counts as one assertion for the plan count. If the
35
+ * attempt failed, calling this will also cause your test to fail.
36
+ */
37
+ commit(options?: CommitDiscardOptions): void;
38
+
39
+ /**
40
+ * Discard the attempt.
41
+ */
42
+ discard(options?: CommitDiscardOptions): void;
43
+ }
44
+
45
+ export interface TryFn<Context = unknown> {
46
+ /**
47
+ * Attempt to run some assertions. The result must be explicitly committed or discarded or else
48
+ * the test will fail. The title may help distinguish attempts from one another.
49
+ */
50
+ <Args extends unknown[]>(title: string, fn: Implementation<Args, Context>, ...args: Args): Promise<TryResult>;
51
+
52
+ /**
53
+ * Attempt to run some assertions. The result must be explicitly committed or discarded or else
54
+ * the test will fail.
55
+ */
56
+ <Args extends unknown[]>(fn: Implementation<Args, Context>, ...args: Args): Promise<TryResult>;
57
+ }
58
+
package/cli.js DELETED
@@ -1,11 +0,0 @@
1
- #!/usr/bin/env node
2
- 'use strict';
3
- const debug = require('debug')('ava');
4
- const importLocal = require('import-local');
5
-
6
- // Prefer the local installation of AVA
7
- if (importLocal(__filename)) {
8
- debug('Using local install of AVA');
9
- } else {
10
- require('./lib/cli').run();
11
- }
package/index.js DELETED
@@ -1,8 +0,0 @@
1
- 'use strict';
2
-
3
- // Ensure the same AVA install is loaded by the test file as by the test worker
4
- if (process.env.AVA_PATH && process.env.AVA_PATH !== __dirname) {
5
- module.exports = require(process.env.AVA_PATH);
6
- } else {
7
- module.exports = require('./lib/worker/main');
8
- }