ava 3.15.0 → 4.0.0

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 (72) hide show
  1. package/entrypoints/cli.mjs +4 -0
  2. package/entrypoints/eslint-plugin-helper.cjs +109 -0
  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 -816
  8. package/lib/api.js +108 -49
  9. package/lib/assert.js +255 -270
  10. package/lib/chalk.js +9 -14
  11. package/lib/cli.js +118 -112
  12. package/lib/code-excerpt.js +12 -17
  13. package/lib/concordance-options.js +29 -65
  14. package/lib/context-ref.js +3 -6
  15. package/lib/create-chain.js +32 -20
  16. package/lib/environment-variables.js +1 -4
  17. package/lib/eslint-plugin-helper-worker.js +73 -0
  18. package/lib/extensions.js +2 -2
  19. package/lib/fork.js +81 -84
  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 +11 -18
  26. package/lib/load-config.js +56 -180
  27. package/lib/module-types.js +3 -7
  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 -46
  34. package/lib/provider-manager.js +20 -14
  35. package/lib/reporters/beautify-stack.js +6 -12
  36. package/lib/reporters/colors.js +40 -15
  37. package/lib/reporters/default.js +114 -364
  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 +18 -25
  42. package/lib/run-status.js +29 -23
  43. package/lib/runner.js +157 -172
  44. package/lib/scheduler.js +53 -0
  45. package/lib/serialize-error.js +61 -64
  46. package/lib/snapshot-manager.js +271 -289
  47. package/lib/test.js +135 -291
  48. package/lib/watcher.js +69 -44
  49. package/lib/worker/base.js +208 -0
  50. package/lib/worker/channel.cjs +290 -0
  51. package/lib/worker/dependency-tracker.js +24 -23
  52. package/lib/worker/{ensure-forked.js → guard-environment.cjs} +5 -4
  53. package/lib/worker/line-numbers.js +58 -20
  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} +30 -21
  57. package/lib/worker/state.cjs +5 -0
  58. package/lib/worker/utils.cjs +6 -0
  59. package/package.json +71 -68
  60. package/plugin.d.ts +51 -53
  61. package/readme.md +5 -13
  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/eslint-plugin-helper.js +0 -201
  68. package/index.js +0 -8
  69. package/lib/worker/ipc.js +0 -201
  70. package/lib/worker/main.js +0 -21
  71. package/lib/worker/subprocess.js +0 -266
  72. package/plugin.js +0 -9
