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
package/lib/assert.js CHANGED
@@ -1,23 +1,23 @@
1
- 'use strict';
2
- const concordance = require('concordance');
3
- const isError = require('is-error');
4
- const isPromise = require('is-promise');
5
- const concordanceOptions = require('./concordance-options').default;
6
- const {CIRCULAR_SELECTOR, isLikeSelector, selectComparable} = require('./like-selector');
7
- const snapshotManager = require('./snapshot-manager');
1
+ import concordance from 'concordance';
2
+ import isError from 'is-error';
3
+ import isPromise from 'is-promise';
4
+
5
+ import concordanceOptions from './concordance-options.js';
6
+ import {CIRCULAR_SELECTOR, isLikeSelector, selectComparable} from './like-selector.js';
7
+ import {SnapshotError, VersionMismatchError} from './snapshot-manager.js';
8
8
 
9
9
  function formatDescriptorDiff(actualDescriptor, expectedDescriptor, options) {
10
10
  options = {...options, ...concordanceOptions};
11
11
  return {
12
12
  label: 'Difference:',
13
- formatted: concordance.diffDescriptors(actualDescriptor, expectedDescriptor, options)
13
+ formatted: concordance.diffDescriptors(actualDescriptor, expectedDescriptor, options),
14
14
  };
15
15
  }
16
16
 
17
17
  function formatDescriptorWithLabel(label, descriptor) {
18
18
  return {
19
19
  label,
20
- formatted: concordance.formatDescriptor(descriptor, concordanceOptions)
20
+ formatted: concordance.formatDescriptor(descriptor, concordanceOptions),
21
21
  };
22
22
  }
23
23
 
@@ -25,17 +25,13 @@ function formatWithLabel(label, value) {
25
25
  return formatDescriptorWithLabel(label, concordance.describe(value, concordanceOptions));
26
26
  }
27
27
 
28
- function formatPowerAssertValue(value) {
29
- return concordance.format(value, concordanceOptions);
30
- }
31
-
32
28
  const hasOwnProperty = (object, prop) => Object.prototype.hasOwnProperty.call(object, prop);
33
29
  const noop = () => {};
34
30
  const notImplemented = () => {
35
31
  throw new Error('not implemented');
36
32
  };
37
33
 
