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.
- package/entrypoints/cli.mjs +4 -0
- package/entrypoints/eslint-plugin-helper.cjs +109 -0
- 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 -816
- package/lib/api.js +108 -49
- package/lib/assert.js +255 -270
- package/lib/chalk.js +9 -14
- package/lib/cli.js +118 -112
- package/lib/code-excerpt.js +12 -17
- package/lib/concordance-options.js +29 -65
- package/lib/context-ref.js +3 -6
- package/lib/create-chain.js +32 -20
- package/lib/environment-variables.js +1 -4
- package/lib/eslint-plugin-helper-worker.js +73 -0
- package/lib/extensions.js +2 -2
- package/lib/fork.js +81 -84
- 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 +11 -18
- package/lib/load-config.js +56 -180
- package/lib/module-types.js +3 -7
- 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 -46
- package/lib/provider-manager.js +20 -14
- package/lib/reporters/beautify-stack.js +6 -12
- package/lib/reporters/colors.js +40 -15
- package/lib/reporters/default.js +114 -364
- 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 +18 -25
- package/lib/run-status.js +29 -23
- package/lib/runner.js +157 -172
- package/lib/scheduler.js +53 -0
- package/lib/serialize-error.js +61 -64
- package/lib/snapshot-manager.js +271 -289
- package/lib/test.js +135 -291
- package/lib/watcher.js +69 -44
- package/lib/worker/base.js +208 -0
- package/lib/worker/channel.cjs +290 -0
- package/lib/worker/dependency-tracker.js +24 -23
- package/lib/worker/{ensure-forked.js → guard-environment.cjs} +5 -4
- package/lib/worker/line-numbers.js +58 -20
- package/lib/worker/main.cjs +12 -0
- package/lib/worker/{options.js → options.cjs} +0 -0
- package/lib/worker/{plugin.js → plugin.cjs} +30 -21
- package/lib/worker/state.cjs +5 -0
- package/lib/worker/utils.cjs +6 -0
- package/package.json +71 -68
- package/plugin.d.ts +51 -53
- package/readme.md +5 -13
- 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/eslint-plugin-helper.js +0 -201
- package/index.js +0 -8
- package/lib/worker/ipc.js +0 -201
- package/lib/worker/main.js +0 -21
- package/lib/worker/subprocess.js +0 -266
- package/plugin.js +0 -9
package/lib/serialize-error.js
CHANGED
|
@@ -1,42 +1,45 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
1
|
+
import path from 'node:path';
|
|
2
|
+
import process from 'node:process';
|
|
3
|
+
import {fileURLToPath, pathToFileURL} from 'node:url';
|
|
4
|
+
|
|
5
|
+
import cleanYamlObject from 'clean-yaml-object';
|
|
6
|
+
import concordance from 'concordance';
|
|
7
|
+
import isError from 'is-error';
|
|
8
|
+
import StackUtils from 'stack-utils';
|
|
9
|
+
|
|
10
|
+
import {AssertionError} from './assert.js';
|
|
11
|
+
import concordanceOptions from './concordance-options.js';
|
|
10
12
|
|
|
11
13
|
function isAvaAssertionError(source) {
|
|
12
|
-
return source instanceof
|
|
14
|
+
return source instanceof AssertionError;
|
|
13
15
|
}
|
|
14
16
|
|
|
15
17
|
function filter(propertyName, isRoot) {
|
|
16
18
|
return !isRoot || (propertyName !== 'message' && propertyName !== 'name' && propertyName !== 'stack');
|
|
17
19
|
}
|
|
18
20
|
|
|
21
|
+
function normalizeFile(file, ...base) {
|
|
22
|
+
return file.startsWith('file://') ? file : pathToFileURL(path.resolve(...base, file)).toString();
|
|
23
|
+
}
|
|
24
|
+
|
|
19
25
|
const stackUtils = new StackUtils();
|
|
20
26
|
function extractSource(stack, testFile) {
|
|
21
27
|
if (!stack || !testFile) {
|
|
22
28
|
return null;
|
|
23
29
|
}
|
|
24
30
|
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
const normalizedFile = process.platform === 'win32' ? slash(relFile) : relFile;
|
|
31
|
+
testFile = normalizeFile(testFile);
|
|
32
|
+
|
|
28
33
|
for (const line of stack.split('\n')) {
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
}
|
|
39
|
-
} catch {}
|
|
34
|
+
const callSite = stackUtils.parseLine(line);
|
|
35
|
+
if (callSite && normalizeFile(callSite.file) === testFile) {
|
|
36
|
+
return {
|
|
37
|
+
isDependency: false,
|
|
38
|
+
isWithinProject: true,
|
|
39
|
+
file: testFile,
|
|
40
|
+
line: callSite.line,
|
|
41
|
+
};
|
|
42
|
+
}
|
|
40
43
|
}
|
|
41
44
|
|
|
42
45
|
return null;
|
|
@@ -52,8 +55,8 @@ function buildSource(source) {
|
|
|
52
55
|
// directory set to the project directory.
|
|
53
56
|
const projectDir = process.cwd();
|
|
54
57
|
|
|
55
|
-
const file =
|
|
56
|
-
const rel = path.relative(projectDir, file);
|
|
58
|
+
const file = normalizeFile(source.file.trim(), projectDir);
|
|
59
|
+
const rel = path.relative(projectDir, fileURLToPath(file));
|
|
57
60
|
|
|
58
61
|
const [segment] = rel.split(path.sep);
|
|
59
62
|
const isWithinProject = segment !== '..' && (process.platform !== 'win32' || !segment.includes(':'));
|
|
@@ -63,60 +66,59 @@ function buildSource(source) {
|
|
|
63
66
|
isDependency,
|
|
64
67
|
isWithinProject,
|
|
65
68
|
file,
|
|
66
|
-
line: source.line
|
|
69
|
+
line: source.line,
|
|
67
70
|
};
|
|
68
71
|
}
|
|
69
72
|
|
|
70
|
-
function trySerializeError(
|
|
71
|
-
const stack =
|
|
73
|
+
function trySerializeError(error, shouldBeautifyStack, testFile) {
|
|
74
|
+
const stack = error.savedError ? error.savedError.stack : error.stack;
|
|
72
75
|
|
|
73
76
|
const retval = {
|
|
74
|
-
avaAssertionError: isAvaAssertionError(
|
|
77
|
+
avaAssertionError: isAvaAssertionError(error),
|
|
75
78
|
nonErrorObject: false,
|
|
76
79
|
source: extractSource(stack, testFile),
|
|
77
80
|
stack,
|
|
78
|
-
shouldBeautifyStack
|
|
81
|
+
shouldBeautifyStack,
|
|
79
82
|
};
|
|
80
83
|
|
|
81
|
-
if (
|
|
82
|
-
retval.stack =
|
|
84
|
+
if (error.actualStack) {
|
|
85
|
+
retval.stack = error.actualStack;
|
|
83
86
|
}
|
|
84
87
|
|
|
85
88
|
if (retval.avaAssertionError) {
|
|
86
|
-
retval.improperUsage =
|
|
87
|
-
retval.message =
|
|
88
|
-
retval.name =
|
|
89
|
-
retval.
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
const source = buildSource(err.fixedSource);
|
|
89
|
+
retval.improperUsage = error.improperUsage;
|
|
90
|
+
retval.message = error.message;
|
|
91
|
+
retval.name = error.name;
|
|
92
|
+
retval.values = error.values;
|
|
93
|
+
|
|
94
|
+
if (error.fixedSource) {
|
|
95
|
+
const source = buildSource(error.fixedSource);
|
|
94
96
|
if (source) {
|
|
95
97
|
retval.source = source;
|
|
96
98
|
}
|
|
97
99
|
}
|
|
98
100
|
|
|
99
|
-
if (
|
|
100
|
-
retval.assertion =
|
|
101
|
+
if (error.assertion) {
|
|
102
|
+
retval.assertion = error.assertion;
|
|
101
103
|
}
|
|
102
104
|
|
|
103
|
-
if (
|
|
104
|
-
retval.operator =
|
|
105
|
+
if (error.operator) {
|
|
106
|
+
retval.operator = error.operator;
|
|
105
107
|
}
|
|
106
108
|
} else {
|
|
107
|
-
retval.object = cleanYamlObject(
|
|
108
|
-
if (typeof
|
|
109
|
-
retval.message =
|
|
109
|
+
retval.object = cleanYamlObject(error, filter); // Cleanly copy non-standard properties
|
|
110
|
+
if (typeof error.message === 'string') {
|
|
111
|
+
retval.message = error.message;
|
|
110
112
|
}
|
|
111
113
|
|
|
112
|
-
if (typeof
|
|
113
|
-
retval.name =
|
|
114
|
+
if (typeof error.name === 'string') {
|
|
115
|
+
retval.name = error.name;
|
|
114
116
|
}
|
|
115
117
|
}
|
|
116
118
|
|
|
117
|
-
if (typeof
|
|
118
|
-
const lines =
|
|
119
|
-
if (
|
|
119
|
+
if (typeof error.stack === 'string') {
|
|
120
|
+
const lines = error.stack.split('\n');
|
|
121
|
+
if (error.name === 'SyntaxError' && !lines[0].startsWith('SyntaxError')) {
|
|
120
122
|
retval.summary = '';
|
|
121
123
|
for (const line of lines) {
|
|
122
124
|
retval.summary += line + '\n';
|
|
@@ -127,11 +129,8 @@ function trySerializeError(err, shouldBeautifyStack, testFile) {
|
|
|
127
129
|
|
|
128
130
|
retval.summary = retval.summary.trim();
|
|
129
131
|
} else {
|
|
130
|
-
// Skip the source line header inserted by `esm`:
|
|
131
|
-
// <https://github.com/standard-things/esm/wiki/improved-errors>
|
|
132
|
-
const start = lines.findIndex(line => !/:\d+$/.test(line));
|
|
133
132
|
retval.summary = '';
|
|
134
|
-
for (let index =
|
|
133
|
+
for (let index = 0; index < lines.length; index++) {
|
|
135
134
|
if (lines[index].startsWith(' at')) {
|
|
136
135
|
break;
|
|
137
136
|
}
|
|
@@ -146,17 +145,17 @@ function trySerializeError(err, shouldBeautifyStack, testFile) {
|
|
|
146
145
|
return retval;
|
|
147
146
|
}
|
|
148
147
|
|
|
149
|
-
function serializeError(origin, shouldBeautifyStack,
|
|
150
|
-
if (!isError(
|
|
148
|
+
export default function serializeError(origin, shouldBeautifyStack, error, testFile) {
|
|
149
|
+
if (!isError(error)) {
|
|
151
150
|
return {
|
|
152
151
|
avaAssertionError: false,
|
|
153
152
|
nonErrorObject: true,
|
|
154
|
-
formatted: concordance.formatDescriptor(concordance.describe(
|
|
153
|
+
formatted: concordance.formatDescriptor(concordance.describe(error, concordanceOptions), concordanceOptions),
|
|
155
154
|
};
|
|
156
155
|
}
|
|
157
156
|
|
|
158
157
|
try {
|
|
159
|
-
return trySerializeError(
|
|
158
|
+
return trySerializeError(error, shouldBeautifyStack, testFile);
|
|
160
159
|
} catch {
|
|
161
160
|
const replacement = new Error(`${origin}: Could not serialize error`);
|
|
162
161
|
return {
|
|
@@ -165,9 +164,7 @@ function serializeError(origin, shouldBeautifyStack, err, testFile) {
|
|
|
165
164
|
name: replacement.name,
|
|
166
165
|
message: replacement.message,
|
|
167
166
|
stack: replacement.stack,
|
|
168
|
-
summary: replacement.message
|
|
167
|
+
summary: replacement.message,
|
|
169
168
|
};
|
|
170
169
|
}
|
|
171
170
|
}
|
|
172
|
-
|
|
173
|
-
module.exports = serializeError;
|