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.
- package/entrypoints/cli.mjs +4 -0
- package/{eslint-plugin-helper.js → entrypoints/eslint-plugin-helper.cjs} +20 -7
- package/entrypoints/main.cjs +2 -0
- package/entrypoints/main.mjs +1 -0
- package/entrypoints/plugin.cjs +2 -0
- package/entrypoints/plugin.mjs +4 -0
- package/index.d.ts +6 -709
- package/lib/api.js +95 -46
- package/lib/assert.js +122 -173
- package/lib/chalk.js +9 -14
- package/lib/cli.js +105 -97
- package/lib/code-excerpt.js +12 -17
- package/lib/concordance-options.js +30 -31
- package/lib/context-ref.js +3 -6
- package/lib/create-chain.js +32 -4
- package/lib/environment-variables.js +1 -4
- package/lib/eslint-plugin-helper-worker.js +16 -26
- package/lib/extensions.js +2 -2
- package/lib/fork.js +42 -83
- package/lib/glob-helpers.cjs +140 -0
- package/lib/globs.js +136 -163
- package/lib/{ipc-flow-control.js → ipc-flow-control.cjs} +1 -0
- package/lib/is-ci.js +4 -2
- package/lib/like-selector.js +7 -13
- package/lib/line-numbers.js +10 -17
- package/lib/load-config.js +62 -56
- package/lib/module-types.js +3 -3
- package/lib/node-arguments.js +4 -5
- package/lib/{now-and-timers.js → now-and-timers.cjs} +0 -0
- package/lib/parse-test-args.js +22 -11
- package/lib/pkg.cjs +2 -0
- package/lib/plugin-support/shared-worker-loader.js +45 -48
- package/lib/plugin-support/shared-workers.js +24 -43
- package/lib/provider-manager.js +20 -14
- package/lib/reporters/beautify-stack.js +6 -11
- package/lib/reporters/colors.js +40 -15
- package/lib/reporters/default.js +115 -350
- package/lib/reporters/format-serialized-error.js +7 -18
- package/lib/reporters/improper-usage-messages.js +8 -9
- package/lib/reporters/prefix-title.js +17 -15
- package/lib/reporters/tap.js +15 -16
- package/lib/run-status.js +25 -23
- package/lib/runner.js +138 -127
- package/lib/scheduler.js +42 -36
- package/lib/serialize-error.js +34 -34
- package/lib/snapshot-manager.js +83 -76
- package/lib/test.js +114 -195
- package/lib/watcher.js +65 -40
- package/lib/worker/base.js +48 -99
- package/lib/worker/channel.cjs +290 -0
- package/lib/worker/dependency-tracker.js +22 -22
- package/lib/worker/guard-environment.cjs +19 -0
- package/lib/worker/line-numbers.js +57 -19
- package/lib/worker/main.cjs +12 -0
- package/lib/worker/{options.js → options.cjs} +0 -0
- package/lib/worker/{plugin.js → plugin.cjs} +31 -16
- package/lib/worker/state.cjs +5 -0
- package/lib/worker/{utils.js → utils.cjs} +1 -1
- package/package.json +60 -68
- package/plugin.d.ts +51 -53
- package/readme.md +5 -12
- package/types/assertions.d.ts +327 -0
- package/types/subscribable.ts +6 -0
- package/types/test-fn.d.ts +231 -0
- package/types/try-fn.d.ts +58 -0
- package/cli.js +0 -11
- package/index.js +0 -8
- package/lib/worker/channel.js +0 -218
- package/lib/worker/main.js +0 -20
- package/plugin.js +0 -9
package/lib/chalk.js
CHANGED
|
@@ -1,20 +1,15 @@
|
|
|
1
|
-
|
|
2
|
-
const chalk = require('chalk');
|
|
1
|
+
import {Chalk} from 'chalk'; // eslint-disable-line unicorn/import-style
|
|
3
2
|
|
|
4
|
-
let
|
|
5
|
-
exports.get = () => {
|
|
6
|
-
if (!ctx) {
|
|
7
|
-
throw new Error('Chalk has not yet been configured');
|
|
8
|
-
}
|
|
3
|
+
let chalk = new Chalk(); // eslint-disable-line import/no-mutable-exports
|
|
9
4
|
|
|
10
|
-
|
|
11
|
-
};
|
|
5
|
+
export {chalk};
|
|
12
6
|
|
|
13
|
-
|
|
14
|
-
|
|
7
|
+
let configured = false;
|
|
8
|
+
export function set(options) {
|
|
9
|
+
if (configured) {
|
|
15
10
|
throw new Error('Chalk has already been configured');
|
|
16
11
|
}
|
|
17
12
|
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
}
|
|
13
|
+
configured = true;
|
|
14
|
+
chalk = new Chalk(options);
|
|
15
|
+
}
|
package/lib/cli.js
CHANGED
|
@@ -1,94 +1,112 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
1
|
+
|
|
2
|
+
import fs from 'node:fs';
|
|
3
|
+
import path from 'node:path';
|
|
4
|
+
import process from 'node:process';
|
|
5
|
+
|
|
6
|
+
import arrify from 'arrify';
|
|
7
|
+
import ciParallelVars from 'ci-parallel-vars';
|
|
8
|
+
import del from 'del';
|
|
9
|
+
import figures from 'figures';
|
|
10
|
+
import yargs from 'yargs';
|
|
11
|
+
import {hideBin} from 'yargs/helpers'; // eslint-disable-line node/file-extension-in-import
|
|
12
|
+
|
|
13
|
+
import Api from './api.js';
|
|
14
|
+
import {chalk} from './chalk.js';
|
|
15
|
+
import validateEnvironmentVariables from './environment-variables.js';
|
|
16
|
+
import normalizeExtensions from './extensions.js';
|
|
17
|
+
import {normalizeGlobs, normalizePattern} from './globs.js';
|
|
18
|
+
import {controlFlow} from './ipc-flow-control.cjs';
|
|
19
|
+
import isCi from './is-ci.js';
|
|
20
|
+
import {splitPatternAndLineNumbers} from './line-numbers.js';
|
|
21
|
+
import {loadConfig} from './load-config.js';
|
|
22
|
+
import normalizeModuleTypes from './module-types.js';
|
|
23
|
+
import normalizeNodeArguments from './node-arguments.js';
|
|
24
|
+
import providerManager from './provider-manager.js';
|
|
25
|
+
import DefaultReporter from './reporters/default.js';
|
|
26
|
+
import TapReporter from './reporters/tap.js';
|
|
27
|
+
import Watcher from './watcher.js';
|
|
11
28
|
|
|
12
29
|
function exit(message) {
|
|
13
|
-
console.error(`\n ${
|
|
30
|
+
console.error(`\n ${chalk.red(figures.cross)} ${message}`);
|
|
14
31
|
process.exit(1); // eslint-disable-line unicorn/no-process-exit
|
|
15
32
|
}
|
|
16
33
|
|
|
17
|
-
const coerceLastValue = value =>
|
|
18
|
-
return Array.isArray(value) ? value.pop() : value;
|
|
19
|
-
};
|
|
34
|
+
const coerceLastValue = value => Array.isArray(value) ? value.pop() : value;
|
|
20
35
|
|
|
21
36
|
const FLAGS = {
|
|
22
37
|
concurrency: {
|
|
23
38
|
alias: 'c',
|
|
24
39
|
coerce: coerceLastValue,
|
|
25
40
|
description: 'Max number of test files running at the same time (default: CPU cores)',
|
|
26
|
-
type: 'number'
|
|
41
|
+
type: 'number',
|
|
27
42
|
},
|
|
28
43
|
'fail-fast': {
|
|
29
44
|
coerce: coerceLastValue,
|
|
30
45
|
description: 'Stop after first test failure',
|
|
31
|
-
type: 'boolean'
|
|
46
|
+
type: 'boolean',
|
|
32
47
|
},
|
|
33
48
|
match: {
|
|
34
49
|
alias: 'm',
|
|
35
50
|
description: 'Only run tests with matching title (can be repeated)',
|
|
36
|
-
type: 'string'
|
|
51
|
+
type: 'string',
|
|
37
52
|
},
|
|
38
53
|
'no-worker-threads': {
|
|
39
54
|
coerce: coerceLastValue,
|
|
40
55
|
description: 'Don\'t use worker threads',
|
|
41
|
-
type: 'boolean'
|
|
56
|
+
type: 'boolean',
|
|
42
57
|
},
|
|
43
58
|
'node-arguments': {
|
|
44
59
|
coerce: coerceLastValue,
|
|
45
60
|
description: 'Additional Node.js arguments for launching worker processes (specify as a single string)',
|
|
46
|
-
type: 'string'
|
|
61
|
+
type: 'string',
|
|
47
62
|
},
|
|
48
63
|
serial: {
|
|
49
64
|
alias: 's',
|
|
50
65
|
coerce: coerceLastValue,
|
|
51
66
|
description: 'Run tests serially',
|
|
52
|
-
type: 'boolean'
|
|
67
|
+
type: 'boolean',
|
|
53
68
|
},
|
|
54
69
|
tap: {
|
|
55
70
|
alias: 't',
|
|
56
71
|
coerce: coerceLastValue,
|
|
57
72
|
description: 'Generate TAP output',
|
|
58
|
-
type: 'boolean'
|
|
73
|
+
type: 'boolean',
|
|
59
74
|
},
|
|
60
75
|
timeout: {
|
|
61
76
|
alias: 'T',
|
|
62
77
|
coerce: coerceLastValue,
|
|
63
78
|
description: 'Set global timeout (milliseconds or human-readable, e.g. 10s, 2m)',
|
|
64
|
-
type: 'string'
|
|
79
|
+
type: 'string',
|
|
65
80
|
},
|
|
66
81
|
'update-snapshots': {
|
|
67
82
|
alias: 'u',
|
|
68
83
|
coerce: coerceLastValue,
|
|
69
84
|
description: 'Update snapshots',
|
|
70
|
-
type: 'boolean'
|
|
85
|
+
type: 'boolean',
|
|
71
86
|
},
|
|
72
87
|
verbose: {
|
|
73
88
|
alias: 'v',
|
|
74
89
|
coerce: coerceLastValue,
|
|
75
|
-
description: 'Enable verbose output',
|
|
76
|
-
type: 'boolean'
|
|
90
|
+
description: 'Enable verbose output (default)',
|
|
91
|
+
type: 'boolean',
|
|
77
92
|
},
|
|
78
93
|
watch: {
|
|
79
94
|
alias: 'w',
|
|
80
95
|
coerce: coerceLastValue,
|
|
81
96
|
description: 'Re-run tests when files change',
|
|
82
|
-
type: 'boolean'
|
|
83
|
-
}
|
|
97
|
+
type: 'boolean',
|
|
98
|
+
},
|
|
84
99
|
};
|
|
85
100
|
|
|
86
|
-
|
|
87
|
-
let conf
|
|
88
|
-
let confError
|
|
101
|
+
export default async function loadCli() { // eslint-disable-line complexity
|
|
102
|
+
let conf;
|
|
103
|
+
let confError;
|
|
89
104
|
try {
|
|
90
|
-
const {argv: {config: configFile}} = yargs.help(false);
|
|
105
|
+
const {argv: {config: configFile}} = yargs(hideBin(process.argv)).help(false);
|
|
91
106
|
conf = await loadConfig({configFile});
|
|
107
|
+
if (conf.configFile && path.basename(conf.configFile) !== path.relative(conf.projectDir, conf.configFile)) {
|
|
108
|
+
console.log(chalk.magenta(` ${figures.warning} Using configuration from ${conf.configFile}`));
|
|
109
|
+
}
|
|
92
110
|
} catch (error) {
|
|
93
111
|
confError = error;
|
|
94
112
|
}
|
|
@@ -96,18 +114,24 @@ exports.run = async () => { // eslint-disable-line complexity
|
|
|
96
114
|
// Enter debug mode if the main process is being inspected. This assumes the
|
|
97
115
|
// worker processes are automatically inspected, too. It is not necessary to
|
|
98
116
|
// run AVA with the debug command, though it's allowed.
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
{
|
|
117
|
+
let activeInspector = false;
|
|
118
|
+
try {
|
|
119
|
+
const {default: inspector} = await import('node:inspector'); // eslint-disable-line node/no-unsupported-features/es-syntax
|
|
120
|
+
|
|
121
|
+
activeInspector = inspector.url() !== undefined;
|
|
122
|
+
} catch {}
|
|
123
|
+
|
|
124
|
+
let debug = activeInspector
|
|
125
|
+
? {
|
|
102
126
|
active: true,
|
|
103
127
|
break: false,
|
|
104
128
|
files: [],
|
|
105
129
|
host: undefined,
|
|
106
|
-
port: undefined
|
|
130
|
+
port: undefined,
|
|
107
131
|
} : null;
|
|
108
132
|
|
|
109
133
|
let resetCache = false;
|
|
110
|
-
const {argv} = yargs
|
|
134
|
+
const {argv} = yargs(hideBin(process.argv))
|
|
111
135
|
.parserConfiguration({
|
|
112
136
|
'boolean-negation': true,
|
|
113
137
|
'camel-case-expansion': false,
|
|
@@ -121,7 +145,7 @@ exports.run = async () => { // eslint-disable-line complexity
|
|
|
121
145
|
'set-placeholder-key': false,
|
|
122
146
|
'short-option-groups': true,
|
|
123
147
|
'strip-aliased': true,
|
|
124
|
-
'unknown-options-as-args': false
|
|
148
|
+
'unknown-options-as-args': false,
|
|
125
149
|
})
|
|
126
150
|
.usage('$0 [<pattern>...]')
|
|
127
151
|
.usage('$0 debug [<pattern>...]')
|
|
@@ -129,16 +153,16 @@ exports.run = async () => { // eslint-disable-line complexity
|
|
|
129
153
|
.options({
|
|
130
154
|
color: {
|
|
131
155
|
description: 'Force color output',
|
|
132
|
-
type: 'boolean'
|
|
156
|
+
type: 'boolean',
|
|
133
157
|
},
|
|
134
158
|
config: {
|
|
135
|
-
description: 'Specific JavaScript file for AVA to read its config from, instead of using package.json or ava.config.* files'
|
|
136
|
-
}
|
|
159
|
+
description: 'Specific JavaScript file for AVA to read its config from, instead of using package.json or ava.config.* files',
|
|
160
|
+
},
|
|
137
161
|
})
|
|
138
162
|
.command('* [<pattern>...]', 'Run tests', yargs => yargs.options(FLAGS).positional('pattern', {
|
|
139
163
|
array: true,
|
|
140
|
-
describe: '
|
|
141
|
-
type: 'string'
|
|
164
|
+
describe: 'Select which test files to run. Leave empty if you want AVA to run all test files as per your configuration. Accepts glob patterns, directories that (recursively) contain test files, and file paths. Add a colon and specify line numbers of specific tests to run',
|
|
165
|
+
type: 'string',
|
|
142
166
|
}), argv => {
|
|
143
167
|
if (activeInspector) {
|
|
144
168
|
debug.files = argv.pattern || [];
|
|
@@ -150,22 +174,22 @@ exports.run = async () => { // eslint-disable-line complexity
|
|
|
150
174
|
yargs => yargs.options(FLAGS).options({
|
|
151
175
|
break: {
|
|
152
176
|
description: 'Break before the test file is loaded',
|
|
153
|
-
type: 'boolean'
|
|
177
|
+
type: 'boolean',
|
|
154
178
|
},
|
|
155
179
|
host: {
|
|
156
180
|
default: '127.0.0.1',
|
|
157
181
|
description: 'Address or hostname through which you can connect to the inspector',
|
|
158
|
-
type: 'string'
|
|
182
|
+
type: 'string',
|
|
159
183
|
},
|
|
160
184
|
port: {
|
|
161
185
|
default: 9229,
|
|
162
186
|
description: 'Port on which you can connect to the inspector',
|
|
163
|
-
type: 'number'
|
|
164
|
-
}
|
|
187
|
+
type: 'number',
|
|
188
|
+
},
|
|
165
189
|
}).positional('pattern', {
|
|
166
190
|
demand: true,
|
|
167
191
|
describe: 'Glob patterns to select a single test file to debug. Add a colon and specify line numbers of specific tests to run',
|
|
168
|
-
type: 'string'
|
|
192
|
+
type: 'string',
|
|
169
193
|
}),
|
|
170
194
|
argv => {
|
|
171
195
|
debug = {
|
|
@@ -173,12 +197,12 @@ exports.run = async () => { // eslint-disable-line complexity
|
|
|
173
197
|
break: argv.break === true,
|
|
174
198
|
files: argv.pattern,
|
|
175
199
|
host: argv.host,
|
|
176
|
-
port: argv.port
|
|
200
|
+
port: argv.port,
|
|
177
201
|
};
|
|
178
202
|
})
|
|
179
203
|
.command(
|
|
180
204
|
'reset-cache',
|
|
181
|
-
'
|
|
205
|
+
'Delete any temporary files and state kept by AVA, then exit',
|
|
182
206
|
yargs => yargs,
|
|
183
207
|
() => {
|
|
184
208
|
resetCache = true;
|
|
@@ -196,7 +220,7 @@ exports.run = async () => { // eslint-disable-line complexity
|
|
|
196
220
|
continue;
|
|
197
221
|
}
|
|
198
222
|
|
|
199
|
-
if (
|
|
223
|
+
if (argv[flag] !== undefined) {
|
|
200
224
|
if (flag === 'fail-fast') {
|
|
201
225
|
combined.failFast = argv[flag];
|
|
202
226
|
} else if (flag === 'update-snapshots') {
|
|
@@ -207,8 +231,14 @@ exports.run = async () => { // eslint-disable-line complexity
|
|
|
207
231
|
}
|
|
208
232
|
}
|
|
209
233
|
|
|
210
|
-
const chalkOptions = {level:
|
|
211
|
-
|
|
234
|
+
const chalkOptions = {level: 0};
|
|
235
|
+
if (combined.color !== false) {
|
|
236
|
+
const {supportsColor: {level}} = await import('chalk'); // eslint-disable-line node/no-unsupported-features/es-syntax, unicorn/import-style
|
|
237
|
+
chalkOptions.level = level;
|
|
238
|
+
}
|
|
239
|
+
|
|
240
|
+
const {set: setChalk} = await import('./chalk.js'); // eslint-disable-line node/no-unsupported-features/es-syntax
|
|
241
|
+
setChalk(chalkOptions);
|
|
212
242
|
|
|
213
243
|
if (confError) {
|
|
214
244
|
if (confError.parent) {
|
|
@@ -218,23 +248,23 @@ exports.run = async () => { // eslint-disable-line complexity
|
|
|
218
248
|
}
|
|
219
249
|
}
|
|
220
250
|
|
|
221
|
-
updateNotifier({pkg: require('../package.json')}).notify();
|
|
222
|
-
|
|
223
251
|
const {nonSemVerExperiments: experiments, projectDir} = conf;
|
|
224
252
|
if (resetCache) {
|
|
225
253
|
const cacheDir = path.join(projectDir, 'node_modules', '.cache', 'ava');
|
|
254
|
+
|
|
226
255
|
try {
|
|
227
|
-
await del('*', {
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
256
|
+
const deletedFilePaths = await del('*', {cwd: cacheDir});
|
|
257
|
+
|
|
258
|
+
if (deletedFilePaths.length === 0) {
|
|
259
|
+
console.log(`\n${chalk.green(figures.tick)} No cache files to remove`);
|
|
260
|
+
} else {
|
|
261
|
+
console.log(`\n${chalk.green(figures.tick)} Removed AVA cache files in ${cacheDir}`);
|
|
262
|
+
}
|
|
263
|
+
|
|
232
264
|
process.exit(0); // eslint-disable-line unicorn/no-process-exit
|
|
233
265
|
} catch (error) {
|
|
234
266
|
exit(`Error removing AVA cache files in ${cacheDir}\n\n${chalk.gray((error && error.stack) || error)}`);
|
|
235
267
|
}
|
|
236
|
-
|
|
237
|
-
return;
|
|
238
268
|
}
|
|
239
269
|
|
|
240
270
|
if (argv.watch) {
|
|
@@ -273,6 +303,10 @@ exports.run = async () => { // eslint-disable-line complexity
|
|
|
273
303
|
console.log(chalk.magenta(` ${figures.warning} Experiments are enabled. These are unsupported and may change or be removed at any time.`));
|
|
274
304
|
}
|
|
275
305
|
|
|
306
|
+
if (Reflect.has(conf, 'babel')) {
|
|
307
|
+
exit('Built-in Babel support has been removed.');
|
|
308
|
+
}
|
|
309
|
+
|
|
276
310
|
if (Reflect.has(conf, 'compileEnhancements')) {
|
|
277
311
|
exit('Enhancement compilation must be configured in AVA’s Babel options.');
|
|
278
312
|
}
|
|
@@ -285,22 +319,9 @@ exports.run = async () => { // eslint-disable-line complexity
|
|
|
285
319
|
exit('’sources’ has been removed. Use ’ignoredByWatcher’ to provide glob patterns of files that the watcher should ignore.');
|
|
286
320
|
}
|
|
287
321
|
|
|
288
|
-
const ciParallelVars = require('ci-parallel-vars');
|
|
289
|
-
const Api = require('./api');
|
|
290
|
-
const DefaultReporter = require('./reporters/default');
|
|
291
|
-
const TapReporter = require('./reporters/tap');
|
|
292
|
-
const Watcher = require('./watcher');
|
|
293
|
-
const normalizeExtensions = require('./extensions');
|
|
294
|
-
const normalizeModuleTypes = require('./module-types');
|
|
295
|
-
const {normalizeGlobs, normalizePattern} = require('./globs');
|
|
296
|
-
const normalizeNodeArguments = require('./node-arguments');
|
|
297
|
-
const validateEnvironmentVariables = require('./environment-variables');
|
|
298
|
-
const {splitPatternAndLineNumbers} = require('./line-numbers');
|
|
299
|
-
const providerManager = require('./provider-manager');
|
|
300
|
-
|
|
301
322
|
let pkg;
|
|
302
323
|
try {
|
|
303
|
-
pkg =
|
|
324
|
+
pkg = JSON.parse(fs.readFileSync(path.resolve(projectDir, 'package.json')));
|
|
304
325
|
} catch (error) {
|
|
305
326
|
if (error.code !== 'ENOENT') {
|
|
306
327
|
throw error;
|
|
@@ -310,26 +331,13 @@ exports.run = async () => { // eslint-disable-line complexity
|
|
|
310
331
|
const {type: defaultModuleType = 'commonjs'} = pkg || {};
|
|
311
332
|
|
|
312
333
|
const providers = [];
|
|
313
|
-
if (Reflect.has(conf, 'babel')) {
|
|
314
|
-
try {
|
|
315
|
-
const {level, main} = providerManager.babel(projectDir);
|
|
316
|
-
providers.push({
|
|
317
|
-
level,
|
|
318
|
-
main: main({config: conf.babel}),
|
|
319
|
-
type: 'babel'
|
|
320
|
-
});
|
|
321
|
-
} catch (error) {
|
|
322
|
-
exit(error.message);
|
|
323
|
-
}
|
|
324
|
-
}
|
|
325
|
-
|
|
326
334
|
if (Reflect.has(conf, 'typescript')) {
|
|
327
335
|
try {
|
|
328
|
-
const {level, main} = providerManager.typescript(projectDir);
|
|
336
|
+
const {level, main} = await providerManager.typescript(projectDir);
|
|
329
337
|
providers.push({
|
|
330
338
|
level,
|
|
331
339
|
main: main({config: conf.typescript}),
|
|
332
|
-
type: 'typescript'
|
|
340
|
+
type: 'typescript',
|
|
333
341
|
});
|
|
334
342
|
} catch (error) {
|
|
335
343
|
exit(error.message);
|
|
@@ -384,7 +392,7 @@ exports.run = async () => { // eslint-disable-line complexity
|
|
|
384
392
|
.map(pattern => splitPatternAndLineNumbers(pattern))
|
|
385
393
|
.map(({pattern, ...rest}) => ({
|
|
386
394
|
pattern: normalizePattern(path.relative(projectDir, path.resolve(process.cwd(), pattern))),
|
|
387
|
-
...rest
|
|
395
|
+
...rest,
|
|
388
396
|
}));
|
|
389
397
|
|
|
390
398
|
const api = new Api({
|
|
@@ -411,26 +419,26 @@ exports.run = async () => { // eslint-disable-line complexity
|
|
|
411
419
|
snapshotDir: combined.snapshotDir ? path.resolve(projectDir, combined.snapshotDir) : null,
|
|
412
420
|
timeout: combined.timeout || '10s',
|
|
413
421
|
updateSnapshots: combined.updateSnapshots,
|
|
414
|
-
workerArgv: argv['--']
|
|
422
|
+
workerArgv: argv['--'],
|
|
415
423
|
});
|
|
416
424
|
|
|
417
425
|
const reporter = combined.tap && !combined.watch && debug === null ? new TapReporter({
|
|
426
|
+
extensions: globs.extensions,
|
|
418
427
|
projectDir,
|
|
419
428
|
reportStream: process.stdout,
|
|
420
|
-
stdStream: process.stderr
|
|
429
|
+
stdStream: process.stderr,
|
|
421
430
|
}) : new DefaultReporter({
|
|
431
|
+
extensions: globs.extensions,
|
|
422
432
|
projectDir,
|
|
423
433
|
reportStream: process.stdout,
|
|
424
434
|
stdStream: process.stderr,
|
|
425
435
|
watching: combined.watch,
|
|
426
|
-
verbose: debug !== null || combined.verbose || isCi || !process.stdout.isTTY
|
|
427
436
|
});
|
|
428
437
|
|
|
429
438
|
api.on('run', plan => {
|
|
430
439
|
reporter.startRun(plan);
|
|
431
440
|
|
|
432
441
|
if (process.env.AVA_EMIT_RUN_STATUS_OVER_IPC === 'I\'ll find a payphone baby / Take some time to talk to you') {
|
|
433
|
-
const {controlFlow} = require('./ipc-flow-control');
|
|
434
442
|
const bufferedSend = controlFlow(process);
|
|
435
443
|
|
|
436
444
|
plan.status.on('stateChange', evt => {
|
|
@@ -453,7 +461,7 @@ exports.run = async () => { // eslint-disable-line complexity
|
|
|
453
461
|
globs,
|
|
454
462
|
projectDir,
|
|
455
463
|
providers,
|
|
456
|
-
reporter
|
|
464
|
+
reporter,
|
|
457
465
|
});
|
|
458
466
|
watcher.observeStdin(process.stdin);
|
|
459
467
|
} else {
|
|
@@ -474,4 +482,4 @@ exports.run = async () => { // eslint-disable-line complexity
|
|
|
474
482
|
process.exitCode = runStatus.suggestExitCode({matching: match.length > 0});
|
|
475
483
|
reporter.endRun();
|
|
476
484
|
}
|
|
477
|
-
}
|
|
485
|
+
}
|
package/lib/code-excerpt.js
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
1
|
+
import fs from 'node:fs';
|
|
2
|
+
|
|
3
|
+
import truncate from 'cli-truncate';
|
|
4
|
+
import codeExcerpt from 'code-excerpt';
|
|
5
|
+
|
|
6
|
+
import {chalk} from './chalk.js';
|
|
7
7
|
|
|
8
8
|
const formatLineNumber = (lineNumber, maxLineNumber) =>
|
|
9
9
|
' '.repeat(Math.max(0, String(maxLineNumber).length - String(lineNumber).length)) + lineNumber;
|
|
10
10
|
|
|
11
|
-
|
|
11
|
+
export default function exceptCode(source, options = {}) {
|
|
12
12
|
if (!source.isWithinProject || source.isDependency) {
|
|
13
13
|
return null;
|
|
14
14
|
}
|
|
@@ -18,7 +18,7 @@ module.exports = (source, options = {}) => {
|
|
|
18
18
|
|
|
19
19
|
let contents;
|
|
20
20
|
try {
|
|
21
|
-
contents = fs.readFileSync(file, 'utf8');
|
|
21
|
+
contents = fs.readFileSync(new URL(file), 'utf8');
|
|
22
22
|
} catch {
|
|
23
23
|
return null;
|
|
24
24
|
}
|
|
@@ -30,25 +30,20 @@ module.exports = (source, options = {}) => {
|
|
|
30
30
|
|
|
31
31
|
const lines = excerpt.map(item => ({
|
|
32
32
|
line: item.line,
|
|
33
|
-
value: truncate(item.value, maxWidth - String(line).length - 5)
|
|
33
|
+
value: truncate(item.value, maxWidth - String(line).length - 5),
|
|
34
34
|
}));
|
|
35
35
|
|
|
36
|
-
const
|
|
37
|
-
const extendedLines = equalLength(joinedLines).split('\n');
|
|
36
|
+
const extendedWidth = Math.max(...lines.map(item => item.value.length));
|
|
38
37
|
|
|
39
38
|
return lines
|
|
40
|
-
.map((item, index) => ({
|
|
41
|
-
line: item.line,
|
|
42
|
-
value: extendedLines[index]
|
|
43
|
-
}))
|
|
44
39
|
.map(item => {
|
|
45
40
|
const isErrorSource = item.line === line;
|
|
46
41
|
|
|
47
42
|
const lineNumber = formatLineNumber(item.line, line) + ':';
|
|
48
43
|
const coloredLineNumber = isErrorSource ? lineNumber : chalk.grey(lineNumber);
|
|
49
|
-
const result = ` ${coloredLineNumber} ${item.value}`;
|
|
44
|
+
const result = ` ${coloredLineNumber} ${item.value.padEnd(extendedWidth)}`;
|
|
50
45
|
|
|
51
46
|
return isErrorSource ? chalk.bgRed(result) : result;
|
|
52
47
|
})
|
|
53
48
|
.join('\n');
|
|
54
|
-
}
|
|
49
|
+
}
|
|
@@ -1,31 +1,32 @@
|
|
|
1
|
-
|
|
2
|
-
const util = require('util'); // eslint-disable-line unicorn/import-style
|
|
3
|
-
const ansiStyles = require('ansi-styles');
|
|
4
|
-
const stripAnsi = require('strip-ansi');
|
|
5
|
-
const cloneDeepWith = require('lodash/cloneDeepWith');
|
|
6
|
-
const chalk = require('./chalk').get();
|
|
1
|
+
import {inspect} from 'node:util';
|
|
7
2
|
|
|
8
|
-
|
|
3
|
+
import ansiStyles from 'ansi-styles';
|
|
4
|
+
import {Chalk} from 'chalk'; // eslint-disable-line unicorn/import-style
|
|
5
|
+
import stripAnsi from 'strip-ansi';
|
|
6
|
+
|
|
7
|
+
import {chalk} from './chalk.js';
|
|
8
|
+
|
|
9
|
+
const forceColor = new Chalk({level: Math.max(chalk.level, 1)});
|
|
9
10
|
|
|
10
11
|
const colorTheme = {
|
|
11
12
|
boolean: ansiStyles.yellow,
|
|
12
13
|
circular: forceColor.grey('[Circular]'),
|
|
13
14
|
date: {
|
|
14
15
|
invalid: forceColor.red('invalid'),
|
|
15
|
-
value: ansiStyles.blue
|
|
16
|
+
value: ansiStyles.blue,
|
|
16
17
|
},
|
|
17
18
|
diffGutters: {
|
|
18
19
|
actual: forceColor.red('-') + ' ',
|
|
19
20
|
expected: forceColor.green('+') + ' ',
|
|
20
|
-
padding: ' '
|
|
21
|
+
padding: ' ',
|
|
21
22
|
},
|
|
22
23
|
error: {
|
|
23
24
|
ctor: {open: ansiStyles.grey.open + '(', close: ')' + ansiStyles.grey.close},
|
|
24
|
-
name: ansiStyles.magenta
|
|
25
|
+
name: ansiStyles.magenta,
|
|
25
26
|
},
|
|
26
27
|
function: {
|
|
27
28
|
name: ansiStyles.blue,
|
|
28
|
-
stringTag: ansiStyles.magenta
|
|
29
|
+
stringTag: ansiStyles.magenta,
|
|
29
30
|
},
|
|
30
31
|
global: ansiStyles.magenta,
|
|
31
32
|
item: {after: forceColor.grey(',')},
|
|
@@ -39,16 +40,16 @@ const colorTheme = {
|
|
|
39
40
|
closeBracket: forceColor.grey('}'),
|
|
40
41
|
ctor: ansiStyles.magenta,
|
|
41
42
|
stringTag: {open: ansiStyles.magenta.open + '@', close: ansiStyles.magenta.close},
|
|
42
|
-
secondaryStringTag: {open: ansiStyles.grey.open + '@', close: ansiStyles.grey.close}
|
|
43
|
+
secondaryStringTag: {open: ansiStyles.grey.open + '@', close: ansiStyles.grey.close},
|
|
43
44
|
},
|
|
44
45
|
property: {
|
|
45
46
|
after: forceColor.grey(','),
|
|
46
47
|
keyBracket: {open: forceColor.grey('['), close: forceColor.grey(']')},
|
|
47
|
-
valueFallback: forceColor.grey('…')
|
|
48
|
+
valueFallback: forceColor.grey('…'),
|
|
48
49
|
},
|
|
49
50
|
regexp: {
|
|
50
51
|
source: {open: ansiStyles.blue.open + '/', close: '/' + ansiStyles.blue.close},
|
|
51
|
-
flags: ansiStyles.yellow
|
|
52
|
+
flags: ansiStyles.yellow,
|
|
52
53
|
},
|
|
53
54
|
stats: {separator: forceColor.grey('---')},
|
|
54
55
|
string: {
|
|
@@ -60,44 +61,42 @@ const colorTheme = {
|
|
|
60
61
|
diff: {
|
|
61
62
|
insert: {
|
|
62
63
|
open: ansiStyles.bgGreen.open + ansiStyles.black.open,
|
|
63
|
-
close: ansiStyles.black.close + ansiStyles.bgGreen.close
|
|
64
|
+
close: ansiStyles.black.close + ansiStyles.bgGreen.close,
|
|
64
65
|
},
|
|
65
66
|
delete: {
|
|
66
67
|
open: ansiStyles.bgRed.open + ansiStyles.black.open,
|
|
67
|
-
close: ansiStyles.black.close + ansiStyles.bgRed.close
|
|
68
|
+
close: ansiStyles.black.close + ansiStyles.bgRed.close,
|
|
68
69
|
},
|
|
69
70
|
equal: ansiStyles.blue,
|
|
70
71
|
insertLine: {
|
|
71
72
|
open: ansiStyles.green.open,
|
|
72
|
-
close: ansiStyles.green.close
|
|
73
|
+
close: ansiStyles.green.close,
|
|
73
74
|
},
|
|
74
75
|
deleteLine: {
|
|
75
76
|
open: ansiStyles.red.open,
|
|
76
|
-
close: ansiStyles.red.close
|
|
77
|
-
}
|
|
78
|
-
}
|
|
77
|
+
close: ansiStyles.red.close,
|
|
78
|
+
},
|
|
79
|
+
},
|
|
79
80
|
},
|
|
80
81
|
symbol: ansiStyles.yellow,
|
|
81
82
|
typedArray: {
|
|
82
|
-
bytes: ansiStyles.yellow
|
|
83
|
+
bytes: ansiStyles.yellow,
|
|
83
84
|
},
|
|
84
|
-
undefined: ansiStyles.yellow
|
|
85
|
+
undefined: ansiStyles.yellow,
|
|
85
86
|
};
|
|
86
87
|
|
|
87
|
-
const plainTheme =
|
|
88
|
-
if (typeof value === 'string') {
|
|
89
|
-
return stripAnsi(value);
|
|
90
|
-
}
|
|
91
|
-
});
|
|
88
|
+
const plainTheme = JSON.parse(JSON.stringify(colorTheme), value => typeof value === 'string' ? stripAnsi(value) : value);
|
|
92
89
|
|
|
93
90
|
const theme = chalk.level > 0 ? colorTheme : plainTheme;
|
|
94
91
|
|
|
95
|
-
|
|
92
|
+
const concordanceOptions = {
|
|
96
93
|
// Use Node's object inspection depth, clamped to a minimum of 3
|
|
97
94
|
get maxDepth() {
|
|
98
|
-
return Math.max(3,
|
|
95
|
+
return Math.max(3, inspect.defaultOptions.depth);
|
|
99
96
|
},
|
|
100
|
-
theme
|
|
97
|
+
theme,
|
|
101
98
|
};
|
|
102
99
|
|
|
103
|
-
|
|
100
|
+
export default concordanceOptions;
|
|
101
|
+
|
|
102
|
+
export const snapshotManager = {theme: plainTheme};
|
package/lib/context-ref.js
CHANGED
|
@@ -1,7 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
const clone = require('lodash/clone');
|
|
3
|
-
|
|
4
|
-
class ContextRef {
|
|
1
|
+
export default class ContextRef {
|
|
5
2
|
constructor() {
|
|
6
3
|
this.value = {};
|
|
7
4
|
}
|
|
@@ -18,7 +15,6 @@ class ContextRef {
|
|
|
18
15
|
return new LateBinding(this);
|
|
19
16
|
}
|
|
20
17
|
}
|
|
21
|
-
module.exports = ContextRef;
|
|
22
18
|
|
|
23
19
|
class LateBinding extends ContextRef {
|
|
24
20
|
constructor(ref) {
|
|
@@ -29,7 +25,8 @@ class LateBinding extends ContextRef {
|
|
|
29
25
|
|
|
30
26
|
get() {
|
|
31
27
|
if (!this.bound) {
|
|
32
|
-
this.
|
|
28
|
+
const value = this.ref.get();
|
|
29
|
+
this.set(value !== null && typeof value === 'object' ? {...value} : value);
|
|
33
30
|
}
|
|
34
31
|
|
|
35
32
|
return super.get();
|