38
- class AssertionError extends Error {
34
+ export class AssertionError extends Error {
39
35
  constructor(options) {
40
36
  super(options.message || '');
41
37
  this.name = 'AssertionError';
@@ -52,19 +48,11 @@ class AssertionError extends Error {
52
48
  // use the values for custom diff views
53
49
  this.raw = options.raw;
54
50
 
55
- // Reserved for power-assert statements
56
- this.statements = [];
57
-
58
- if (options.savedError) {
59
- this.savedError = options.savedError;
60
- } else {
61
- this.savedError = getErrorWithLongStackTrace();
62
- }
51
+ this.savedError = options.savedError ? options.savedError : getErrorWithLongStackTrace();
63
52
  }
64
53
  }
65
- exports.AssertionError = AssertionError;
66
54
 
67
- function checkAssertionMessage(assertion, message) {
55
+ export function checkAssertionMessage(assertion, message) {
68
56
  if (typeof message === 'undefined' || typeof message === 'string') {
69
57
  return true;
70
58
  }
@@ -73,12 +61,10 @@ function checkAssertionMessage(assertion, message) {
73
61
  assertion,
74
62
  improperUsage: true,
75
63
  message: 'The assertion message must be a string',
76
- values: [formatWithLabel('Called with:', message)]
64
+ values: [formatWithLabel('Called with:', message)],
77
65
  });
78
66
  }
79
67
 
80
- exports.checkAssertionMessage = checkAssertionMessage;
81
-
82
68
  function getErrorWithLongStackTrace() {
83
69
  const limitBefore = Error.stackTraceLimit;
84
70
  Error.stackTraceLimit = Number.POSITIVE_INFINITY;
@@ -93,30 +79,30 @@ function validateExpectations(assertion, expectations, numberArgs) { // eslint-d
93
79
  throw new AssertionError({
94
80
  assertion,
95
81
  message: `The second argument to \`t.${assertion}()\` must be an expectation object or \`undefined\``,
96
- values: [formatWithLabel('Called with:', expectations)]
82
+ values: [formatWithLabel('Called with:', expectations)],
97
83
  });
98
84
  }
99
85
 
100
86
  expectations = {};
101
87
  } else if (
102
- typeof expectations === 'function' ||
103
- typeof expectations === 'string' ||
104
- expectations instanceof RegExp ||
105
- typeof expectations !== 'object' ||
106
- Array.isArray(expectations) ||
107
- Object.keys(expectations).length === 0
88
+ typeof expectations === 'function'
89
+ || typeof expectations === 'string'
90
+ || expectations instanceof RegExp
91
+ || typeof expectations !== 'object'
92
+ || Array.isArray(expectations)
93
+ || Object.keys(expectations).length === 0
108
94
  ) {
109
95
  throw new AssertionError({
110
96
  assertion,
111
97
  message: `The second argument to \`t.${assertion}()\` must be an expectation object, \`null\` or \`undefined\``,
112
- values: [formatWithLabel('Called with:', expectations)]
98
+ values: [formatWithLabel('Called with:', expectations)],
113
99
  });
114
100
  } else {
115
101
  if (hasOwnProperty(expectations, 'instanceOf') && typeof expectations.instanceOf !== 'function') {
116
102
  throw new AssertionError({
117
103
  assertion,
118
104
  message: `The \`instanceOf\` property of the second argument to \`t.${assertion}()\` must be a function`,
119
- values: [formatWithLabel('Called with:', expectations)]
105
+ values: [formatWithLabel('Called with:', expectations)],
120
106
  });
121
107
  }
122
108
 
@@ -124,7 +110,7 @@ function validateExpectations(assertion, expectations, numberArgs) { // eslint-d
124
110
  throw new AssertionError({
125
111
  assertion,
126
112
  message: `The \`message\` property of the second argument to \`t.${assertion}()\` must be a string or regular expression`,
127
- values: [formatWithLabel('Called with:', expectations)]
113
+ values: [formatWithLabel('Called with:', expectations)],
128
114
  });
129
115
  }
130
116
 
@@ -132,7 +118,7 @@ function validateExpectations(assertion, expectations, numberArgs) { // eslint-d
132
118
  throw new AssertionError({
133
119
  assertion,
134
120
  message: `The \`name\` property of the second argument to \`t.${assertion}()\` must be a string`,
135
- values: [formatWithLabel('Called with:', expectations)]
121
+ values: [formatWithLabel('Called with:', expectations)],
136
122
  });
137
123
  }
138
124
 
@@ -140,7 +126,7 @@ function validateExpectations(assertion, expectations, numberArgs) { // eslint-d
140
126
  throw new AssertionError({
141
127
  assertion,
142
128
  message: `The \`code\` property of the second argument to \`t.${assertion}()\` must be a string or number`,
143
- values: [formatWithLabel('Called with:', expectations)]
129
+ values: [formatWithLabel('Called with:', expectations)],
144
130
  });
145
131
  }
146
132
 
@@ -156,7 +142,7 @@ function validateExpectations(assertion, expectations, numberArgs) { // eslint-d
156
142
  throw new AssertionError({
157
143
  assertion,
158
144
  message: `The second argument to \`t.${assertion}()\` contains unexpected properties`,
159
- values: [formatWithLabel('Called with:', expectations)]
145
+ values: [formatWithLabel('Called with:', expectations)],
160
146
  });
161
147
  }
162
148
  }
@@ -173,7 +159,7 @@ function assertExpectations({assertion, actual, expectations, message, prefix, s
173
159
  assertion,
174
160
  message,
175
161
  savedError,
176
- values: [formatWithLabel(`${prefix} exception that is not an error:`, actual)]
162
+ values: [formatWithLabel(`${prefix} exception that is not an error:`, actual)],
177
163
  });
178
164
  }
179
165
 
@@ -187,8 +173,8 @@ function assertExpectations({assertion, actual, expectations, message, prefix, s
187
173
  actualStack,
188
174
  values: [
189
175
  formatWithLabel(`${prefix} unexpected exception:`, actual),
190
- formatWithLabel('Expected to be strictly equal to:', expectations.is)
191
- ]
176
+ formatWithLabel('Expected to be strictly equal to:', expectations.is),
177
+ ],
192
178
  });
