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,14 +1,11 @@
1
- const events = require('events');
2
- const serializeError = require('../serialize-error');
1
+ import events from 'node:events';
2
+ import {pathToFileURL} from 'node:url';
3
+ import {Worker} from 'node:worker_threads';
3
4
 
4
- let Worker;
5
- try {
6
- ({Worker} = require('worker_threads'));
7
- } catch {}
5
+ import serializeError from '../serialize-error.js';
8
6
 
9
- const LOADER = require.resolve('./shared-worker-loader');
7
+ const LOADER = new URL('shared-worker-loader.js', import.meta.url);
10
8
 
11
- let sharedWorkerCounter = 0;
12
9
  const launchedWorkers = new Map();
13
10
 
14
11
  const waitForAvailable = async worker => {
@@ -19,30 +16,28 @@ const waitForAvailable = async worker => {
19
16
  }
20
17
  };
21
18
 
22
- function launchWorker({filename, initialData}) {
19
+ function launchWorker(filename, initialData) {
23
20
  if (launchedWorkers.has(filename)) {
24
21
  return launchedWorkers.get(filename);
25
22
  }
26
23
 
27
- const id = `shared-worker/${++sharedWorkerCounter}`;
28
24
  const worker = new Worker(LOADER, {
29
25
  // Ensure the worker crashes for unhandled rejections, rather than allowing undefined behavior.
30
26
  execArgv: ['--unhandled-rejections=strict'],
31
27
  workerData: {
32
28
  filename,
33
- id,
34
- initialData
35
- }
29
+ initialData,
30
+ },
36
31
  });
37
32
  worker.setMaxListeners(0);
38
33
 
39
34
  const launched = {
40
35
  statePromises: {
41
36
  available: waitForAvailable(worker),
42
- error: events.once(worker, 'error').then(([error]) => error) // eslint-disable-line promise/prefer-await-to-then
37
+ error: events.once(worker, 'error').then(([error]) => error),
43
38
  },
44
39
  exited: false,
45
- worker
40
+ worker,
46
41
  };
47
42
 
48
43
  launchedWorkers.set(filename, launched);
@@ -53,7 +48,7 @@ function launchWorker({filename, initialData}) {
53
48
  return launched;
54
49
  }
55
50
 
56
- async function observeWorkerProcess(fork, runStatus) {
51
+ export async function observeWorkerProcess(fork, runStatus) {
57
52
  let registrationCount = 0;
58
53
  let signalDeregistered;
59
54
  const deregistered = new Promise(resolve => {
@@ -66,26 +61,11 @@ async function observeWorkerProcess(fork, runStatus) {
66
61
  }
67
62
  });
68
63
 
69
- fork.onConnectSharedWorker(async channel => {
70
- const launched = launchWorker(channel);
71
-
72
- const handleChannelMessage = ({messageId, replyTo, serializedData}) => {
73
- launched.worker.postMessage({
74
- type: 'message',
75
- testWorkerId: fork.forkId,
76
- messageId,
77
- replyTo,
78
- serializedData
79
- });
80
- };
64
+ fork.onConnectSharedWorker(async ({filename, initialData, port, signalError}) => {
65
+ const launched = launchWorker(filename, initialData);
81
66
 
82
67
  const handleWorkerMessage = async message => {
83
- if (message.type === 'broadcast' || (message.type === 'message' && message.testWorkerId === fork.forkId)) {
84
- const {messageId, replyTo, serializedData} = message;
85
- channel.forwardMessageToFork({messageId, replyTo, serializedData});
86
- }
87
-
88
- if (message.type === 'deregistered-test-worker' && message.id === fork.forkId) {
68
+ if (message.type === 'deregistered-test-worker' && message.id === fork.threadId) {
89
69
  launched.worker.off('message', handleWorkerMessage);
90
70
 
91
71
  registrationCount--;
@@ -95,35 +75,35 @@ async function observeWorkerProcess(fork, runStatus) {
95
75
  }
96
76
  };
97
77
 
98
- launched.statePromises.error.then(error => { // eslint-disable-line promise/prefer-await-to-then
78
+ launched.statePromises.error.then(error => {
99
79
  signalDeregistered();
100
80
  launched.worker.off('message', handleWorkerMessage);
101
81
  runStatus.emitStateChange({type: 'shared-worker-error', err: serializeError('Shared worker error', true, error)});
102
- channel.signalError();
82
+ signalError();
103
83
  });
104
84
 
105
85
  try {
106
86
  await launched.statePromises.available;
107
87
 
108
88
  registrationCount++;
89
+
90
+ port.postMessage({type: 'ready'});
91
+
109
92
  launched.worker.postMessage({
110
93
  type: 'register-test-worker',
111
- id: fork.forkId,
112
- file: fork.file
113
- });
94
+ id: fork.threadId,
95
+ file: pathToFileURL(fork.file).toString(),
96
+ port,
97
+ }, [port]);
114
98
 
115
99
  fork.promise.finally(() => {
116
100
  launched.worker.postMessage({
117
101
  type: 'deregister-test-worker',
118
- id: fork.forkId
102
+ id: fork.threadId,
119
103
  });
120
-
121
- channel.off('message', handleChannelMessage);
122
104
  });
123
105
 
124
106
  launched.worker.on('message', handleWorkerMessage);
125
- channel.on('message', handleChannelMessage);
126
- channel.signalReady();
127
107
  } catch {
128
108
  return;
129
109
  } finally {
@@ -136,5 +116,3 @@ async function observeWorkerProcess(fork, runStatus) {
136
116
 
137
117
  return deregistered;
138
118
  }
139
-
140
- exports.observeWorkerProcess = observeWorkerProcess;
@@ -1,21 +1,21 @@
1
- const pkg = require('../package.json');
2
- const globs = require('./globs');
1
+ import * as globs from './globs.js';
2
+ import pkg from './pkg.cjs';
3
3
 
4
4
  const levels = {
5
- ava3: 1,
6
- pathRewrites: 2
5
+ // As the protocol changes, comparing levels by integer allows AVA to be
6
+ // compatible with different versions. Currently there is only one supported
7
+ // version, so this is effectively unused. The infrastructure is retained for
8
+ // future use.
9
+ levelIntegersAreCurrentlyUnused: 0,
7
10
  };
8
11
 
9
- exports.levels = levels;
10
-
11
12
  const levelsByProtocol = {
12
- 'ava-3': levels.ava3,
13
- 'ava-3.2': levels.pathRewrites
13
+ 'ava-3.2': levels.levelIntegersAreCurrentlyUnused,
14
14
  };
15
15
 
16
- function load(providerModule, projectDir) {
16
+ async function load(providerModule, projectDir) {
17
17
  const ava = {version: pkg.version};
18
- const makeProvider = require(providerModule);
18
+ const {default: makeProvider} = await import(providerModule); // eslint-disable-line node/no-unsupported-features/es-syntax
19
19
 
20
20
  let fatal;
21
21
  let level;
@@ -37,9 +37,9 @@ function load(providerModule, projectDir) {
37
37
  },
38
38
  identifier,
39
39
  normalizeGlobPatterns: globs.normalizePatterns,
40
- projectDir
40
+ projectDir,
41
41
  };
42
- }
42
+ },
43
43
  });
44
44
 
45
45
  if (fatal) {
@@ -49,5 +49,11 @@ function load(providerModule, projectDir) {
49
49
  return {...provider, level};
50
50
  }
51
51
 
52
- exports.babel = projectDir => load('@ava/babel', projectDir);
53
- exports.typescript = projectDir => load('@ava/typescript', projectDir);
52
+ const providerManager = {
53
+ levels,
54
+ async typescript(projectDir) {
55
+ return load('@ava/typescript', projectDir);
56
+ },
57
+ };
58
+
59
+ export default providerManager;
@@ -1,16 +1,10 @@
1
- 'use strict';
2
- const StackUtils = require('stack-utils');
1
+ import StackUtils from 'stack-utils';
3
2
 
4
3
  const stackUtils = new StackUtils({
5
4
  ignoredPackages: [
6
- '@ava/babel',
7
- '@ava/require-precompiled',
8
5
  '@ava/typescript',
9
- 'append-transform',
10
6
  'ava',
11
- 'empower-core',
12
- 'esm',
13
- 'nyc'
7
+ 'nyc',
14
8
  ],
15
9
  internals: [
16
10
  // AVA internals, which ignoredPackages don't ignore when we run our own unit tests.
@@ -20,8 +14,8 @@ const stackUtils = new StackUtils({
20
14
  /\(internal\/process\/task_queues\.js:\d+:\d+\)$/,
21
15
  /\(internal\/modules\/cjs\/.+?\.js:\d+:\d+\)$/,
22
16
  /async Promise\.all \(index/,
23
- /new Promise \(<anonymous>\)/
24
- ]
17
+ /new Promise \(<anonymous>\)/,
18
+ ],
25
19
  });
26
20
 
27
21
  /*
@@ -60,7 +54,7 @@ const stackUtils = new StackUtils({
60
54
  * Module.runMain (module.js:604:10)
61
55
  * ```
62
56
  */
63
- module.exports = stack => {
57
+ export default function beautifyStack(stack) {
64
58
  if (!stack) {
65
59
  return [];
66
60
  }
@@ -70,4 +64,4 @@ module.exports = stack => {
70
64
  .split('\n')
71
65
  .map(line => line.trim())
72
66
  .filter(line => line !== '');
73
- };
67
+ }
@@ -1,17 +1,42 @@
1
- 'use strict';
2
- const chalk = require('../chalk').get();
1
+ import {chalk} from '../chalk.js';
3
2
 
4
- module.exports = {
5
- log: chalk.gray,
6
- title: chalk.bold,
7
- error: chalk.red,
8
- skip: chalk.yellow,
9
- todo: chalk.blue,
10
- pass: chalk.green,
11
- duration: chalk.gray.dim,
12
- errorSource: chalk.gray,
13
- errorStack: chalk.gray,
14
- errorStackInternal: chalk.gray.dim,
15
- stack: chalk.red,
16
- information: chalk.magenta
3
+ const colors = {
4
+ get log() {
5
+ return chalk.gray;
6
+ },
7
+ get title() {
8
+ return chalk.bold;
9
+ },
10
+ get error() {
11
+ return chalk.red;
12
+ },
13
+ get skip() {
14
+ return chalk.yellow;
15
+ },
16
+ get todo() {
17
+ return chalk.blue;
18
+ },
19
+ get pass() {
20
+ return chalk.green;
21
+ },
22
+ get duration() {
23
+ return chalk.gray.dim;
24
+ },
25
+ get errorSource() {
26
+ return chalk.gray;
27
+ },
28
+ get errorStack() {
29
+ return chalk.gray;
30
+ },
31
+ get errorStackInternal() {
32
+ return chalk.gray.dim;
33
+ },
34
+ get stack() {
35
+ return chalk.red;
36
+ },
37
+ get information() {
38
+ return chalk.magenta;
39
+ },
17
40
  };
41
+
42
+ export default colors;