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
@@ -1,218 +0,0 @@
1
- 'use strict';
2
- const events = require('events');
3
- const pEvent = require('p-event');
4
- const {get: getOptions} = require('./options');
5
- const {isRunningInChildProcess, isRunningInThread} = require('./utils');
6
- const selectAvaMessage = type => message => message.ava && message.ava.type === type;
7
-
8
- const handle = {
9
- channel: null,
10
- send: null,
11
- ref: null
12
- };
13
-
14
- if (isRunningInChildProcess) {
15
- const {controlFlow} = require('../ipc-flow-control');
16
- const bufferedSend = controlFlow(process);
17
- handle.send = evt => {
18
- bufferedSend({ava: evt});
19
- };
20
-
21
- handle.channel = process;
22
- handle.ref = process.channel;
23
- } else if (isRunningInThread) {
24
- const {parentPort} = require('worker_threads');
25
- handle.channel = parentPort;
26
- handle.ref = parentPort;
27
- handle.send = evt => {
28
- handle.channel.postMessage({ava: evt});
29
- };
30
- }
31
-
32
- exports.options = pEvent(handle.channel, 'message', selectAvaMessage('options')).then(message => message.ava.options);
33
- exports.peerFailed = pEvent(handle.channel, 'message', selectAvaMessage('peer-failed'));
34
- exports.send = handle.send;
35
-
36
- let refs = 1;
37
- function ref() {
38
- if (++refs === 1) {
39
- handle.ref.ref();
40
- }
41
- }
42
-
43
- function unref() {
44
- if (refs > 0 && --refs === 0) {
45
- handle.ref.unref();
46
- }
47
- }
48
-
49
- exports.unref = unref;
50
-
51
- let pendingPings = Promise.resolve();
52
- async function flush() {
53
- ref();
54
- const promise = pendingPings.then(async () => { // eslint-disable-line promise/prefer-await-to-then
55
- handle.send({type: 'ping'});
56
- await pEvent(handle.channel, 'message', selectAvaMessage('pong'));
57
- if (promise === pendingPings) {
58
- unref();
59
- }
60
- });
61
- pendingPings = promise;
62
- await promise;
63
- }
64
-
65
- exports.flush = flush;
66
-
67
- let channelCounter = 0;
68
- let messageCounter = 0;
69
-
70
- const channelEmitters = new Map();
71
- function createChannelEmitter(channelId) {
72
- if (channelEmitters.size === 0) {
73
- handle.channel.on('message', message => {
74
- if (!message.ava) {
75
- return;
76
- }
77
-
78
- const {channelId, type, ...payload} = message.ava;
79
- if (
80
- type === 'shared-worker-error' ||
81
- type === 'shared-worker-message' ||
82
- type === 'shared-worker-ready'
83
- ) {
84
- const emitter = channelEmitters.get(channelId);
85
- if (emitter !== undefined) {
86
- emitter.emit(type, payload);
87
- }
88
- }
89
- });
90
- }
91
-
92
- const emitter = new events.EventEmitter();
93
- channelEmitters.set(channelId, emitter);
94
- return [emitter, () => channelEmitters.delete(channelId)];
95
- }
96
-
97
- function registerSharedWorker(filename, initialData) {
98
- const channelId = `${getOptions().forkId}/channel/${++channelCounter}`;
99
- const [channelEmitter, unsubscribe] = createChannelEmitter(channelId);
100
-
101
- let forcedUnref = false;
102
- let refs = 0;
103
- const forceUnref = () => {
104
- if (forcedUnref) {
105
- return;
106
- }
107
-
108
- forcedUnref = true;
109
- if (refs > 0) {
110
- unref();
111
- }
112
- };
113
-
114
- const refChannel = () => {
115
- if (!forcedUnref && ++refs === 1) {
116
- ref();
117
- }
118
- };
119
-
120
- const unrefChannel = () => {
121
- if (!forcedUnref && refs > 0 && --refs === 0) {
122
- unref();
123
- }
124
- };
125
-
126
- handle.send({
127
- type: 'shared-worker-connect',
128
- channelId,
129
- filename,
130
- initialData
131
- });
132
-
133
- let currentlyAvailable = false;
134
- let error = null;
135
-
136
- refChannel();
137
- const ready = pEvent(channelEmitter, 'shared-worker-ready').then(() => { // eslint-disable-line promise/prefer-await-to-then
138
- currentlyAvailable = error === null;
139
- }).finally(unrefChannel);
140
-
141
- const messageEmitters = new Set();
142
- const handleMessage = message => {
143
- // Wait for a turn of the event loop, to allow new subscriptions to be set
144
- // up in response to the previous message.
145
- setImmediate(() => {
146
- for (const emitter of messageEmitters) {
147
- emitter.emit('message', message);
148
- }
149
- });
150
- };
151
-
152
- channelEmitter.on('shared-worker-message', handleMessage);
153
-
154
- pEvent(channelEmitter, 'shared-worker-error').then(() => { // eslint-disable-line promise/prefer-await-to-then
155
- unsubscribe();
156
- forceUnref();
157
-
158
- error = new Error('The shared worker is no longer available');
159
- currentlyAvailable = false;
160
- for (const emitter of messageEmitters) {
161
- emitter.emit('error', error);
162
- }
163
- });
164
-
165
- return {
166
- forceUnref,
167
- ready,
168
- channel: {
169
- available: ready,
170
-
171
- get currentlyAvailable() {
172
- return currentlyAvailable;
173
- },
174
-
175
- async * receive() {
176
- if (error !== null) {
177
- throw error;
178
- }
179
-
180
- const emitter = new events.EventEmitter();
181
- messageEmitters.add(emitter);
182
- try {
183
- refChannel();
184
- for await (const [message] of events.on(emitter, 'message')) {
185
- yield message;
186
- }
187
- } finally {
188
- unrefChannel();
189
- messageEmitters.delete(emitter);
190
- }
191
- },
192
-
193
- post(serializedData, replyTo) {
194
- if (error !== null) {
195
- throw error;
196
- }
197
-
198
- if (!currentlyAvailable) {
199
- throw new Error('Shared worker is not yet available');
200
- }
201
-
202
- const messageId = `${channelId}/message/${++messageCounter}`;
203
- handle.send({
204
- type: 'shared-worker-message',
205
- channelId,
206
- messageId,
207
- replyTo,
208
- serializedData
209
- });
210
-
211
- return messageId;
212
- }
213
- }
214
- };
215
- }
216
-
217
- exports.registerSharedWorker = registerSharedWorker;
218
-
@@ -1,20 +0,0 @@
1
- 'use strict';
2
- const runner = require('./base').getRunner();
3
- const makeCjsExport = () => {
4
- function test(...args) {
5
- return runner.chain(...args);
6
- }
7
-
8
- return Object.assign(test, runner.chain);
9
- };
10
-
11
- // Support CommonJS modules by exporting a test function that can be fully
12
- // chained. Also support ES module loaders by exporting __esModule and a
13
- // default. Support `import * as ava from 'ava'` use cases by exporting a
14
- // `test` member. Do all this whilst preventing `test.test.test() or
15
- // `test.default.test()` chains, though in CommonJS `test.test()` is
16
- // unavoidable.
17
- module.exports = Object.assign(makeCjsExport(), {
18
- __esModule: true,
19
- default: runner.chain
20
- });
package/plugin.js DELETED
@@ -1,9 +0,0 @@
1
- 'use strict';
2
- const path = require('path');
3
-
4
- // Ensure the same AVA install is loaded by the test file as by the test worker
5
- if (process.env.AVA_PATH && process.env.AVA_PATH !== __dirname) {
6
- module.exports = require(path.join(process.env.AVA_PATH, 'plugin'));
7
- } else {
8
- module.exports = require('./lib/worker/plugin');
9
- }