193
179
  }
194
180
 
@@ -200,8 +186,8 @@ function assertExpectations({assertion, actual, expectations, message, prefix, s
200
186
  actualStack,
201
187
  values: [
202
188
  formatWithLabel(`${prefix} unexpected exception:`, actual),
203
- formatWithLabel('Expected instance of:', expectations.instanceOf)
204
- ]
189
+ formatWithLabel('Expected instance of:', expectations.instanceOf),
190
+ ],
205
191
  });
206
192
  }
207
193
 
@@ -213,8 +199,8 @@ function assertExpectations({assertion, actual, expectations, message, prefix, s
213
199
  actualStack,
214
200
  values: [
215
201
  formatWithLabel(`${prefix} unexpected exception:`, actual),
216
- formatWithLabel('Expected name to equal:', expectations.name)
217
- ]
202
+ formatWithLabel('Expected name to equal:', expectations.name),
203
+ ],
218
204
  });
219
205
  }
220
206
 
@@ -226,8 +212,8 @@ function assertExpectations({assertion, actual, expectations, message, prefix, s
226
212
  actualStack,
227
213
  values: [
228
214
  formatWithLabel(`${prefix} unexpected exception:`, actual),
229
- formatWithLabel('Expected message to equal:', expectations.message)
230
- ]
215
+ formatWithLabel('Expected message to equal:', expectations.message),
216
+ ],
231
217
  });
232
218
  }
233
219
 
@@ -239,8 +225,8 @@ function assertExpectations({assertion, actual, expectations, message, prefix, s
239
225
  actualStack,
240
226
  values: [
241
227
  formatWithLabel(`${prefix} unexpected exception:`, actual),
242
- formatWithLabel('Expected message to match:', expectations.message)
243
- ]
228
+ formatWithLabel('Expected message to match:', expectations.message),
229
+ ],
244
230
  });
245
231
  }
246
232
 
@@ -252,57 +238,33 @@ function assertExpectations({assertion, actual, expectations, message, prefix, s
252
238
  actualStack,
253
239
  values: [
254
240
  formatWithLabel(`${prefix} unexpected exception:`, actual),
255
- formatWithLabel('Expected code to equal:', expectations.code)
256
- ]
241
+ formatWithLabel('Expected code to equal:', expectations.code),
242
+ ],
257
243
  });
258
244
  }
259
245
  }
260
246
 
