ava 4.2.0 → 4.3.2

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.
@@ -0,0 +1,2 @@
1
+ export {default} from '../index.js';
2
+ export * from '../index.js';
@@ -0,0 +1 @@
1
+ export * from '../plugin.js'
package/index.d.ts CHANGED
@@ -1,9 +1,9 @@
1
- import type {TestFn} from './types/test-fn';
1
+ import type {TestFn} from './types/test-fn.js';
2
2
 
3
- export * from './types/assertions';
4
- export * from './types/try-fn';
5
- export * from './types/test-fn';
6
- export * from './types/subscribable';
3
+ export * from './types/assertions.js';
4
+ export * from './types/try-fn.js';
5
+ export * from './types/test-fn.js';
6
+ export * from './types/subscribable.js';
7
7
 
8
8
  /** Call to declare a test, or chain to declare hooks or test modifiers */
9
9
  declare const test: TestFn;
package/lib/assert.js CHANGED
@@ -106,10 +106,15 @@ function validateExpectations(assertion, expectations, numberArgs) { // eslint-d
106
106
  });
107
107
  }
108
108
 
109
- if (hasOwnProperty(expectations, 'message') && typeof expectations.message !== 'string' && !(expectations.message instanceof RegExp)) {
109
+ if (
110
+ hasOwnProperty(expectations, 'message')
111
+ && typeof expectations.message !== 'string'
112
+ && !(expectations.message instanceof RegExp)
113
+ && !(typeof expectations.message === 'function')
114
+ ) {
110
115
  throw new AssertionError({
111
116
  assertion,
112
- message: `The \`message\` property of the second argument to \`t.${assertion}()\` must be a string or regular expression`,
117
+ message: `The \`message\` property of the second argument to \`t.${assertion}()\` must be a string, regular expression or a function`,
113
118
  values: [formatWithLabel('Called with:', expectations)],
114
119
  });
115
120
  }
@@ -230,6 +235,19 @@ function assertExpectations({assertion, actual, expectations, message, prefix, s
230
235
  });
231
236
  }
232
237
 
