ava 5.3.1 → 6.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (40) hide show
  1. package/entrypoints/internal.d.mts +7 -0
  2. package/lib/api-event-iterator.js +12 -0
  3. package/lib/api.js +14 -23
  4. package/lib/assert.js +289 -444
  5. package/lib/cli.js +95 -61
  6. package/lib/code-excerpt.js +2 -2
  7. package/lib/eslint-plugin-helper-worker.js +3 -3
  8. package/lib/fork.js +3 -13
  9. package/lib/glob-helpers.cjs +1 -9
  10. package/lib/globs.js +7 -3
  11. package/lib/line-numbers.js +1 -1
  12. package/lib/load-config.js +3 -3
  13. package/lib/parse-test-args.js +3 -3
  14. package/lib/plugin-support/shared-workers.js +4 -4
  15. package/lib/provider-manager.js +11 -13
  16. package/lib/reporters/beautify-stack.js +0 -1
  17. package/lib/reporters/default.js +92 -45
  18. package/lib/reporters/format-serialized-error.js +6 -6
  19. package/lib/reporters/improper-usage-messages.js +5 -5
  20. package/lib/reporters/tap.js +30 -30
  21. package/lib/run-status.js +9 -0
  22. package/lib/runner.js +7 -7
  23. package/lib/scheduler.js +14 -1
  24. package/lib/serialize-error.js +44 -116
  25. package/lib/slash.cjs +1 -1
  26. package/lib/snapshot-manager.js +14 -8
  27. package/lib/test.js +90 -81
  28. package/lib/watcher.js +494 -365
  29. package/lib/worker/base.js +90 -51
  30. package/lib/worker/channel.cjs +9 -53
  31. package/license +1 -1
  32. package/package.json +36 -42
  33. package/readme.md +6 -12
  34. package/types/assertions.d.cts +107 -49
  35. package/types/shared-worker.d.cts +0 -2
  36. package/types/state-change-events.d.cts +143 -0
  37. package/types/test-fn.d.cts +10 -5
  38. package/lib/worker/dependency-tracker.js +0 -48
  39. /package/entrypoints/{main.d.ts → main.d.mts} +0 -0
  40. /package/entrypoints/{plugin.d.ts → plugin.d.mts} +0 -0
@@ -0,0 +1,7 @@
1
+ import type {StateChangeEvent} from '../types/state-change-events.d';
2
+
3
+ export type Event = StateChangeEvent;
4
+
5
+ export type ObservedRun = {
6
+ events: AsyncIterableIterator<Event>;
7
+ };
@@ -0,0 +1,12 @@
1
+ export async function * asyncEventIteratorFromApi(api) {
2
+ // TODO: support multiple runs (watch mode)
3
+ const {value: plan} = await api.events('run').next();
4
+
5
+ for await (const stateChange of plan.status.events('stateChange')) {
6
+ yield stateChange;
7
+
8
+ if (stateChange.type === 'end' || stateChange.type === 'interrupt') {
9
+ break;
10
+ }
11
+ }
12
+ }
package/lib/api.js CHANGED
@@ -9,7 +9,6 @@ import commonPathPrefix from 'common-path-prefix';
9
9
  import Emittery from 'emittery';
10
10
  import ms from 'ms';
11
11
  import pMap from 'p-map';
12
- import resolveCwd from 'resolve-cwd';
13
12
  import tempDir from 'temp-dir';
14
13
 
15
14
  import fork from './fork.js';
@@ -22,15 +21,13 @@ import RunStatus from './run-status.js';
22
21
  import scheduler from './scheduler.js';
23
22
  import serializeError from './serialize-error.js';
24
23
 