261
- class Assertions {
247
+ export class Assertions {
262
248
  constructor({
263
249
  pass = notImplemented,
264
250
  pending = notImplemented,
265
251
  fail = notImplemented,
266
252
  skip = notImplemented,
267
253
  compareWithSnapshot = notImplemented,
268
- powerAssert,
269
254
  experiments = {},
270
- disableSnapshots = false
255
+ disableSnapshots = false,
271
256
  } = {}) {
272
257
  const withSkip = assertionFn => {
273
258
  assertionFn.skip = skip;
274
259
  return assertionFn;
275
260
  };
276
261
 
277
- // When adding new enhanced functions with new patterns, don't forget to
278
- // enable the pattern in the power-assert compilation step in @ava/babel.
279
- const withPowerAssert = (pattern, assertionFn) => powerAssert.empower(assertionFn, {
280
- onError: event => {
281
- if (event.powerAssertContext) {
282
- event.error.statements = powerAssert.format(event.powerAssertContext, formatPowerAssertValue);
283
- }
284
-
285
- fail(event.error);
286
- return false;
287
- },
288
- onSuccess: () => {
289
- pass();
290
- return true;
291
- },
292
- bindReceiver: false,
293
- patterns: [pattern]
294
- });
295
-
296
- const checkMessage = (assertion, message, powerAssert = false) => {
262
+ const checkMessage = (assertion, message) => {
297
263
  const result = checkAssertionMessage(assertion, message);
298
264
  if (result === true) {
299
265
  return true;
300
266
  }
301
267
 
302
- if (powerAssert) {
303
- throw result;
304
- }
305
-
306
268
  fail(result);
307
269
  return false;
308
270
  };
@@ -319,7 +281,7 @@ class Assertions {
319
281
 
320
282
  fail(new AssertionError({
321
283
  assertion: 'fail',
322
- message: message || 'Test failed via `t.fail()`'
284
+ message: message || 'Test failed via `t.fail()`',
323
285
  }));
324
286
 
325
287
  return false;
@@ -344,14 +306,14 @@ class Assertions {
344
306
  assertion: 'is',
345
307
  message,
346
308
  raw: {actual, expected},
347
- values: [formatDescriptorWithLabel('Values are deeply equal to each other, but they are not the same:', actualDescriptor)]
309
+ values: [formatDescriptorWithLabel('Values are deeply equal to each other, but they are not the same:', actualDescriptor)],
348
310
  }));
349
311
  } else {
350
312
  fail(new AssertionError({
351
313
  assertion: 'is',
352
314
  message,
353
315
  raw: {actual, expected},
354
- values: [formatDescriptorDiff(actualDescriptor, expectedDescriptor)]
316
+ values: [formatDescriptorDiff(actualDescriptor, expectedDescriptor)],
355
317
  }));
356
318
  }
357
319
 
@@ -368,7 +330,7 @@ class Assertions {
368
330
  assertion: 'not',
369
331
  message,
370
332
  raw: {actual, expected},
371
- values: [formatWithLabel('Value is the same as:', actual)]
333
+ values: [formatWithLabel('Value is the same as:', actual)],
372
334
  }));
373
335
  return false;
374
336
  }
@@ -394,7 +356,7 @@ class Assertions {
394
356
  assertion: 'deepEqual',
395
357
  message,
396
358
  raw: {actual, expected},
397
- values: [formatDescriptorDiff(actualDescriptor, expectedDescriptor)]
359
+ values: [formatDescriptorDiff(actualDescriptor, expectedDescriptor)],
398
360
  }));
399
361
  return false;
400
362
  });
@@ -411,7 +373,7 @@ class Assertions {
411
373
  assertion: 'notDeepEqual',
412
374
  message,
413
375
  raw: {actual, expected},
414
- values: [formatDescriptorWithLabel('Value is deeply equal:', actualDescriptor)]
376
+ values: [formatDescriptorWithLabel('Value is deeply equal:', actualDescriptor)],
415
377
  }));
416
378
  return false;
417
379
  }
@@ -430,7 +392,7 @@ class Assertions {
430
392
  assertion: 'like',
431
393
  improperUsage: true,
432
394
  message: '`t.like()` selector must be a non-empty object',
433
- values: [formatWithLabel('Called with:', selector)]
395
+ values: [formatWithLabel('Called with:', selector)],
434
396
  }));
435
397
  return false;
436
398
  }
@@ -444,7 +406,7 @@ class Assertions {
444
406
  assertion: 'like',
445
407
  improperUsage: true,
446
408
  message: '`t.like()` selector must not contain circular references',
447
- values: [formatWithLabel('Called with:', selector)]
409
+ values: [formatWithLabel('Called with:', selector)],
448
410
  }));
449
411
  return false;
450
412
  }
@@ -463,7 +425,7 @@ class Assertions {
463
425
  fail(new AssertionError({
464
426
  assertion: 'like',
465
427
  message,
466
- values: [formatDescriptorDiff(actualDescriptor, expectedDescriptor)]
428
+ values: [formatDescriptorDiff(actualDescriptor, expectedDescriptor)],
467
429
  }));
468
430
 
469
431
  return false;
@@ -484,7 +446,7 @@ class Assertions {
484
446
  assertion: 'throws',
485
447
  improperUsage: true,
486
448
  message: '`t.throws()` must be called with a function',
487
- values: [formatWithLabel('Called with:', fn)]
449
+ values: [formatWithLabel('Called with:', fn)],
488
450
  }));
489
451
  return;
490
452
  }
