test-inventory 0.9.0 → 0.9.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/CHANGELOG.md +100 -0
- package/dist/config-runs.d.ts +3 -3
- package/dist/config-runs.js +64 -32
- package/dist/files.d.ts +3 -2
- package/dist/files.js +52 -9
- package/dist/frameworks/bun.d.ts +2 -0
- package/dist/frameworks/bun.js +10 -2
- package/dist/frameworks/jasmine.d.ts +4 -3
- package/dist/frameworks/jasmine.js +13 -3
- package/dist/frameworks/mocha.js +3 -2
- package/dist/frameworks/node.js +11 -8
- package/dist/frameworks/playwright.d.ts +5 -0
- package/dist/frameworks/playwright.js +27 -0
- package/dist/frameworks/test-functions.js +9 -0
- package/dist/node-scripts.d.ts +5 -0
- package/dist/node-scripts.js +53 -2
- package/dist/records.d.ts +2 -0
- package/dist/records.js +45 -15
- package/dist/resolve.d.ts +7 -1
- package/dist/resolve.js +16 -4
- package/dist/scan-file.js +2 -0
- package/dist/toml.js +10 -3
- package/dist/yaml.d.ts +2 -1
- package/dist/yaml.js +174 -35
- package/package.json +8 -2
package/dist/yaml.js
CHANGED
|
@@ -9,15 +9,34 @@ export class YamlError extends Error {
|
|
|
9
9
|
/**
|
|
10
10
|
* The value of a YAML config as Mocha's `.mocharc.yml` files write it: a map of keys to scalars, to lists written one
|
|
11
11
|
* item per line or in brackets, and to maps of those. Anchors, multi-line strings, flow maps and documents after the
|
|
12
|
-
* first are refused with a `YamlError`, as a guess at them could read the wrong test files
|
|
12
|
+
* first are refused with a `YamlError`, as a guess at them could read the wrong test files, and so is what js-yaml,
|
|
13
|
+
* Mocha's reader, refuses: a key set twice, a tab in the indent, or `: ` in a plain value.
|
|
13
14
|
*/
|
|
14
15
|
export function readYaml(text) {
|
|
15
16
|
const lines = [];
|
|
16
|
-
|
|
17
|
+
let ended = false;
|
|
18
|
+
text
|
|
19
|
+
.replace(/^\uFEFF/, '')
|
|
20
|
+
.split(/\r?\n/)
|
|
21
|
+
.forEach((raw, index) => {
|
|
17
22
|
const content = withoutComment(raw);
|
|
18
|
-
|
|
23
|
+
const trimmed = content.trim();
|
|
24
|
+
if (trimmed === '')
|
|
19
25
|
return;
|
|
20
|
-
|
|
26
|
+
const number = index + 1;
|
|
27
|
+
// Directives and the `---` that starts the document come before its content, and `...` ends it.
|
|
28
|
+
if (lines.length === 0 && !ended && (trimmed === '---' || trimmed.startsWith('%')))
|
|
29
|
+
return;
|
|
30
|
+
if (ended || trimmed === '---')
|
|
31
|
+
throw new YamlError('documents after the first are not read', number);
|
|
32
|
+
if (trimmed === '...') {
|
|
33
|
+
ended = true;
|
|
34
|
+
return;
|
|
35
|
+
}
|
|
36
|
+
const indent = content.slice(0, content.length - content.trimStart().length);
|
|
37
|
+
if (indent.includes('\t'))
|
|
38
|
+
throw new YamlError('the line is indented with a tab, which YAML refuses', number);
|
|
39
|
+
lines.push({ number, indent: indent.length, text: trimmed });
|
|
21
40
|
});
|
|
22
41
|
if (lines.length === 0)
|
|
23
42
|
return {};
|
|
@@ -26,18 +45,25 @@ export function readYaml(text) {
|
|
|
26
45
|
throw new YamlError('a line is indented less than the one it continues', lines[next].number);
|
|
27
46
|
return value;
|
|
28
47
|
}
|
|
48
|
+
/** Whether a line is a list item: a `-` alone or before a space, as `-a.js` is a plain value. */
|
|
49
|
+
function isItem(text) {
|
|
50
|
+
return /^-(\s|$)/.test(text);
|
|
51
|
+
}
|
|
29
52
|
/** A map or a list whose lines start at `indent`, and the index of the line after it. */
|
|
30
53
|
function block(lines, start, indent) {
|
|
31
|
-
if (lines[start].text
|
|
54
|
+
if (isItem(lines[start].text))
|
|
32
55
|
return list(lines, start, indent);
|
|
33
|
-
|
|
56
|
+
// Without a prototype, a `__proto__` key is the map's own, as js-yaml, which Mocha uses, reads it.
|
|
57
|
+
const map = Object.create(null);
|
|
34
58
|
let index = start;
|
|
35
59
|
while (index < lines.length && lines[index].indent === indent) {
|
|
36
60
|
const line = lines[index];
|
|
37
61
|
const match = /^("[^"]*"|'[^']*'|[^\s:'"][^:]*?)\s*:(?:\s+(.*))?$/.exec(line.text);
|
|
38
62
|
if (!match)
|
|
39
63
|
throw new YamlError(`"${line.text}" is not a key and its value`, line.number);
|
|
40
|
-
const key = unquote(match[1]);
|
|
64
|
+
const key = unquote(match[1], line.number);
|
|
65
|
+
if (Object.hasOwn(map, key))
|
|
66
|
+
throw new YamlError(`${key} is set twice, which YAML refuses`, line.number);
|
|
41
67
|
// An optional group that matched nothing is undefined, though the type says it is a string.
|
|
42
68
|
const value = match[2];
|
|
43
69
|
if (value !== undefined) {
|
|
@@ -47,9 +73,7 @@ function block(lines, start, indent) {
|
|
|
47
73
|
else if (index + 1 < lines.length && lines[index + 1].indent > indent) {
|
|
48
74
|
[map[key], index] = block(lines, index + 1, lines[index + 1].indent);
|
|
49
75
|
}
|
|
50
|
-
else if (index + 1 < lines.length &&
|
|
51
|
-
lines[index + 1].indent === indent &&
|
|
52
|
-
lines[index + 1].text.startsWith('-')) {
|
|
76
|
+
else if (index + 1 < lines.length && lines[index + 1].indent === indent && isItem(lines[index + 1].text)) {
|
|
53
77
|
// A list may sit at the same indent as its key.
|
|
54
78
|
[map[key], index] = list(lines, index + 1, indent);
|
|
55
79
|
}
|
|
@@ -63,7 +87,7 @@ function block(lines, start, indent) {
|
|
|
63
87
|
function list(lines, start, indent) {
|
|
64
88
|
const items = [];
|
|
65
89
|
let index = start;
|
|
66
|
-
while (index < lines.length && lines[index].indent === indent && lines[index].text
|
|
90
|
+
while (index < lines.length && lines[index].indent === indent && isItem(lines[index].text)) {
|
|
67
91
|
const line = lines[index];
|
|
68
92
|
const item = line.text.slice(1).trim();
|
|
69
93
|
if (item === '' || /^[^'"[\]]*:(\s|$)/.test(item)) {
|
|
@@ -79,30 +103,58 @@ function scalarOrFlow(text, line) {
|
|
|
79
103
|
if (text.startsWith('[')) {
|
|
80
104
|
if (!text.endsWith(']'))
|
|
81
105
|
throw new YamlError('a list in brackets must end on its line', line);
|
|
106
|
+
const items = flowItems(text.slice(1, -1));
|
|
82
107
|
// A trailing comma ends the list without another item, as in `[ts, js,]`.
|
|
83
|
-
const items = text
|
|
84
|
-
.slice(1, -1)
|
|
85
|
-
.split(',')
|
|
86
|
-
.map((item) => item.trim());
|
|
87
108
|
if (items.at(-1) === '')
|
|
88
109
|
items.pop();
|
|
110
|
+
if (items.includes(''))
|
|
111
|
+
throw new YamlError('a list in brackets has an empty item', line);
|
|
89
112
|
return items.map((item) => scalar(item, line));
|
|
90
113
|
}
|
|
91
114
|
return scalar(text, line);
|
|
92
115
|
}
|
|
116
|
+
/** The items of a list in brackets, split at the commas outside quotes. */
|
|
117
|
+
function flowItems(inner) {
|
|
118
|
+
const items = [];
|
|
119
|
+
let item = '';
|
|
120
|
+
let quote = null;
|
|
121
|
+
for (let index = 0; index < inner.length; index++) {
|
|
122
|
+
const char = inner[index];
|
|
123
|
+
if (quote === null && char === ',') {
|
|
124
|
+
items.push(item.trim());
|
|
125
|
+
item = '';
|
|
126
|
+
continue;
|
|
127
|
+
}
|
|
128
|
+
item += char;
|
|
129
|
+
if (quote === null) {
|
|
130
|
+
if ((char === '"' || char === "'") && item.trim() === char)
|
|
131
|
+
quote = char;
|
|
132
|
+
}
|
|
133
|
+
else if (quote === '"' && char === '\\') {
|
|
134
|
+
item += inner[++index] ?? '';
|
|
135
|
+
}
|
|
136
|
+
else if (char === quote) {
|
|
137
|
+
if (quote === "'" && inner[index + 1] === "'")
|
|
138
|
+
item += inner[++index];
|
|
139
|
+
else
|
|
140
|
+
quote = null;
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
items.push(item.trim());
|
|
144
|
+
return items;
|
|
145
|
+
}
|
|
93
146
|
function scalar(text, line) {
|
|
94
147
|
if (/^["']/.test(text)) {
|
|
95
148
|
if (text.length < 2 || text.at(-1) !== text[0])
|
|
96
149
|
throw new YamlError('a quoted value must end on its line', line);
|
|
97
|
-
|
|
98
|
-
return unquote(text);
|
|
99
|
-
}
|
|
100
|
-
catch {
|
|
101
|
-
throw new YamlError(`${text} has an escape that is not read`, line);
|
|
102
|
-
}
|
|
150
|
+
return unquote(text, line);
|
|
103
151
|
}
|
|
104
|
-
|
|
152
|
+
// `@`, `` ` `` and `%` are reserved, and `- `, `? ` and `: ` start a list, a key or a value, as js-yaml reads them.
|
|
153
|
+
if (/^([&*!|>{[\]@`%]|[-?:](\s|$))/.test(text))
|
|
105
154
|
throw new YamlError(`"${text}" uses YAML that is not read`, line);
|
|
155
|
+
if (/:(\s|$)/.test(text)) {
|
|
156
|
+
throw new YamlError(`"${text}" has a colon and a space outside quotes, which YAML refuses`, line);
|
|
157
|
+
}
|
|
106
158
|
if (/^(true|True|TRUE)$/.test(text))
|
|
107
159
|
return true;
|
|
108
160
|
if (/^(false|False|FALSE)$/.test(text))
|
|
@@ -114,35 +166,122 @@ function scalar(text, line) {
|
|
|
114
166
|
return Number.parseInt(text.slice(2), 8);
|
|
115
167
|
if (/^0x[\da-fA-F]+$/.test(text))
|
|
116
168
|
return Number.parseInt(text.slice(2), 16);
|
|
117
|
-
|
|
169
|
+
// A sign needs a digit after it: js-yaml reads `-.5` as a string.
|
|
170
|
+
if (/^([-+]?\d+(\.\d*)?|\.\d+)([eE][-+]?\d+)?$/.test(text))
|
|
118
171
|
return Number(text);
|
|
119
172
|
return text;
|
|
120
173
|
}
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
174
|
+
/** YAML's escapes in double quotes, besides `\\x`, `\\u` and `\\U` with hex digits. */
|
|
175
|
+
const ESCAPES = {
|
|
176
|
+
'0': '\0',
|
|
177
|
+
a: '\x07',
|
|
178
|
+
b: '\b',
|
|
179
|
+
t: '\t',
|
|
180
|
+
'\t': '\t',
|
|
181
|
+
n: '\n',
|
|
182
|
+
v: '\v',
|
|
183
|
+
f: '\f',
|
|
184
|
+
r: '\r',
|
|
185
|
+
e: '\x1B',
|
|
186
|
+
' ': ' ',
|
|
187
|
+
'"': '"',
|
|
188
|
+
'/': '/',
|
|
189
|
+
'\\': '\\',
|
|
190
|
+
N: '\x85',
|
|
191
|
+
_: '\xA0',
|
|
192
|
+
L: '\u2028',
|
|
193
|
+
P: '\u2029',
|
|
194
|
+
};
|
|
195
|
+
const HEX_DIGITS = { x: 2, u: 4, U: 8 };
|
|
196
|
+
/** A quoted key or value without its quotes: `''` is a quote in single quotes, and double quotes take escapes. */
|
|
197
|
+
function unquote(text, line) {
|
|
198
|
+
if (!/^["']/.test(text))
|
|
199
|
+
return text;
|
|
200
|
+
const inner = text.slice(1, -1);
|
|
201
|
+
if (text.startsWith("'")) {
|
|
202
|
+
if (inner.replaceAll("''", '').includes("'"))
|
|
203
|
+
throw new YamlError('a quoted value must end on its line', line);
|
|
204
|
+
return inner.replaceAll("''", "'");
|
|
205
|
+
}
|
|
206
|
+
let value = '';
|
|
207
|
+
for (let index = 0; index < inner.length; index++) {
|
|
208
|
+
const char = inner[index];
|
|
209
|
+
if (char === '"')
|
|
210
|
+
throw new YamlError('a quoted value must end on its line', line);
|
|
211
|
+
if (char !== '\\') {
|
|
212
|
+
value += char;
|
|
213
|
+
continue;
|
|
214
|
+
}
|
|
215
|
+
const escape = inner[++index] ?? '';
|
|
216
|
+
const size = HEX_DIGITS[escape] ?? 0;
|
|
217
|
+
const digits = inner.slice(index + 1, index + 1 + size);
|
|
218
|
+
const code = size > 0 && /^[\da-fA-F]+$/.test(digits) ? Number.parseInt(digits, 16) : Number.NaN;
|
|
219
|
+
if (digits.length === size && code <= 0x10ffff) {
|
|
220
|
+
value += String.fromCodePoint(code);
|
|
221
|
+
index += size;
|
|
222
|
+
}
|
|
223
|
+
else if (size === 0 && Object.hasOwn(ESCAPES, escape)) {
|
|
224
|
+
value += ESCAPES[escape];
|
|
225
|
+
}
|
|
226
|
+
else if (escape === '') {
|
|
227
|
+
throw new YamlError('a quoted value must end on its line', line);
|
|
228
|
+
}
|
|
229
|
+
else {
|
|
230
|
+
throw new YamlError(`${text} has an escape that is not read`, line);
|
|
231
|
+
}
|
|
232
|
+
}
|
|
233
|
+
return value;
|
|
127
234
|
}
|
|
128
235
|
/**
|
|
129
236
|
* The line without a `#` comment, which starts after a space or at the start, outside quotes. A quote opens only where
|
|
130
|
-
* a value
|
|
237
|
+
* a value starts: at the start of the line, after a key's `: `, a list's `- `, or a `[` or `,` in brackets, so the
|
|
238
|
+
* apostrophe in `grep: don't` is part of the value. One pass over the line, as a long one must not stall the scan.
|
|
131
239
|
*/
|
|
132
240
|
function withoutComment(line) {
|
|
133
241
|
let quote = null;
|
|
242
|
+
let valueStarts = true;
|
|
243
|
+
let started = false;
|
|
244
|
+
let brackets = 0;
|
|
134
245
|
for (let index = 0; index < line.length; index++) {
|
|
135
246
|
const char = line[index];
|
|
136
|
-
if (quote) {
|
|
137
|
-
if (char ===
|
|
247
|
+
if (quote === '"') {
|
|
248
|
+
if (char === '\\')
|
|
249
|
+
index++;
|
|
250
|
+
else if (char === '"')
|
|
138
251
|
quote = null;
|
|
252
|
+
continue;
|
|
139
253
|
}
|
|
140
|
-
|
|
141
|
-
|
|
254
|
+
if (quote === "'") {
|
|
255
|
+
if (char === "'" && line[index + 1] === "'")
|
|
256
|
+
index++;
|
|
257
|
+
else if (char === "'")
|
|
258
|
+
quote = null;
|
|
259
|
+
continue;
|
|
142
260
|
}
|
|
143
|
-
|
|
261
|
+
if (char === '#' && (index === 0 || /\s/.test(line[index - 1])))
|
|
144
262
|
return line.slice(0, index).trimEnd();
|
|
263
|
+
if (/\s/.test(char))
|
|
264
|
+
continue;
|
|
265
|
+
const endsToken = index + 1 === line.length || /\s/.test(line[index + 1]);
|
|
266
|
+
if ((char === '"' || char === "'") && valueStarts)
|
|
267
|
+
quote = char;
|
|
268
|
+
else if (char === '[' && valueStarts)
|
|
269
|
+
brackets++;
|
|
270
|
+
else if (char === ',' && brackets > 0) {
|
|
271
|
+
valueStarts = true;
|
|
272
|
+
continue;
|
|
273
|
+
}
|
|
274
|
+
else if (char === ':' && endsToken) {
|
|
275
|
+
valueStarts = true;
|
|
276
|
+
continue;
|
|
277
|
+
}
|
|
278
|
+
else if (char === '-' && endsToken && !started) {
|
|
279
|
+
started = true;
|
|
280
|
+
valueStarts = true;
|
|
281
|
+
continue;
|
|
145
282
|
}
|
|
283
|
+
started = true;
|
|
284
|
+
valueStarts = char === '[';
|
|
146
285
|
}
|
|
147
286
|
return line.trimEnd();
|
|
148
287
|
}
|
package/package.json
CHANGED
|
@@ -1,12 +1,18 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "test-inventory",
|
|
3
|
-
"version": "0.9.
|
|
4
|
-
"description": "Lists every Playwright, Vitest and
|
|
3
|
+
"version": "0.9.1",
|
|
4
|
+
"description": "Lists every Playwright, Vitest, Jest, Mocha, Jasmine, Cypress, WebdriverIO, node:test and Bun test from the source code, without running it: its state and why, tags, an id that survives a move, a hash of everything it runs, and the tests a change can affect.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"testing",
|
|
7
7
|
"playwright",
|
|
8
8
|
"vitest",
|
|
9
9
|
"jest",
|
|
10
|
+
"mocha",
|
|
11
|
+
"jasmine",
|
|
12
|
+
"cypress",
|
|
13
|
+
"webdriverio",
|
|
14
|
+
"bun",
|
|
15
|
+
"node-test",
|
|
10
16
|
"test-suite",
|
|
11
17
|
"test-inventory",
|
|
12
18
|
"static-analysis",
|