@@ -1,27 +1,16 @@
1
- 'use strict';
2
- const trimOffNewlines = require('trim-off-newlines');
3
- const chalk = require('../chalk').get();
1
+ export default function formatSerializedError(error) {
2
+ const printMessage = error.values.length === 0
3
+ ? Boolean(error.message)
4
+ : !error.values[0].label.startsWith(error.message);
4
5
 
5
- function formatSerializedError(error) {
6
- const printMessage = error.values.length === 0 ?
7
- Boolean(error.message) :
8
- !error.values[0].label.startsWith(error.message);
9
-
10
- if (error.statements.length === 0 && error.values.length === 0) {
6
+ if (error.values.length === 0) {
11
7
  return {formatted: null, printMessage};
12
8
  }
13
9
 
14
10
  let formatted = '';
15
11
  for (const value of error.values) {
16
- formatted += `${value.label}\n\n${trimOffNewlines(value.formatted)}\n\n`;
17
- }
18
-
19
- for (const statement of error.statements) {
20
- formatted += `${statement[0]}\n${chalk.grey('=>')} ${trimOffNewlines(statement[1])}\n\n`;
12
+ formatted += `${value.label}\n\n${value.formatted}\n\n`;
21
13
  }
22
14
 
23
- formatted = trimOffNewlines(formatted);
24
- return {formatted, printMessage};
15
+ return {formatted: formatted.trim(), printMessage};
25
16
  }
26
-
27
- module.exports = formatSerializedError;
@@ -1,8 +1,7 @@
1
- 'use strict';
2
- const chalk = require('../chalk').get();
3
- const pkg = require('../../package.json');
1
+ import {chalk} from '../chalk.js';
2
+ import pkg from '../pkg.cjs';
4
3
 
5
- exports.forError = error => {
4
+ export default function buildMessage(error) {
6
5
  if (!error.improperUsage) {
7
6
  return null;
8
7
  }
@@ -21,7 +20,7 @@ Visit the following URL for more details:
21
20
  if (assertion === 'snapshot') {
22
21
  const {name, snapPath} = error.improperUsage;
23
22
 
24
- if (name === 'ChecksumError') {
23
+ if (name === 'ChecksumError' || name === 'InvalidSnapshotError') {
25
24
  return `The snapshot file is corrupted.
26
25
 
27
26
  File path: ${chalk.yellow(snapPath)}
@@ -39,9 +38,9 @@ Please run AVA again with the ${chalk.cyan('--update-snapshots')} flag to upgrad
39
38
 
40
39
  if (name === 'VersionMismatchError') {
41
40
  const {snapVersion, expectedVersion} = error.improperUsage;
42
- const upgradeMessage = snapVersion < expectedVersion ?
43
- `Please run AVA again with the ${chalk.cyan('--update-snapshots')} flag to upgrade.` :
44
- 'You should upgrade AVA.';
41
+ const upgradeMessage = snapVersion < expectedVersion
42
+ ? `Please run AVA again with the ${chalk.cyan('--update-snapshots')} flag to upgrade.`
43
+ : 'You should upgrade AVA.';
45
44
 
46
45
  return `The snapshot file is v${snapVersion}, but only v${expectedVersion} is supported.
47
46
 
@@ -52,4 +51,4 @@ ${upgradeMessage}`;
52
51
  }
53
52
 
54
53
  return null;
55
- };
54
+ }
@@ -1,21 +1,23 @@
1
- 'use strict';
2
- const path = require('path');
3
- const figures = require('figures');
4
- const chalk = require('../chalk').get();
1
+ import path from 'node:path';
5
2
 
6
- const SEPERATOR = ' ' + chalk.gray.dim(figures.pointerSmall) + ' ';
3
+ import figures from 'figures';
7
4
 
8
- module.exports = (base, file, title) => {
9
- const prefix = file
5
+ import {chalk} from '../chalk.js';
6
+
7
+ const SEPARATOR = ' ' + chalk.gray.dim(figures.pointerSmall) + ' ';
8
+
9
+ export default function prefixTitle(extensions, base, file, title) {
10
+ const parts = file
10
11
  // Only replace base if it is found at the start of the path
11
12
  .replace(base, (match, offset) => offset === 0 ? '' : match)
12
- .replace(/\.spec/, '')
13
- .replace(/\.test/, '')
14
- .replace(/test-/g, '')
15
- .replace(/\.js$/, '')
16
13
  .split(path.sep)
17
- .filter(p => p !== '__tests__')
18
- .join(SEPERATOR);
14
+ .filter(p => p !== '__tests__');
15
+
16
+ const filename = parts.pop()
17
+ .replace(/\.spec\./, '.')
18
+ .replace(/\.test\./, '.')
19
+ .replace(/test-/, '')
20
+ .replace(new RegExp(`.(${extensions.join('|')})$`), '');
19
21
 
20
- return prefix + SEPERATOR + title;
21
- };
22
+ return [...parts, filename, title].join(SEPARATOR);
23
+ }
@@ -1,14 +1,13 @@
1
- 'use strict';
2
- const os = require('os');
3
- const path = require('path');
1
+ import os from 'node:os';
2
+ import path from 'node:path';
4
3
 
5
- const plur = require('plur');
6
- const stripAnsi = require('strip-ansi');
7
- const supertap = require('supertap');
8
- const indentString = require('indent-string');
4
+ import indentString from 'indent-string';
5
+ import plur from 'plur';
6
+ import stripAnsi from 'strip-ansi';
7
+ import supertap from 'supertap';
9
8
 
10
- const beautifyStack = require('./beautify-stack');
11
- const prefixTitle = require('./prefix-title');
9
+ import beautifyStack from './beautify-stack.js';
10
+ import prefixTitle from './prefix-title.js';
12
11
 
13
12
  function dumpError(error) {
14
13
  const object = {...error.object};
@@ -30,10 +29,7 @@ function dumpError(error) {
30
29
  }
31
30
 
32
31
  if (error.values.length > 0) {
33
- object.values = error.values.reduce((acc, value) => { // eslint-disable-line unicorn/no-reduce
34
- acc[value.label] = stripAnsi(value.formatted);
35
- return acc;
36
- }, {});
32
+ object.values = Object.fromEntries(error.values.map(({label, formatted}) => [label, stripAnsi(formatted)]));
37
33
  }
38
34
  }
39
35
 
@@ -49,10 +45,11 @@ function dumpError(error) {
49
45
  return object;
50
46
  }
51
47
 
52
- class TapReporter {
48
+ export default class TapReporter {
53
49
  constructor(options) {
54
50
  this.i = 0;
55
51
 
52
+ this.extensions = options.extensions;
56
53
  this.stdStream = options.stdStream;
57
54
  this.reportStream = options.reportStream;
58
55
 
@@ -65,7 +62,7 @@ class TapReporter {
65
62
 
66
63
  startRun(plan) {
67
64
  if (plan.files.length > 1) {
68
- this.prefixTitle = (testFile, title) => prefixTitle(plan.filePathPrefix, testFile, title);
65
+ this.prefixTitle = (testFile, title) => prefixTitle(this.extensions, plan.filePathPrefix, testFile, title);
69
66
  }
70
67
 
71
68
  plan.status.on('stateChange', evt => this.consumeStateChange(evt));
@@ -80,7 +77,7 @@ class TapReporter {
80
77
  failed: this.stats.failedTests + this.stats.remainingTests,
81
78
  passed: this.stats.passedTests + this.stats.passedKnownFailingTests,
82
79
  skipped: this.stats.skippedTests,
83
- todo: this.stats.todoTests
80
+ todo: this.stats.todoTests,
84
81
  }) + os.EOL);
85
82
 
86
83
  if (this.stats.parallelRuns) {
@@ -93,7 +90,7 @@ class TapReporter {
93
90
  failed: 0,
94
91
  passed: 0,
95
92
  skipped: 0,
96
- todo: 0
93
+ todo: 0,
97
94
  }) + os.EOL);
98
95
  }
99
96
  }
@@ -105,7 +102,7 @@ class TapReporter {
105
102
  index: ++this.i,
106
103
  passed: flags.passed,
107
104
  skip: flags.skip,
108
- todo: flags.todo
105
+ todo: flags.todo,
109
106
  }) + os.EOL);
110
107
  }
111
108
 
@@ -117,7 +114,7 @@ class TapReporter {
117
114
  index: ++this.i,
118
115
  passed: false,
119
116
  skip: false,
120
- todo: false
117
+ todo: false,
121
118
  }) + os.EOL);
122
119
  }
123
120
 
@@ -132,11 +129,11 @@ class TapReporter {
132
129
  }
133
130
 
134
131
  writeTimeout(evt) {
135
- const err = new Error(`Exited because no new tests completed within the last ${evt.period}ms of inactivity`);
132
+ const error = new Error(`Exited because no new tests completed within the last ${evt.period}ms of inactivity`);
136
133
 
137
134
  for (const [testFile, tests] of evt.pendingTests) {
138
135
  for (const title of tests) {
139
- this.writeTest({testFile, title, err}, {passed: false, todo: false, skip: false});
136
+ this.writeTest({testFile, title, err: error}, {passed: false, todo: false, skip: false});
140
137
  }
141
138
  }
142
139
  }
@@ -168,9 +165,6 @@ class TapReporter {
168
165
  this.writeTest(evt, {passed: false, todo: true, skip: false});
169
166
  }
170
167
 
171
- break;
172
- case 'snapshot-error':
173
- this.writeComment(evt, {title: 'Could not update snapshots'});
174
168
  break;
175
169
  case 'stats':
176
170
  this.stats = evt.stats;
@@ -219,4 +213,3 @@ class TapReporter {
219
213
  }
220
214
  }
221
215
  }
222
- module.exports = TapReporter;
package/lib/run-status.js CHANGED
@@ -1,17 +1,21 @@
1
- 'use strict';
2
- const Emittery = require('emittery');
3
- const cloneDeep = require('lodash/cloneDeep');
1
+ import v8 from 'node:v8';
4
2
 
5
- class RunStatus extends Emittery {
6
- constructor(files, parallelRuns) {
3
+ import Emittery from 'emittery';
4
+
5
+ const copyStats = stats => v8.deserialize(v8.serialize(stats));
6
+
7
+ export default class RunStatus extends Emittery {
8
+ constructor(files, parallelRuns, selectionInsights) {
7
9
  super();
8
10
 
9
11
  this.pendingTests = new Map();
10
12
 
11
- this.emptyParallelRun = parallelRuns &&
12
- parallelRuns.currentFileCount === 0 &&
13
- parallelRuns.totalRuns > 1 &&
14
- files > 0;
13
+ this.emptyParallelRun = parallelRuns
14
+ && parallelRuns.currentFileCount === 0
15
+ && parallelRuns.totalRuns > 1
16
+ && files > 0;
17
+
18
+ this.selectionInsights = selectionInsights;
15
19
 
16
20
  this.stats = {
17
21
  byFile: new Map(),
@@ -32,7 +36,7 @@ class RunStatus extends Emittery {
32
36
  timeouts: 0,
33
37
  todoTests: 0,
34
38
  uncaughtExceptions: 0,
35
- unhandledRejections: 0
39
+ unhandledRejections: 0,
36
40
  };
37
41
  }
38
42
 
@@ -51,7 +55,7 @@ class RunStatus extends Emittery {
51
55
  todoTests: 0,
52
56
  uncaughtExceptions: 0,
53
57
  unhandledRejections: 0,
54
- ...stats
58
+ ...stats,
55
59
  });
56
60
 
57
61
  this.pendingTests.set(testFile, new Set());
@@ -147,7 +151,7 @@ class RunStatus extends Emittery {
147
151
  }
148
152
 
149
153
  if (changedStats) {
150
- this.emit('stateChange', {type: 'stats', stats: cloneDeep(stats)});
154
+ this.emit('stateChange', {type: 'stats', stats: copyStats(stats)});
151
155
  }
152
156
 
153
157
  this.emit('stateChange', event);
@@ -163,15 +167,15 @@ class RunStatus extends Emittery {
163
167
  }
164
168
 
165
169
  if (
166
- this.stats.declaredTests === 0 ||
167
- this.stats.internalErrors > 0 ||
168
- this.stats.failedHooks > 0 ||
169
- this.stats.failedTests > 0 ||
170
- this.stats.failedWorkers > 0 ||
171
- this.stats.sharedWorkerErrors > 0 ||
172
- this.stats.timeouts > 0 ||
173
- this.stats.uncaughtExceptions > 0 ||
174
- this.stats.unhandledRejections > 0
170
+ this.stats.declaredTests === 0
171
+ || this.stats.internalErrors > 0
172
+ || this.stats.failedHooks > 0
173
+ || this.stats.failedTests > 0
174
+ || this.stats.failedWorkers > 0
175
+ || this.stats.sharedWorkerErrors > 0
176
+ || this.stats.timeouts > 0
177
+ || this.stats.uncaughtExceptions > 0
178
+ || this.stats.unhandledRejections > 0
175
179
  ) {
176
180
  return 1;
177
181
  }
@@ -194,6 +198,8 @@ class RunStatus extends Emittery {
194
198
  this.pendingTests.get(event.testFile).delete(event.title);
195
199
  }
196
200
  }
197
- }
198
201
 
199
- module.exports = RunStatus;
202
+ getFailedTestFiles() {
203
+ return [...this.stats.byFile].filter(statByFile => statByFile[1].failedTests).map(statByFile => statByFile[0]);
204
+ }
205
+ }