@@ -506,7 +468,7 @@ class Assertions {
506
468
  fail(new AssertionError({
507
469
  assertion: 'throws',
508
470
  message,
509
- values: [formatWithLabel('Function returned a promise. Use `t.throwsAsync()` instead:', retval)]
471
+ values: [formatWithLabel('Function returned a promise. Use `t.throwsAsync()` instead:', retval)],
510
472
  }));
511
473
  return;
512
474
  }
@@ -518,7 +480,7 @@ class Assertions {
518
480
  fail(new AssertionError({
519
481
  assertion: 'throws',
520
482
  message,
521
- values: [formatWithLabel('Function returned:', retval)]
483
+ values: [formatWithLabel('Function returned:', retval)],
522
484
  }));
523
485
  return;
524
486
  }
@@ -529,7 +491,7 @@ class Assertions {
529
491
  actual,
530
492
  expectations,
531
493
  message,
532
- prefix: 'Function threw'
494
+ prefix: 'Function threw',
533
495
  });
534
496
  pass();
535
497
  return actual;
@@ -538,11 +500,11 @@ class Assertions {
538
500
  }
539
501
  });
540
502
 
541
- this.throwsAsync = withSkip((...args) => {
503
+ this.throwsAsync = withSkip(async (...args) => {
542
504
  let [thrower, expectations, message] = args;
543
505
 
544
506
  if (!checkMessage('throwsAsync', message)) {
545
- return Promise.resolve();
507
+ return;
546
508
  }
547
509
 
548
510
  if (typeof thrower !== 'function' && !isPromise(thrower)) {
@@ -550,28 +512,28 @@ class Assertions {
550
512
  assertion: 'throwsAsync',
551
513
  improperUsage: true,
552
514
  message: '`t.throwsAsync()` must be called with a function or promise',
553
- values: [formatWithLabel('Called with:', thrower)]
515
+ values: [formatWithLabel('Called with:', thrower)],
554
516
  }));
555
- return Promise.resolve();
517
+ return;
556
518
  }
557
519
 
558
520
  try {
559
521
  expectations = validateExpectations('throwsAsync', expectations, args.length, experiments);
560
522
  } catch (error) {
561
523
  fail(error);
562
- return Promise.resolve();
524
+ return;
563
525
  }
564
526
 
565
- const handlePromise = (promise, wasReturned) => {
527
+ const handlePromise = async (promise, wasReturned) => {
566
528
  // Create an error object to record the stack before it gets lost in the promise chain.
567
529
  const savedError = getErrorWithLongStackTrace();
568
530
  // Handle "promise like" objects by casting to a real Promise.
569
- const intermediate = Promise.resolve(promise).then(value => { // eslint-disable-line promise/prefer-await-to-then
531
+ const intermediate = Promise.resolve(promise).then(value => {
570
532
  throw new AssertionError({
571
533
  assertion: 'throwsAsync',
572
534
  message,
573
535
  savedError,
574
- values: [formatWithLabel(`${wasReturned ? 'Returned promise' : 'Promise'} resolved with:`, value)]
536
+ values: [formatWithLabel(`${wasReturned ? 'Returned promise' : 'Promise'} resolved with:`, value)],
575
537
  });
576
538
  }, error => {
577
539
  assertExpectations({
@@ -580,14 +542,17 @@ class Assertions {
580
542
  expectations,
581
543
  message,
582
544
  prefix: `${wasReturned ? 'Returned promise' : 'Promise'} rejected with`,
583
- savedError
545
+ savedError,
584
546
  });
585
547
  return error;
586
548
  });
587
549
 
588
550
  pending(intermediate);
589
- // Don't reject the returned promise, even if the assertion fails.
590
- return intermediate.catch(noop);
551
+ try {
552
+ return await intermediate;
553
+ } catch {
554
+ // Don't reject the returned promise, even if the assertion fails.
555
+ }
591
556
  };
592
557
 
593
558
  if (isPromise(thrower)) {
@@ -607,9 +572,9 @@ class Assertions {
607
572
  assertion: 'throwsAsync',
608
573
  message,
609
574
  actualStack: actual.stack,
610
- values: [formatWithLabel('Function threw synchronously. Use `t.throws()` instead:', actual)]
575
+ values: [formatWithLabel('Function threw synchronously. Use `t.throws()` instead:', actual)],
611
576
  }));
612
- return Promise.resolve();
577
+ return;
613
578
  }
614
579
 
615
580
  if (isPromise(retval)) {
@@ -619,9 +584,8 @@ class Assertions {
619
584
  fail(new AssertionError({
620
585
  assertion: 'throwsAsync',
621
586
  message,
622
- values: [formatWithLabel('Function returned:', retval)]
587
+ values: [formatWithLabel('Function returned:', retval)],
623
588
  }));
624
- return Promise.resolve();
625
589
  });
626
590
 
627
591
  this.notThrows = withSkip((fn, message) => {
@@ -634,7 +598,7 @@ class Assertions {
634
598
  assertion: 'notThrows',
635
599
  improperUsage: true,
636
600
  message: '`t.notThrows()` must be called with a function',
637
- values: [formatWithLabel('Called with:', fn)]
601
+ values: [formatWithLabel('Called with:', fn)],
638
602
  }));
639
603
  return;
640
604
  }
@@ -646,7 +610,7 @@ class Assertions {
646
610
  assertion: 'notThrows',
647
611
  message,
648
612
  actualStack: error.stack,
649
- values: [formatWithLabel('Function threw:', error)]
613
+ values: [formatWithLabel('Function threw:', error)],
650
614
  }));
651
615
  return;
652
616
  }