25
- function resolveModules(modules) {
26
- return arrify(modules).map(name => {
27
- const modulePath = resolveCwd.silent(name);
28
-
29
- if (modulePath === undefined) {
30
- throw new Error(`Could not resolve required module ’${name}’`);
24
+ function normalizeRequireOption(require) {
25
+ return arrify(require).map(name => {
26
+ if (typeof name === 'string') {
27
+ return arrify(name);
31
28
  }
32
29
 
33
- return modulePath;
30
+ return name;
34
31
  });
35
32
  }
36
33
 
@@ -81,7 +78,7 @@ export default class Api extends Emittery {
81
78
  super();
82
79
 
83
80
  this.options = {match: [], moduleTypes: {}, ...options};
84
- this.options.require = resolveModules(this.options.require);
81
+ this.options.require = normalizeRequireOption(this.options.require);
85
82
 
86
83
  this._cacheDir = null;
87
84
  this._interruptHandler = () => {};
@@ -167,7 +164,7 @@ export default class Api extends Emittery {
167
164
 
168
165
  const selectionInsights = {
169
166
  filter,
170
- ignoredFilterPatternFiles: selectedFiles.ignoredFilterPatternFiles || [],
167
+ ignoredFilterPatternFiles: selectedFiles.ignoredFilterPatternFiles ?? [],
171
168
  testFileCount: testFiles.length,
172
169
  selectionCount: selectedFiles.length,
173
170
  };
@@ -179,7 +176,7 @@ export default class Api extends Emittery {
179
176
 
180
177
  // The files must be in the same order across all runs, so sort them.
181
178
  const defaultComparator = (a, b) => a.localeCompare(b, [], {numeric: true});
182
- selectedFiles = selectedFiles.sort(this.options.sortTestFiles || defaultComparator);
179
+ selectedFiles = selectedFiles.sort(this.options.sortTestFiles ?? defaultComparator);
183
180
  selectedFiles = chunkd(selectedFiles, currentIndex, totalRuns);
184
181
 
185
182
  const currentFileCount = selectedFiles.length;
@@ -200,15 +197,14 @@ export default class Api extends Emittery {
200
197
 
201
198
  await this.emit('run', {
202
199
  bailWithoutReporting: debugWithoutSpecificFile,
203
- clearLogOnNextRun: runtimeOptions.clearLogOnNextRun === true,
204
200
  debug: Boolean(this.options.debug),
205
201
  failFastEnabled: failFast,
206
202
  filePathPrefix: getFilePathPrefix(selectedFiles),
207
203
  files: selectedFiles,
208
204
  matching: apiOptions.match.length > 0,
209
- previousFailures: runtimeOptions.previousFailures || 0,
205
+ previousFailures: runtimeOptions.previousFailures ?? 0,
210
206
  runOnlyExclusive: runtimeOptions.runOnlyExclusive === true,
211
- runVector: runtimeOptions.runVector || 0,
207
+ firstRun: runtimeOptions.firstRun ?? true,
212
208
  status: runStatus,
213
209
  });
214
210
 
@@ -306,19 +302,14 @@ export default class Api extends Emittery {
306
302
 
307
303
  // Allow shared workers to clean up before the run ends.
308
304
  await Promise.all(deregisteredSharedWorkers);
309
- scheduler.storeFailedTestFiles(runStatus, this.options.cacheEnabled === false ? null : this._createCacheDir());
305
+ const files = scheduler.storeFailedTestFiles(runStatus, this.options.cacheEnabled === false ? null : this._createCacheDir());
306
+ runStatus.emitStateChange({type: 'touched-files', files});
310
307
  } catch (error) {
311
- if (error && error.name === 'AggregateError') {
312
- for (const error_ of error.errors) {
313
- runStatus.emitStateChange({type: 'internal-error', err: serializeError('Internal error', false, error_)});
314
- }
315
- } else {
316
- runStatus.emitStateChange({type: 'internal-error', err: serializeError('Internal error', false, error)});
317
- }
308
+ runStatus.emitStateChange({type: 'internal-error', err: serializeError(error)});
318
309
  }
319
310
 
320
311
  timeoutTrigger.discard();
321
- return runStatus;
312
+ return runStatus.end();
322
313
  }
323
314
 
324
315
  _getLocalCacheDir() {