test-inventory 0.6.1 → 0.7.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/CHANGELOG.md +49 -0
- package/dist/case-titles.d.ts +14 -0
- package/dist/case-titles.js +227 -0
- package/dist/cli.d.ts +1 -1
- package/dist/cli.js +3 -0
- package/dist/diagnostics.js +1 -0
- package/dist/extract.d.ts +19 -1
- package/dist/extract.js +345 -29
- package/dist/filter.js +1 -0
- package/dist/framework-version.d.ts +4 -2
- package/dist/framework-version.js +17 -3
- package/dist/frameworks/common.d.ts +6 -0
- package/dist/frameworks/common.js +20 -0
- package/dist/frameworks/playwright.d.ts +3 -1
- package/dist/frameworks/playwright.js +14 -5
- package/dist/frameworks/vitest.d.ts +11 -1
- package/dist/frameworks/vitest.js +68 -11
- package/dist/imported-values.d.ts +22 -0
- package/dist/imported-values.js +135 -0
- package/dist/model.d.ts +8 -0
- package/dist/options.d.ts +11 -0
- package/dist/options.js +7 -0
- package/dist/records.js +11 -4
- package/dist/scan-file.d.ts +5 -0
- package/dist/scan-file.js +8 -5
- package/dist/scan-source.js +3 -1
- package/dist/scan.js +10 -4
- package/dist/types.d.ts +15 -3
- package/dist/values.d.ts +39 -1
- package/dist/values.js +425 -18
- package/package.json +1 -1
- package/schema/v1.json +28 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,54 @@
|
|
|
1
1
|
# test-inventory
|
|
2
2
|
|
|
3
|
+
## 0.7.0
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- [#72](https://github.com/Huldoser/test-inventory/pull/72) [`cf784f0`](https://github.com/Huldoser/test-inventory/commit/cf784f070e66523df1d68c546f033e1f495f0f49) - `--expand-cases` (library: `expandCases: true`) lists each case of a `.each` or `.for` table and each pass of a loop
|
|
8
|
+
whose values the scan can work out as its own record, with the title the runner gives it. Vitest's titles follow the
|
|
9
|
+
rules of the project's Vitest version, 3.0 to 5: `%s`, `%d`, `%i`, `%f`, `%j`, `%o`, `%O`, `%c`, `%#`, `%$` and `$name`,
|
|
10
|
+
with values quoted and cut as that version does; they match the names Vitest 3.0, 3.1, 3.2, 4.0, 4.1 and 5.0 list.
|
|
11
|
+
Each case's values are bound in its callback, so titles, tags and conditions built from them are worked out per case,
|
|
12
|
+
and an `if`, `?:`, `&&`, `||` or `??` that reads nothing but them registers only the branch it takes. Loops in test
|
|
13
|
+
and hook bodies and loops over a `var` are not expanded, and a file starts expansions up to 1,000 loop passes and
|
|
14
|
+
describe cases.
|
|
15
|
+
Suites and tests have a new key, `caseIndex`: the case's index from 0, as `%#` counts, or `null` without the option. A
|
|
16
|
+
table that can't be expanded stays one record with a new `cases-not-expanded` warning. Without the option the output
|
|
17
|
+
is as before, apart from `caseIndex: null` on every suite and test.
|
|
18
|
+
|
|
19
|
+
- [#72](https://github.com/Huldoser/test-inventory/pull/72) [`cf784f0`](https://github.com/Huldoser/test-inventory/commit/cf784f070e66523df1d68c546f033e1f495f0f49) - Values imported from other files of the project are now worked out: a title, tag, annotation, reason, run setting or
|
|
20
|
+
`.each` table built from a constant, enum or default export of another module, through re-exports, `export *`,
|
|
21
|
+
`import * as` and JSON files, found the same way as helper functions (relative paths, tsconfig `paths`, `#imports`,
|
|
22
|
+
workspace packages). Values from installed packages are still not read, and keep their diagnostic.
|
|
23
|
+
|
|
24
|
+
A test in a `for...of`, `for...in`, `forEach` or `map` loop over values the scan can work out now has `caseCount`, the
|
|
25
|
+
number of tests the runner registers, and no `test-in-loop` warning; the warning now marks a loop the scan can't
|
|
26
|
+
count. Values also work out arithmetic on numbers, as in `30 * 1000`, `?:`, `&&`, `||`, `??`, comparisons,
|
|
27
|
+
`Object.keys()`, `Object.values()`, `Object.entries()`, `JSON.stringify()`, `String()`, and a string's `toUpperCase()`,
|
|
28
|
+
`toLowerCase()` and `trim()` and an array's `join()`. A skip condition that works out to a constant, such as
|
|
29
|
+
`side === 'short'` in a helper called with `'buy'`, now sets the state it gives instead of being kept as a condition.
|
|
30
|
+
|
|
31
|
+
Code after an `if` whose branch always returns or throws, as in `if (!strategy.enabled) return;` in a helper, is now
|
|
32
|
+
under the opposite condition, so its tests have `isInCondition` and a loop around them no count. A tagged-template
|
|
33
|
+
table is counted as Vitest splits it: outer pipes are columns, an incomplete last row is left out, and a template
|
|
34
|
+
without values is one case.
|
|
35
|
+
|
|
36
|
+
A test whose title was its source text and is now worked out gets a new `id`, once.
|
|
37
|
+
|
|
38
|
+
### Patch Changes
|
|
39
|
+
|
|
40
|
+
- [#71](https://github.com/Huldoser/test-inventory/pull/71) [`bf8383f`](https://github.com/Huldoser/test-inventory/commit/bf8383f009a73a026d128cd8e050505cdd63cfb5) - A name destructured from a test object, as in `const { describe, beforeEach } = test`, is now read as that member:
|
|
41
|
+
`beforeEach(...)` is a hook, `describe(...)` a describe and `skip(...)` a skipped test, for Playwright and Vitest,
|
|
42
|
+
also nested, as in `const { describe: { serial } } = test`. Every such name was read as `test` itself, so a hook got
|
|
43
|
+
`test-without-body` and every test of the file `notLoaded`, and the tests inside a describe were left out with
|
|
44
|
+
`nested-test` warnings.
|
|
45
|
+
|
|
46
|
+
- [#71](https://github.com/Huldoser/test-inventory/pull/71) [`bf8383f`](https://github.com/Huldoser/test-inventory/commit/bf8383f009a73a026d128cd8e050505cdd63cfb5) - When the root and the folders above it don't have the framework, its version is now read from the shallowest
|
|
47
|
+
`package.json` below the root that declares it and holds scanned files, as `code/package.json` in a monorepo, with
|
|
48
|
+
that package's lockfile or installed copy first. The version was `null` there, so the newest rules applied: Vitest
|
|
49
|
+
5's, which refuse a file that calls `vi.mock` inside a block, made every test of such a file `notLoaded` in a project
|
|
50
|
+
on Vitest 3.
|
|
51
|
+
|
|
3
52
|
## 0.6.1
|
|
4
53
|
|
|
5
54
|
### Patch Changes
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import type { Value } from './values.ts';
|
|
2
|
+
/**
|
|
3
|
+
* The title Vitest gives one case of a `.each` or `.for` table, read from Vitest's `formatTitle` in 3.0, 3.1, 4.1
|
|
4
|
+
* and 5.0: `%#` and `%$` for the case's index, printf placeholders for its items, and `$name` for a key of its object.
|
|
5
|
+
* Vitest 3 formats the whole title and then replaces `$name`, also inside the values it put in; Vitest 4 and 5 format
|
|
6
|
+
* each placeholder on its own and replace `$name` only in the text between them. Vitest 3.0 has no `%$`, and reads
|
|
7
|
+
* `$name` only when the case is an object. Null when the title shows a value the scan doesn't format the way Vitest
|
|
8
|
+
* does, which is any array or object printed as a whole.
|
|
9
|
+
*
|
|
10
|
+
* `version` is Vitest's `[major, minor]`, null for the newest rules. `truncate` is the length Vitest shortens a value to,
|
|
11
|
+
* 40 unless the config sets `chaiConfig.truncateThreshold` (3 and 4) or `taskTitleValueFormatTruncate` (5); 0 keeps
|
|
12
|
+
* values whole.
|
|
13
|
+
*/
|
|
14
|
+
export declare function vitestCaseTitle(template: string, items: readonly Value[], index: number, version: readonly [number, number] | null, truncate?: number): string | null;
|
|
@@ -0,0 +1,227 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The title Vitest gives one case of a `.each` or `.for` table, read from Vitest's `formatTitle` in 3.0, 3.1, 4.1
|
|
3
|
+
* and 5.0: `%#` and `%$` for the case's index, printf placeholders for its items, and `$name` for a key of its object.
|
|
4
|
+
* Vitest 3 formats the whole title and then replaces `$name`, also inside the values it put in; Vitest 4 and 5 format
|
|
5
|
+
* each placeholder on its own and replace `$name` only in the text between them. Vitest 3.0 has no `%$`, and reads
|
|
6
|
+
* `$name` only when the case is an object. Null when the title shows a value the scan doesn't format the way Vitest
|
|
7
|
+
* does, which is any array or object printed as a whole.
|
|
8
|
+
*
|
|
9
|
+
* `version` is Vitest's `[major, minor]`, null for the newest rules. `truncate` is the length Vitest shortens a value to,
|
|
10
|
+
* 40 unless the config sets `chaiConfig.truncateThreshold` (3 and 4) or `taskTitleValueFormatTruncate` (5); 0 keeps
|
|
11
|
+
* values whole.
|
|
12
|
+
*/
|
|
13
|
+
export function vitestCaseTitle(template, items, index, version, truncate = 40) {
|
|
14
|
+
const rules = version === null || version[0] >= 5 ? 5 : version[0];
|
|
15
|
+
const isFirst3 = version !== null && version[0] === 3 && version[1] === 0;
|
|
16
|
+
let text = template;
|
|
17
|
+
if (text.includes('%#') || (!isFirst3 && text.includes('%$'))) {
|
|
18
|
+
text = text.replace(/%%/g, ESCAPED).replace(/%#/g, String(index));
|
|
19
|
+
if (!isFirst3)
|
|
20
|
+
text = text.replace(/%\$/g, String(index + 1));
|
|
21
|
+
text = text.replaceAll(ESCAPED, '%%');
|
|
22
|
+
}
|
|
23
|
+
const count = text.split('%').length - 1;
|
|
24
|
+
if (text.includes('%f'))
|
|
25
|
+
text = negativeFloats(text, items);
|
|
26
|
+
const isObjectItem = isObject(items[0]);
|
|
27
|
+
const attribute = (key) => {
|
|
28
|
+
const isArrayKey = !isFirst3 && /^\d+$/.test(key);
|
|
29
|
+
if (!isObjectItem && !isArrayKey)
|
|
30
|
+
return `$${key}`;
|
|
31
|
+
const element = isArrayKey ? objectAttr(items, key) : undefined;
|
|
32
|
+
const value = isObjectItem ? objectAttr(items[0], key, element) : element;
|
|
33
|
+
if (value === NOT_PLAIN)
|
|
34
|
+
return null;
|
|
35
|
+
if (rules === 5)
|
|
36
|
+
return typeof value === 'string' ? shorten(value, truncate) : prettyFormat(value, truncate);
|
|
37
|
+
return loupe(value, truncate === 0 ? Infinity : truncate);
|
|
38
|
+
};
|
|
39
|
+
if (rules === 3) {
|
|
40
|
+
const formatted = printf(text, items.slice(0, count), rules, truncate);
|
|
41
|
+
return formatted === null ? null : replaceAttributes(formatted, ATTRIBUTE_3, attribute);
|
|
42
|
+
}
|
|
43
|
+
let output = '';
|
|
44
|
+
let used = 0;
|
|
45
|
+
let last = 0;
|
|
46
|
+
for (const match of text.matchAll(PLACEHOLDER)) {
|
|
47
|
+
const between = replaceAttributes(text.slice(last, match.index), rules === 5 ? ATTRIBUTE_5 : ATTRIBUTE_3, attribute);
|
|
48
|
+
if (between === null)
|
|
49
|
+
return null;
|
|
50
|
+
output += between;
|
|
51
|
+
// Each placeholder, `%%` included, takes the next item, also one past the end of the case.
|
|
52
|
+
const placeholder = printf(match[0], [items[used++]], rules, truncate);
|
|
53
|
+
if (placeholder === null)
|
|
54
|
+
return null;
|
|
55
|
+
output += placeholder;
|
|
56
|
+
last = match.index + match[0].length;
|
|
57
|
+
}
|
|
58
|
+
const rest = replaceAttributes(text.slice(last), rules === 5 ? ATTRIBUTE_5 : ATTRIBUTE_3, attribute);
|
|
59
|
+
return rest === null ? null : output + rest;
|
|
60
|
+
}
|
|
61
|
+
const ESCAPED = '__vitest_escaped_%__';
|
|
62
|
+
const PLACEHOLDER = /%[sdjifoOc%]/g;
|
|
63
|
+
const ATTRIBUTE_3 = /\$([$\w.]+)/g;
|
|
64
|
+
const ATTRIBUTE_5 = /\$([$\p{ID_Continue}.]+)/gu;
|
|
65
|
+
/** A key that leads to something other than a plain value, such as `toString`, which Vitest would show as a function. */
|
|
66
|
+
const NOT_PLAIN = Symbol('not plain');
|
|
67
|
+
function isPrimitive(value) {
|
|
68
|
+
return typeof value !== 'object' || value === null;
|
|
69
|
+
}
|
|
70
|
+
function isObject(value) {
|
|
71
|
+
return value !== null && typeof value === 'object' && !Array.isArray(value);
|
|
72
|
+
}
|
|
73
|
+
/** Vitest's `objectAttr`: a path such as `order.qty`, `legs[0].side` or `0`, read as `new Object(value)[key]` reads it. */
|
|
74
|
+
function objectAttr(source, path, fallback) {
|
|
75
|
+
let result = source;
|
|
76
|
+
for (const key of path.replace(/\[(\d+)\]/g, '.$1').split('.')) {
|
|
77
|
+
if (result === null || result === undefined)
|
|
78
|
+
return fallback;
|
|
79
|
+
const object = Object(result);
|
|
80
|
+
if (Object.hasOwn(object, key)) {
|
|
81
|
+
result = object[key];
|
|
82
|
+
}
|
|
83
|
+
else if (key in object) {
|
|
84
|
+
return NOT_PLAIN;
|
|
85
|
+
}
|
|
86
|
+
else {
|
|
87
|
+
return fallback;
|
|
88
|
+
}
|
|
89
|
+
if (result === undefined)
|
|
90
|
+
return fallback;
|
|
91
|
+
}
|
|
92
|
+
return result;
|
|
93
|
+
}
|
|
94
|
+
/** `%f` of `-0` shows a minus, which Vitest adds for the item at the same place among the items. */
|
|
95
|
+
function negativeFloats(template, items) {
|
|
96
|
+
let text = template;
|
|
97
|
+
template.match(/%f/g).forEach((_, index) => {
|
|
98
|
+
if (!Object.is(items[index], -0))
|
|
99
|
+
return;
|
|
100
|
+
let occurrence = 0;
|
|
101
|
+
text = text.replace(/%f/g, (match) => (++occurrence === index + 1 ? '-%f' : match));
|
|
102
|
+
});
|
|
103
|
+
return text;
|
|
104
|
+
}
|
|
105
|
+
function replaceAttributes(text, pattern, attribute) {
|
|
106
|
+
let output = '';
|
|
107
|
+
let last = 0;
|
|
108
|
+
for (const match of text.matchAll(pattern)) {
|
|
109
|
+
const value = attribute(match[1]);
|
|
110
|
+
if (value === null)
|
|
111
|
+
return null;
|
|
112
|
+
output += text.slice(last, match.index) + value;
|
|
113
|
+
last = match.index + match[0].length;
|
|
114
|
+
}
|
|
115
|
+
return output + text.slice(last);
|
|
116
|
+
}
|
|
117
|
+
/** Vitest's `format()` for a template and its arguments, for the values it shows the way the scan does. */
|
|
118
|
+
function printf(template, args, rules, truncate) {
|
|
119
|
+
let used = 0;
|
|
120
|
+
let output = '';
|
|
121
|
+
let last = 0;
|
|
122
|
+
for (const match of template.matchAll(PLACEHOLDER)) {
|
|
123
|
+
const placeholder = match[0];
|
|
124
|
+
const formatted = placeholder === '%%'
|
|
125
|
+
? '%'
|
|
126
|
+
: used >= args.length
|
|
127
|
+
? placeholder
|
|
128
|
+
: formatValue(placeholder, args[used++], rules, truncate);
|
|
129
|
+
if (formatted === null)
|
|
130
|
+
return null;
|
|
131
|
+
output += template.slice(last, match.index) + formatted;
|
|
132
|
+
last = match.index + placeholder.length;
|
|
133
|
+
}
|
|
134
|
+
output += template.slice(last);
|
|
135
|
+
// Arguments beyond the placeholders are appended, as `console.log` does.
|
|
136
|
+
for (const value of args.slice(used)) {
|
|
137
|
+
if (!isPrimitive(value))
|
|
138
|
+
return null;
|
|
139
|
+
output += ` ${String(value)}`;
|
|
140
|
+
}
|
|
141
|
+
return output;
|
|
142
|
+
}
|
|
143
|
+
function formatValue(placeholder, value, rules, truncate) {
|
|
144
|
+
switch (placeholder) {
|
|
145
|
+
case '%s':
|
|
146
|
+
if (!isPrimitive(value))
|
|
147
|
+
return null;
|
|
148
|
+
return Object.is(value, -0) ? '-0' : String(value);
|
|
149
|
+
case '%d':
|
|
150
|
+
return Number(value).toString();
|
|
151
|
+
case '%i':
|
|
152
|
+
return isPrimitive(value) ? Number.parseInt(String(value)).toString() : null;
|
|
153
|
+
case '%f':
|
|
154
|
+
return isPrimitive(value) ? Number.parseFloat(String(value)).toString() : null;
|
|
155
|
+
case '%j':
|
|
156
|
+
// JSON.stringify(undefined) gives undefined, which the title shows as text.
|
|
157
|
+
return value === undefined ? 'undefined' : JSON.stringify(value);
|
|
158
|
+
case '%c':
|
|
159
|
+
return '';
|
|
160
|
+
default:
|
|
161
|
+
// `%o` and `%O` inspect the value: with loupe in Vitest 3 and 4, with pretty-format and the truncate option in 5.
|
|
162
|
+
if (!isPrimitive(value))
|
|
163
|
+
return null;
|
|
164
|
+
return rules === 5 ? prettyFormat(value, truncate) : loupe(value, Infinity);
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
/** A string cut to `length` with an ellipsis, without splitting a surrogate pair; 0 keeps it whole. */
|
|
168
|
+
function shorten(text, length) {
|
|
169
|
+
if (length === 0 || text.length <= length)
|
|
170
|
+
return text;
|
|
171
|
+
let end = length - 1;
|
|
172
|
+
if (isHighSurrogate(text[end - 1]))
|
|
173
|
+
end -= 1;
|
|
174
|
+
return `${text.slice(0, end)}…`;
|
|
175
|
+
}
|
|
176
|
+
function isHighSurrogate(char) {
|
|
177
|
+
return char !== undefined && char >= '\ud800' && char <= '\udbff';
|
|
178
|
+
}
|
|
179
|
+
/** Vitest 5's `inspect()` of a value, through pretty-format with single quotes. */
|
|
180
|
+
function prettyFormat(value, truncate) {
|
|
181
|
+
if (!isPrimitive(value))
|
|
182
|
+
return null;
|
|
183
|
+
if (typeof value !== 'string')
|
|
184
|
+
return Object.is(value, -0) ? '-0' : String(value);
|
|
185
|
+
const quoted = `'${value}'`;
|
|
186
|
+
if (truncate === 0 || quoted.length <= truncate)
|
|
187
|
+
return quoted;
|
|
188
|
+
let end = truncate - 1;
|
|
189
|
+
if (end > 0 && isHighSurrogate(quoted[end - 1]))
|
|
190
|
+
end -= 1;
|
|
191
|
+
return `'${quoted.slice(1, end)}…'`;
|
|
192
|
+
}
|
|
193
|
+
const LOUPE_ESCAPED = new RegExp("['\\u0000-\\u001f\\u007f-\\u009f\\u00ad\\u0600-\\u0604\\u070f\\u17b4\\u17b5\\u200c-\\u200f\\u2028-\\u202f\\u2060-\\u206f\\ufeff\\ufff0-\\uffff]", 'g');
|
|
194
|
+
const LOUPE_ESCAPES = {
|
|
195
|
+
'\b': '\\b',
|
|
196
|
+
'\t': '\\t',
|
|
197
|
+
'\n': '\\n',
|
|
198
|
+
'\f': '\\f',
|
|
199
|
+
'\r': '\\r',
|
|
200
|
+
"'": "\\'",
|
|
201
|
+
};
|
|
202
|
+
/** loupe's `inspect()` of a value, as Vitest 3 and 4 show it, cut to `truncate`. */
|
|
203
|
+
function loupe(value, truncate) {
|
|
204
|
+
if (!isPrimitive(value))
|
|
205
|
+
return null;
|
|
206
|
+
if (typeof value === 'string') {
|
|
207
|
+
const escaped = value.replace(LOUPE_ESCAPED, (char) => LOUPE_ESCAPES[char] ?? `\\u${`0000${char.charCodeAt(0).toString(16)}`.slice(-4)}`);
|
|
208
|
+
return `'${loupeTruncate(escaped, truncate - 2)}'`;
|
|
209
|
+
}
|
|
210
|
+
if (typeof value !== 'number')
|
|
211
|
+
return String(value);
|
|
212
|
+
if (Number.isNaN(value) || !Number.isFinite(value))
|
|
213
|
+
return String(value);
|
|
214
|
+
if (value === 0)
|
|
215
|
+
return Object.is(value, -0) ? '-0' : '+0';
|
|
216
|
+
return loupeTruncate(String(value), truncate);
|
|
217
|
+
}
|
|
218
|
+
function loupeTruncate(text, length) {
|
|
219
|
+
if (length < 1 && text.length > 1)
|
|
220
|
+
return '…';
|
|
221
|
+
if (text.length <= length || text.length <= 1)
|
|
222
|
+
return text;
|
|
223
|
+
let end = length - 1;
|
|
224
|
+
if (end > 0 && isHighSurrogate(text[end - 1]))
|
|
225
|
+
end -= 1;
|
|
226
|
+
return `${text.slice(0, end)}…`;
|
|
227
|
+
}
|
package/dist/cli.d.ts
CHANGED
|
@@ -6,6 +6,6 @@ export interface Io {
|
|
|
6
6
|
/** Read for `--related -`. */
|
|
7
7
|
stdin?: Readable;
|
|
8
8
|
}
|
|
9
|
-
export declare const HELP = "Usage: test-inventory [glob...] --framework <playwright|vitest> [options]\n\nLists the tests in the matching files as JSON, read from the source code without running them. Without globs, the\ntest files are those the Playwright or Vitest configs in the root and the folders below it run.\n\nOptions:\n --framework <name> playwright or vitest (required)\n --root <dir> project root; paths in the output are relative to it (default: current directory)\n --ignore <glob> leave out matching files; can be repeated (node_modules is always left out)\n --framework-version <x.y.z> apply the rules of this framework version instead of the one in the project\n --comments <mode> comments above tests: all, non-active or none (default: non-active)\n --state <state> keep tests in this state, such as skip or fixme; can be repeated\n --tag <tag> keep tests with this tag, such as @smoke; can be repeated\n --grep <regex> keep tests whose full name matches, ignoring case\n --only keep tests that use .only, or are inside a describe that does\n --without-reason keep tests that don't run and give no reason\n --related <file> keep tests a change to this file can affect; can be repeated; - reads files, one per\n line, from standard input, as git diff --name-only writes them\n --fields <keys> write only these keys of each test, separated by commas; id is always kept\n --format <format> json or jsonl, one record per line (default: json)\n -o, --output <file> write to a file instead of standard output\n --pretty indent the JSON\n -h, --help show this help\n -v, --version show the version\n\nExit codes: 0 when the scan finishes, even with diagnostics; 2 for invalid arguments, an output that cannot be\nwritten, or a crash. 1 is reserved for a future release.\n\nExamples:\n test-inventory \"tests/**/*.spec.ts\" --framework playwright --output inventory.json\n test-inventory \"tests/**/*.spec.ts\" --framework playwright --state skip --fields fullName,reason\n";
|
|
9
|
+
export declare const HELP = "Usage: test-inventory [glob...] --framework <playwright|vitest> [options]\n\nLists the tests in the matching files as JSON, read from the source code without running them. Without globs, the\ntest files are those the Playwright or Vitest configs in the root and the folders below it run.\n\nOptions:\n --framework <name> playwright or vitest (required)\n --root <dir> project root; paths in the output are relative to it (default: current directory)\n --ignore <glob> leave out matching files; can be repeated (node_modules is always left out)\n --framework-version <x.y.z> apply the rules of this framework version instead of the one in the project\n --comments <mode> comments above tests: all, non-active or none (default: non-active)\n --expand-cases one record per case of a .each or .for table and per pass of a loop, with its title\n --state <state> keep tests in this state, such as skip or fixme; can be repeated\n --tag <tag> keep tests with this tag, such as @smoke; can be repeated\n --grep <regex> keep tests whose full name matches, ignoring case\n --only keep tests that use .only, or are inside a describe that does\n --without-reason keep tests that don't run and give no reason\n --related <file> keep tests a change to this file can affect; can be repeated; - reads files, one per\n line, from standard input, as git diff --name-only writes them\n --fields <keys> write only these keys of each test, separated by commas; id is always kept\n --format <format> json or jsonl, one record per line (default: json)\n -o, --output <file> write to a file instead of standard output\n --pretty indent the JSON\n -h, --help show this help\n -v, --version show the version\n\nExit codes: 0 when the scan finishes, even with diagnostics; 2 for invalid arguments, an output that cannot be\nwritten, or a crash. 1 is reserved for a future release.\n\nExamples:\n test-inventory \"tests/**/*.spec.ts\" --framework playwright --output inventory.json\n test-inventory \"tests/**/*.spec.ts\" --framework playwright --state skip --fields fullName,reason\n";
|
|
10
10
|
/** Runs the command line with the given arguments and streams. Resolves to the exit code. */
|
|
11
11
|
export declare function run(argv: string[], io: Io): Promise<number>;
|
package/dist/cli.js
CHANGED
|
@@ -19,6 +19,7 @@ Options:
|
|
|
19
19
|
--ignore <glob> leave out matching files; can be repeated (node_modules is always left out)
|
|
20
20
|
--framework-version <x.y.z> apply the rules of this framework version instead of the one in the project
|
|
21
21
|
--comments <mode> comments above tests: all, non-active or none (default: non-active)
|
|
22
|
+
--expand-cases one record per case of a .each or .for table and per pass of a loop, with its title
|
|
22
23
|
--state <state> keep tests in this state, such as skip or fixme; can be repeated
|
|
23
24
|
--tag <tag> keep tests with this tag, such as @smoke; can be repeated
|
|
24
25
|
--grep <regex> keep tests whose full name matches, ignoring case
|
|
@@ -114,6 +115,7 @@ export async function run(argv, io) {
|
|
|
114
115
|
ignore: { type: 'string', multiple: true },
|
|
115
116
|
'framework-version': { type: 'string' },
|
|
116
117
|
comments: { type: 'string' },
|
|
118
|
+
'expand-cases': { type: 'boolean' },
|
|
117
119
|
state: { type: 'string', multiple: true },
|
|
118
120
|
tag: { type: 'string', multiple: true },
|
|
119
121
|
grep: { type: 'string' },
|
|
@@ -180,6 +182,7 @@ export async function run(argv, io) {
|
|
|
180
182
|
ignore: values.ignore ?? [],
|
|
181
183
|
frameworkVersion: values['framework-version'],
|
|
182
184
|
comments: values.comments,
|
|
185
|
+
expandCases: values['expand-cases'],
|
|
183
186
|
});
|
|
184
187
|
const filtered = filterInventory(inventory, filter);
|
|
185
188
|
result = fields === undefined ? filtered : pickTestFields(filtered, fields);
|
package/dist/diagnostics.js
CHANGED
package/dist/extract.d.ts
CHANGED
|
@@ -48,6 +48,8 @@ export interface PendingSuite {
|
|
|
48
48
|
/** Declared under a condition, or in a function: it may not run while the file loads. */
|
|
49
49
|
isInCondition: boolean;
|
|
50
50
|
isInFunction: boolean;
|
|
51
|
+
/** With `expandCases`, the index of the case of a table or pass of a loop this describe is; null otherwise. */
|
|
52
|
+
caseIndex: number | null;
|
|
51
53
|
}
|
|
52
54
|
export interface PendingTest {
|
|
53
55
|
scope: Scope;
|
|
@@ -66,8 +68,17 @@ export interface PendingTest {
|
|
|
66
68
|
states: StateSetting[];
|
|
67
69
|
annotations: Annotation[];
|
|
68
70
|
isInLoop: boolean;
|
|
71
|
+
/**
|
|
72
|
+
* How many times each loop around the test registers it, outermost first; null for a loop the scan can't count, or
|
|
73
|
+
* one that registers it under a condition.
|
|
74
|
+
*/
|
|
75
|
+
loops: (number | null)[];
|
|
76
|
+
/** How many passes each loop around the test makes, whether or not it registers the test on each. */
|
|
77
|
+
passes: (number | null)[];
|
|
69
78
|
isInCondition: boolean;
|
|
70
79
|
isInFunction: boolean;
|
|
80
|
+
/** With `expandCases`, the index of the case of a table or pass of a loop this test is; null otherwise. */
|
|
81
|
+
caseIndex: number | null;
|
|
71
82
|
comments: string[];
|
|
72
83
|
/** Run settings from calls in the body, which win over everything around the test. */
|
|
73
84
|
run: RunSettings;
|
|
@@ -85,6 +96,13 @@ export interface Frame {
|
|
|
85
96
|
readModule: ModuleReader | null;
|
|
86
97
|
relativeFilePath: string;
|
|
87
98
|
}
|
|
99
|
+
/** How the walk lists tables and loops. */
|
|
100
|
+
export interface ExtractOptions {
|
|
101
|
+
/** One test or describe per case of a table and per pass of a loop whose values the scan can work out. */
|
|
102
|
+
expandCases: boolean;
|
|
103
|
+
/** Vitest's `[major, minor]`, whose rules give each case its title; null for the newest rules. */
|
|
104
|
+
version: readonly [number, number] | null;
|
|
105
|
+
}
|
|
88
106
|
/** Reads a module a helper is imported from as a frame; null when it can't be parsed. */
|
|
89
107
|
export type OpenModule = (module: ModuleSource) => Frame | null;
|
|
90
108
|
export interface Extraction {
|
|
@@ -112,4 +130,4 @@ export declare function anySlow(slows: NonNullable<RunSettings['slow']>[]): NonN
|
|
|
112
130
|
export declare function eitherCondition(parts: string[]): string;
|
|
113
131
|
export declare function noHooks(): HookCounts;
|
|
114
132
|
/** Walks the scanned file; `openModule` reads the modules of imported helpers that the file calls. */
|
|
115
|
-
export declare function extract(main: Frame, openModule: OpenModule): Extraction;
|
|
133
|
+
export declare function extract(main: Frame, openModule: OpenModule, options?: ExtractOptions): Extraction;
|