@@ -664,26 +628,30 @@ class Assertions {
664
628
  assertion: 'notThrowsAsync',
665
629
  improperUsage: true,
666
630
  message: '`t.notThrowsAsync()` must be called with a function or promise',
667
- values: [formatWithLabel('Called with:', nonThrower)]
631
+ values: [formatWithLabel('Called with:', nonThrower)],
668
632
  }));
669
633
  return Promise.resolve();
670
634
  }
671
635
 
672
- const handlePromise = (promise, wasReturned) => {
636
+ const handlePromise = async (promise, wasReturned) => {
673
637
  // Create an error object to record the stack before it gets lost in the promise chain.
674
638
  const savedError = getErrorWithLongStackTrace();
675
639
  // Handle "promise like" objects by casting to a real Promise.
676
- const intermediate = Promise.resolve(promise).then(noop, error => { // eslint-disable-line promise/prefer-await-to-then
640
+ const intermediate = Promise.resolve(promise).then(noop, error => {
677
641
  throw new AssertionError({
678
642
  assertion: 'notThrowsAsync',
679
643
  message,
680
644
  savedError,
681
- values: [formatWithLabel(`${wasReturned ? 'Returned promise' : 'Promise'} rejected with:`, error)]
645
+ values: [formatWithLabel(`${wasReturned ? 'Returned promise' : 'Promise'} rejected with:`, error)],
682
646
  });
683
647
  });
684
648
  pending(intermediate);
685
- // Don't reject the returned promise, even if the assertion fails.
686
- return intermediate.catch(noop);
649
+
650
+ try {
651
+ return await intermediate;
652
+ } catch {
653
+ // Don't reject the returned promise, even if the assertion fails.
654
+ }
687
655
  };
688
656
 
689
657
  if (isPromise(nonThrower)) {
@@ -698,7 +666,7 @@ class Assertions {
698
666
  assertion: 'notThrowsAsync',
699
667
  message,
700
668
  actualStack: error.stack,
701
- values: [formatWithLabel('Function threw:', error)]
669
+ values: [formatWithLabel('Function threw:', error)],
702
670
  }));
703
671
  return Promise.resolve();
704
672
  }
@@ -707,7 +675,7 @@ class Assertions {
707
675
  fail(new AssertionError({
708
676
  assertion: 'notThrowsAsync',
709
677
  message,
710
- values: [formatWithLabel('Function did not return a promise. Use `t.notThrows()` instead:', retval)]
678
+ values: [formatWithLabel('Function did not return a promise. Use `t.notThrows()` instead:', retval)],
711
679
  }));
712
680
  return Promise.resolve();
713
681
  }
@@ -720,7 +688,7 @@ class Assertions {
720
688
  fail(new AssertionError({
721
689
  assertion: 'snapshot',
722
690
  message: '`t.snapshot()` can only be used in tests',
723
- improperUsage: true
691
+ improperUsage: true,
724
692
  }));
725
693
  return false;
726
694
  }
@@ -730,7 +698,7 @@ class Assertions {
730
698
  assertion: 'snapshot',
731
699
  message: 'AVA 4 no longer supports snapshot IDs',
732
700
  improperUsage: true,
733
- values: [formatWithLabel('Called with id:', message.id)]
701
+ values: [formatWithLabel('Called with id:', message.id)],
734
702
  }));