238
+ if (typeof expectations.message === 'function' && expectations.message(actual.message) === false) {
239
+ throw new AssertionError({
240
+ assertion,
241
+ message,
242
+ savedError,
243
+ actualStack,
244
+ values: [
245
+ formatWithLabel(`${prefix} unexpected exception:`, actual),
246
+ formatWithLabel('Expected message to return true:', expectations.message),
247
+ ],
248
+ });
249
+ }
250
+
233
251
  if (typeof expectations.code !== 'undefined' && actual.code !== expectations.code) {
234
252
  throw new AssertionError({
235
253
  assertion,
@@ -101,11 +101,13 @@ export default function createChain(fn, defaults, meta) {
101
101
 
102
102
  root.meta = meta;
103
103
 
104
- // Our type definition uses ESM syntax; when using CJS with VSCode, the
105
- // auto-completion assumes the root is accessed through `require('ava').default`.
106
- // Placate VSCode by adding a mostly hidden default property on the root.
107
- // This is available through both CJS and ESM imports. We use a proxy so that
108
- // we don't end up with root.default.default.default chains.
104
+ // The ESM and CJS type definitions export the chain (`test()` function) as
105
+ // the default. TypeScript's CJS output (when `esModuleInterop` is disabled)
106
+ // assume `require('ava').default` is available. The same goes for `import ava
107
+ // = require('ava')` syntax.
108
+ //
109
+ // Add `test.default` to make this work. Use a proxy to avoid
110
+ // `test.default.default` chains.
109
111
  Object.defineProperty(root, 'default', {
110
112
  configurable: false,
111
113
  enumerable: false,
@@ -220,6 +220,9 @@ export default class Reporter {
220
220
  this.lineNumberErrors.push(event);
221
221
 
222
222
  this.write(colors.information(`${figures.warning} Could not parse ${this.relativeFile(event.testFile)} for line number selection`));
223
+ this.lineWriter.writeLine();
224
+ this.lineWriter.writeLine(colors.errorStack(event.err.stack));
225
+ this.lineWriter.writeLine();
223
226
  break;
224
227
  }
225
228
 
@@ -231,7 +234,7 @@ export default class Reporter {
231
234
  }
232
235
 
233
236
  case 'hook-finished': {
234
- if (true && event.logs.length > 0) {
237
+ if (event.logs.length > 0) {
235
238
  this.lineWriter.writeLine(` ${this.prefixTitle(event.testFile, event.title)}`);
236
239
  this.writeLogs(event);
237
240
  }
@@ -312,7 +315,7 @@ export default class Reporter {
312
315
  this.filesWithoutMatchedLineNumbers.add(event.testFile);
313
316
 
314
317
  this.lineWriter.writeLine(colors.error(`${figures.cross} Line numbers for ${this.relativeFile(event.testFile)} did not match any tests`));
315
- } else if (true && !this.failFastEnabled && fileStats.remainingTests > 0) {
318
+ } else if (!this.failFastEnabled && fileStats.remainingTests > 0) {
316
319
  this.lineWriter.writeLine(colors.error(`${figures.cross} ${fileStats.remainingTests} ${plur('test', fileStats.remainingTests)} remaining in ${this.relativeFile(event.testFile)}`));
317
320
  }
318
321
  }
@@ -515,7 +518,8 @@ export default class Reporter {
515
518
 
516
519
  writeFailure(event) {
517
520
  this.lineWriter.writeLine(colors.title(this.prefixTitle(event.testFile, event.title)));
518
- if (!this.writeLogs(event, true)) {
521
+
522
+ if (!event.logs || event.logs.length === 0) {
519
523
  this.lineWriter.writeLine();
520
524
  }
521
525
 
@@ -570,17 +574,12 @@ export default class Reporter {
570
574
  this.lineWriter.writeLine();
571
575
 
572
576
  if (this.failures.length > 0) {
573
- const writeTrailingLines = this.internalErrors.length > 0 || this.sharedWorkerErrors.length > 0 || this.uncaughtExceptions.length > 0 || this.unhandledRejections.length > 0;
574
-
575
577
  const lastFailure = this.failures[this.failures.length - 1];
576
578
  for (const event of this.failures) {
577
579
  this.writeFailure(event);
578
580
  if (event !== lastFailure) {
579
581
  this.lineWriter.writeLine();
580
582
  this.lineWriter.writeLine();
581
- } else if (!true && writeTrailingLines) {
582
- this.lineWriter.writeLine();
583
- this.lineWriter.writeLine();
584
583
  }
585
584
  }
586
585
 
@@ -659,6 +658,10 @@ export default class Reporter {
659
658
  this.lineWriter.writeLine(colors.error(`${this.stats.uncaughtExceptions} uncaught ${plur('exception', this.stats.uncaughtExceptions)}`));
660
659
  }
661
660
 
661
+ if (this.stats.timeouts > 0) {
662
+ this.lineWriter.writeLine(colors.error(`${this.stats.timeouts} ${plur('test', this.stats.timeouts)} remained pending after a timeout`));
663
+ }
664
+
662
665
  if (this.previousFailures > 0) {
663
666
  this.lineWriter.writeLine(colors.error(`${this.previousFailures} previous ${plur('failure', this.previousFailures)} in test files that were not rerun`));
664
667
  }
package/lib/run-status.js CHANGED
@@ -125,7 +125,10 @@ export default class RunStatus extends Emittery {
125
125
  case 'timeout':
126
126
  event.pendingTests = this.pendingTests;
127
127
  this.pendingTests = new Map();
128
- stats.timeouts++;
128
+ for (const testsInFile of event.pendingTests.values()) {
129
+ stats.timeouts += testsInFile.size;
130
+ }
131
+
129
132
  break;
130
133
  case 'interrupt':
131
134
  event.pendingTests = this.pendingTests;
package/lib/runner.js CHANGED
@@ -524,7 +524,7 @@ export default class Runner extends Emittery {
524
524
  // If a concurrent test fails, even if `failFast` is enabled it won't
525
525
  // stop other concurrent tests from running.
526
526
  const allOkays = await Promise.all(concurrentTests.map(task => this.runTest(task, contextRef.copy())));
527
- return allOkays.every(ok => ok);
527
+ return allOkays.every(Boolean);
528
528
  });
529
529
 
530
530
  const beforeExitHandler = this.beforeExitHandler.bind(this);
@@ -391,7 +391,9 @@ class Manager {
391
391
 
392
392
  const resolveSourceFile = mem(file => {
393
393
  const sourceMap = findSourceMap(file);
394
- if (sourceMap === undefined) {
394
+ // Prior to Node.js 18.8.0, the value when a source map could not be found was `undefined`.
395
+ // This changed to `null` in <https://github.com/nodejs/node/pull/43875>. Check both.
396
+ if (sourceMap === undefined || sourceMap === null) {
395
397
  return file;
396
398
  }
397
399
 
@@ -66,6 +66,13 @@ const translate = (sourceMap, pos) => {
66
66
  }
67
67
 
68
68
  const entry = sourceMap.findEntry(pos.line - 1, pos.column); // Source maps are 0-based
69
+
70
+ // When used with ts-node/register, we've seen entries without original values. Return the
71
+ // original position.
72
+ if (entry.originalLine === undefined || entry.originalColumn === undefined) {
73
+ return pos;
74
+ }
75
+
69
76
  return {
70
77
  line: entry.originalLine + 1, // Readjust for Acorn.
71
78
  column: entry.originalColumn,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ava",
3
- "version": "4.2.0",
3
+ "version": "4.3.2",
4
4
  "description": "Node.js test runner that lets you develop with confidence.",
5
5
  "license": "MIT",
6
6
  "repository": "avajs/ava",
@@ -10,18 +10,30 @@
10
10
  },
11
11
  "exports": {
12
12
  ".": {
13
- "import": "./entrypoints/main.mjs",
14
- "require": "./entrypoints/main.cjs"
13
+ "import": {
14
+ "types": "./index.d.ts",
15
+ "default": "./entrypoints/main.mjs"
16
+ },
17
+ "require": {
18
+ "types": "./entrypoints/index.d.cts",
19
+ "default": "./entrypoints/main.cjs"
20
+ }
15
21
  },
16
22
  "./eslint-plugin-helper": "./entrypoints/eslint-plugin-helper.cjs",
17
23
  "./plugin": {
18
- "import": "./entrypoints/plugin.mjs",
19
- "require": "./entrypoints/plugin.cjs"
24
+ "import": {
25
+ "types": "./plugin.d.ts",
26
+ "default": "./entrypoints/plugin.mjs"
27
+ },
28
+ "require": {
29
+ "types": "./entrypoints/plugin.d.cts",
30
+ "default": "./entrypoints/plugin.cjs"
31
+ }
20
32
  }
21
33
  },
22
34
  "type": "module",
23
35
  "engines": {
24
- "node": ">=12.22 <13 || >=14.17 <15 || >=16.4 <17 || >=17"
36
+ "node": ">=12.22 <13 || >=14.17 <15 || >=16.4 <17 || >=18"
25
37
  },
26
38
  "scripts": {
27
39
  "cover": "c8 --report=none test-ava && c8 --report=none --no-clean tap && c8 report",
@@ -70,17 +82,17 @@
70
82
  "typescript"
71
83
  ],
72
84
  "dependencies": {
73
- "acorn": "^8.7.0",
85
+ "acorn": "^8.7.1",
74
86
  "acorn-walk": "^8.2.0",
75
87
  "ansi-styles": "^6.1.0",
76
88
  "arrgv": "^1.0.2",
77
89
  "arrify": "^3.0.0",
78
90
  "callsites": "^4.0.0",
79
91
  "cbor": "^8.1.0",
80
- "chalk": "^5.0.0",
92
+ "chalk": "^5.0.1",
81
93
  "chokidar": "^3.5.3",
82
94
  "chunkd": "^2.0.1",
83
- "ci-info": "^3.3.0",
95
+ "ci-info": "^3.3.1",
84
96
  "ci-parallel-vars": "^1.0.1",
85
97
  "clean-yaml-object": "^0.1.0",
86
98
  "cli-truncate": "^3.1.0",
@@ -88,12 +100,12 @@
88
100
  "common-path-prefix": "^3.0.0",
89
101
  "concordance": "^5.0.4",
90
102
  "currently-unhandled": "^0.4.1",
91
- "debug": "^4.3.3",
92
- "del": "^6.0.0",
93
- "emittery": "^0.10.1",
94
- "figures": "^4.0.0",
103
+ "debug": "^4.3.4",
104
+ "del": "^6.1.1",
105
+ "emittery": "^0.11.0",
106
+ "figures": "^4.0.1",
95
107
  "globby": "^13.1.1",
96
- "ignore-by-default": "^2.0.0",
108
+ "ignore-by-default": "^2.1.0",
97
109
  "indent-string": "^5.0.0",
98
110
  "is-error": "^2.2.2",
99
111
  "is-plain-object": "^5.0.0",
@@ -102,7 +114,7 @@
102
114
  "mem": "^9.0.2",
103
115
  "ms": "^2.1.3",
104
116
  "p-event": "^5.0.1",
105
- "p-map": "^5.3.0",
117
+ "p-map": "^5.4.0",
106
118
  "picomatch": "^2.3.1",
107
119
  "pkg-conf": "^4.0.0",
108
120
  "plur": "^5.1.0",
@@ -114,27 +126,27 @@
114
126
  "supertap": "^3.0.1",
115
127
  "temp-dir": "^2.0.0",
116
128
  "write-file-atomic": "^4.0.1",
117
- "yargs": "^17.3.1"
129
+ "yargs": "^17.5.1"
118
130
  },
119
131
  "devDependencies": {
120
132
  "@ava/test": "github:avajs/test",
121
133
  "@ava/typescript": "^3.0.1",
122
- "@sinonjs/fake-timers": "^9.1.1",
134
+ "@sinonjs/fake-timers": "^9.1.2",
123
135
  "ansi-escapes": "^5.0.0",
124
- "c8": "^7.11.0",
136
+ "c8": "^7.11.3",
125
137
  "delay": "^5.0.0",
126
138
  "execa": "^6.1.0",
127
- "fs-extra": "^10.0.1",
139
+ "fs-extra": "^10.1.0",
128
140
  "get-stream": "^6.0.1",
129
141
  "replace-string": "^4.0.0",
130
- "sinon": "^13.0.1",
131
- "tap": "^16.0.0",
142
+ "sinon": "^13.0.2",
143
+ "tap": "^16.2.0",
132
144
  "temp-write": "^5.0.0",
133
145
  "tempy": "^2.0.0",
134
146
  "touch": "^3.1.0",
135
- "tsd": "^0.19.1",
136
- "typescript": "^4.6.2",
137
- "xo": "^0.48.0",
147
+ "tsd": "^0.20.0",
148
+ "typescript": "^4.7.2",
149
+ "xo": "^0.49.0",
138
150
  "zen-observable": "^0.8.15"
139
151
  },
140
152
  "peerDependencies": {
@@ -144,5 +156,9 @@
144
156
  "@ava/typescript": {
145
157
  "optional": true
146
158
  }
159
+ },
160
+ "volta": {
161
+ "node": "18.3.0",
162
+ "npm": "8.12.0"
147
163
  }
148
164
  }
package/readme.md CHANGED
@@ -11,7 +11,7 @@ Read our [contributing guide](.github/CONTRIBUTING.md) if you're looking to cont
11
11
  ![](media/verbose-reporter.png)
12
12
 
13
13
 
14
- Translations: [Español](https://github.com/avajs/ava-docs/blob/master/es_ES/readme.md), [Français](https://github.com/avajs/ava-docs/blob/master/fr_FR/readme.md), [Italiano](https://github.com/avajs/ava-docs/blob/master/it_IT/readme.md), [日本語](https://github.com/avajs/ava-docs/blob/master/ja_JP/readme.md), [한국어](https://github.com/avajs/ava-docs/blob/master/ko_KR/readme.md), [Português](https://github.com/avajs/ava-docs/blob/master/pt_BR/readme.md), [Русский](https://github.com/avajs/ava-docs/blob/master/ru_RU/readme.md), [简体中文](https://github.com/avajs/ava-docs/blob/master/zh_CN/readme.md)
14
+ Translations: [Español](https://github.com/avajs/ava-docs/blob/main/es_ES/readme.md), [Français](https://github.com/avajs/ava-docs/blob/main/fr_FR/readme.md), [Italiano](https://github.com/avajs/ava-docs/blob/main/it_IT/readme.md), [日本語](https://github.com/avajs/ava-docs/blob/main/ja_JP/readme.md), [한국어](https://github.com/avajs/ava-docs/blob/main/ko_KR/readme.md), [Português](https://github.com/avajs/ava-docs/blob/main/pt_BR/readme.md), [Русский](https://github.com/avajs/ava-docs/blob/main/ru_RU/readme.md), [简体中文](https://github.com/avajs/ava-docs/blob/main/zh_CN/readme.md)
15
15
 
16
16
 
17
17
  ## Why AVA?
@@ -66,6 +66,8 @@ Alternatively you can install `ava` manually:
66
66
  npm install --save-dev ava
67
67
  ```
68
68
 
69
+ *Make sure to install AVA locally. As of AVA 4 it can no longer be run globally.*
70
+
69
71
  Don't forget to configure the `test` script in your `package.json` as per above.
70
72
 
71
73
  ### Create your test file
@@ -12,7 +12,7 @@ export type ThrowsExpectation = {
12
12
  is?: Error;
13
13
 
14
14
  /** The thrown error must have a message that equals the given string, or matches the regular expression. */
15
- message?: string | RegExp;
15
+ message?: string | RegExp | ((message: string) => boolean);
16
16
 
17
17
  /** The thrown error must have a name that equals the given string. */
18
18
  name?: string;
@@ -252,7 +252,7 @@ export interface NotThrowsAsyncAssertion {
252
252
  (fn: () => PromiseLike<any>, message?: string): Promise<void>;
253
253
 
254
254
  /** Assert that the promise does not reject. You must await the result. */
255
- (promise: PromiseLike<any>, message?: string): Promise<void>; // eslint-disable-line @typescript-eslint/unified-signatures
255
+ (promise: PromiseLike<any>, message?: string): Promise<void>;
256
256
 
257
257
  /** Skip this assertion. */
258
258
  skip(nonThrower: any, message?: string): void;
@@ -311,7 +311,7 @@ export interface ThrowsAsyncAssertion {
311
311
  * rejection reason. Returns undefined when the assertion fails. You must await the result. The error must satisfy all
312
312
  * expectations.
313
313
  */
314
- <ThrownError extends Error>(promise: PromiseLike<any>, expectations?: ThrowsExpectation, message?: string): Promise<ThrownError | undefined>; // eslint-disable-line @typescript-eslint/unified-signatures
314
+ <ThrownError extends Error>(promise: PromiseLike<any>, expectations?: ThrowsExpectation, message?: string): Promise<ThrownError | undefined>;
315
315
 
316
316
  /** Skip this assertion. */
317
317
  skip(thrower: any, expectations?: any, message?: string): void;
File without changes
@@ -1,6 +1,6 @@
1
- import type {Assertions} from './assertions';
2
- import type {Subscribable} from './subscribable';
3
- import type {TryFn} from './try-fn';
1
+ import type {Assertions} from './assertions.js';
2
+ import type {Subscribable} from './subscribable.js';
3
+ import type {TryFn} from './try-fn.js';
4
4
 
5
5
  /** The `t` value passed to test & hook implementations. */
6
6
  export interface ExecutionContext<Context = unknown> extends Assertions {
@@ -219,7 +219,7 @@ export type MacroDeclarationOptions<Args extends unknown[], Context = unknown> =
219
219
  export interface MacroFn<Context = unknown> {
220
220
  /** Declare a reusable test implementation. */
221
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
222
+ <Args extends unknown[]>(declaration: MacroDeclarationOptions<Args, Context>): Macro<Args, Context>;
223
223
  }
224
224
 
225
225
  export interface Meta {
package/types/try-fn.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import type {Implementation} from './test-fn';
1
+ import type {Implementation} from './test-fn.js';
2
2
 
3
3
  export type CommitDiscardOptions = {
4
4
  /**