735
703
  return false;
736
704
  }
@@ -744,7 +712,7 @@ class Assertions {
744
712
  assertion: 'snapshot',
745
713
  improperUsage: true,
746
714
  message: 'The snapshot assertion message must be a non-empty string',
747
- values: [formatWithLabel('Called with:', message)]
715
+ values: [formatWithLabel('Called with:', message)],
748
716
  }));
749
717
  return false;
750
718
  }
@@ -753,12 +721,12 @@ class Assertions {
753
721
  try {
754
722
  result = compareWithSnapshot({expected, message});
755
723
  } catch (error) {
756
- if (!(error instanceof snapshotManager.SnapshotError)) {
724
+ if (!(error instanceof SnapshotError)) {
757
725
  throw error;
758
726
  }
759
727
 
760
728
  const improperUsage = {name: error.name, snapPath: error.snapPath};
761
- if (error instanceof snapshotManager.VersionMismatchError) {
729
+ if (error instanceof VersionMismatchError) {
762
730
  improperUsage.snapVersion = error.snapVersion;
763
731
  improperUsage.expectedVersion = error.expectedVersion;
764
732
  }
@@ -766,7 +734,7 @@ class Assertions {
766
734
  fail(new AssertionError({
767
735
  assertion: 'snapshot',
768
736
  message: message || 'Could not compare snapshot',
769
- improperUsage
737
+ improperUsage,
770
738
  }));
771
739
  return false;
772
740
  }
@@ -780,13 +748,13 @@ class Assertions {
780
748
  fail(new AssertionError({
781
749
  assertion: 'snapshot',
782
750
  message: message || 'Did not match snapshot',
783
- values: [formatDescriptorDiff(result.actual, result.expected, {invert: true})]
751
+ values: [formatDescriptorDiff(result.actual, result.expected, {invert: true})],
784
752
  }));
785
753
  } else {
786
754
  // This can only occur in CI environments.
787
755
  fail(new AssertionError({
788
756
  assertion: 'snapshot',
789
- message: message || 'No snapshot available — new snapshots are not created in CI environments'
757
+ message: message || 'No snapshot available — new snapshots are not created in CI environments',
790
758
  }));
791
759
  }
792
760
 
@@ -807,7 +775,7 @@ class Assertions {
807
775
  assertion: 'truthy',
808
776
  message,
809
777
  operator: '!!',
810
- values: [formatWithLabel('Value is not truthy:', actual)]
778
+ values: [formatWithLabel('Value is not truthy:', actual)],
811
779
  }));
812
780
  return false;
813
781
  });
@@ -822,7 +790,7 @@ class Assertions {
822
790
  assertion: 'falsy',
823
791
  message,
824
792
  operator: '!',
825
- values: [formatWithLabel('Value is not falsy:', actual)]
793
+ values: [formatWithLabel('Value is not falsy:', actual)],
826
794
  }));
827
795
  return false;
828
796
  }
@@ -844,7 +812,7 @@ class Assertions {
844
812
  fail(new AssertionError({
845
813
  assertion: 'true',
846
814
  message,
847
- values: [formatWithLabel('Value is not `true`:', actual)]
815
+ values: [formatWithLabel('Value is not `true`:', actual)],
848
816
  }));
849
817
  return false;
850
818
  });
@@ -862,7 +830,7 @@ class Assertions {
862
830
  fail(new AssertionError({
863
831
  assertion: 'false',
864
832
  message,
865
- values: [formatWithLabel('Value is not `false`:', actual)]
833
+ values: [formatWithLabel('Value is not `false`:', actual)],
866
834
  }));
867
835
  return false;
868
836
  });
@@ -877,7 +845,7 @@ class Assertions {
877
845
  assertion: 'regex',
878
846
  improperUsage: true,
879
847
  message: '`t.regex()` must be called with a string',
880
- values: [formatWithLabel('Called with:', string)]
848
+ values: [formatWithLabel('Called with:', string)],
881
849
  }));
882
850
  return false;
883
851
  }
@@ -887,7 +855,7 @@ class Assertions {
887
855
  assertion: 'regex',
888
856
  improperUsage: true,
889
857
  message: '`t.regex()` must be called with a regular expression',
890
- values: [formatWithLabel('Called with:', regex)]
858
+ values: [formatWithLabel('Called with:', regex)],
891
859
  }));
892
860
  return false;
893
861
  }
@@ -898,8 +866,8 @@ class Assertions {
898
866
  message,
899
867
  values: [
900
868
  formatWithLabel('Value must match expression:', string),
901
- formatWithLabel('Regular expression:', regex)
902
- ]
869
+ formatWithLabel('Regular expression:', regex),
870
+ ],
903
871
  }));
904
872
  return false;
905
873
  }
@@ -918,7 +886,7 @@ class Assertions {
918
886
  assertion: 'notRegex',
919
887
  improperUsage: true,
920
888
  message: '`t.notRegex()` must be called with a string',
921
- values: [formatWithLabel('Called with:', string)]
889
+ values: [formatWithLabel('Called with:', string)],
922
890
  }));
923
891
  return false;
924
892
  }
@@ -928,7 +896,7 @@ class Assertions {
928
896
  assertion: 'notRegex',
929
897
  improperUsage: true,
930
898
  message: '`t.notRegex()` must be called with a regular expression',
931
- values: [formatWithLabel('Called with:', regex)]
899
+ values: [formatWithLabel('Called with:', regex)],
932
900
  }));
933
901
  return false;
934
902
  }
@@ -939,8 +907,8 @@ class Assertions {
939
907
  message,
940
908
  values: [
941
909
  formatWithLabel('Value must not match expression:', string),
942
- formatWithLabel('Regular expression:', regex)
943
- ]
910
+ formatWithLabel('Regular expression:', regex),
911
+ ],
944
912
  }));
945
913
  return false;
946
914
  }
@@ -949,42 +917,23 @@ class Assertions {
949
917
  return true;
950
918
  });
951
919
 
952
- if (powerAssert === undefined) {
953
- this.assert = withSkip((actual, message) => {
954
- if (!checkMessage('assert', message)) {
955
- return false;
956
- }
920
+ this.assert = withSkip((actual, message) => {
921
+ if (!checkMessage('assert', message)) {
922
+ return false;
923
+ }
957
924
 
958
- if (!actual) {
959
- fail(new AssertionError({
960
- assertion: 'assert',
961
- message,
962
- operator: '!!',
963
- values: [formatWithLabel('Value is not truthy:', actual)]
964
- }));
965
- return false;
966
- }
925
+ if (!actual) {
926
+ fail(new AssertionError({
927
+ assertion: 'assert',
928
+ message,
929
+ operator: '!!',
930
+ values: [formatWithLabel('Value is not truthy:', actual)],
931
+ }));
932
+ return false;
933
+ }
967
934
 
968
- pass();
969
- return true;
970
- });
971
- } else {
972
- this.assert = withSkip(withPowerAssert(
973
- 'assert(value, [message])',
974
- (actual, message) => {
975
- checkMessage('assert', message, true);
976
-
977
- if (!actual) {
978
- throw new AssertionError({
979
- assertion: 'assert',
980
- message,
981
- operator: '!!',
982
- values: [formatWithLabel('Value is not truthy:', actual)]
983
- });
984
- }
985
- })
986
- );
987
- }
935
+ pass();
936
+ return true;
937
+ });
988
938
  }
989
939
  }
990
- exports.Assertions = Assertions;