test-inventory 0.10.0 → 0.10.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 +12 -0
- package/dist/config-runs.js +2 -0
- package/dist/config.d.ts +1 -1
- package/dist/config.js +38 -2
- package/dist/dependency-hash.js +4 -2
- package/dist/diff.js +4 -0
- package/dist/extract.js +25 -7
- package/dist/frameworks/jasmine.js +8 -7
- package/dist/frameworks/jest.js +6 -5
- package/dist/frameworks/playwright.d.ts +3 -1
- package/dist/frameworks/playwright.js +54 -14
- package/dist/records.js +8 -4
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,17 @@
|
|
|
1
1
|
# test-inventory
|
|
2
2
|
|
|
3
|
+
## 0.10.1
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- [#99](https://github.com/Huldoser/test-inventory/pull/99) [`df8968d`](https://github.com/Huldoser/test-inventory/commit/df8968dc0357353913b96fadd417a266ab290b2c) - Keep Playwright declaring modifiers when functions are stored in variables or selected inline. Read logical choices with the same rules as the other runners, and classify each nested branch once to avoid exponential traversal.
|
|
8
|
+
|
|
9
|
+
Match Vite's alias merge precedence and preserve object aliases when mixed with lists. Mark imports as unfollowed when an unreadable alias entry or find could match them.
|
|
10
|
+
|
|
11
|
+
Ignore annotation and step line numbers in inventory diffs, so moving unchanged tests to another line does not report metadata changes.
|
|
12
|
+
|
|
13
|
+
- [#100](https://github.com/Huldoser/test-inventory/pull/100) [`fa10d39`](https://github.com/Huldoser/test-inventory/commit/fa10d3970046e4e99b6f175ff5dcf0eee13ccfcd) - Read locally declared describe callbacks passed by name, preserving suite placement, inherited state, lexical values and expanded table arguments. Keep suite hashes, dependencies and nested parent links complete, including when a child is written before its calling parent. Apply the existing helper traversal limits and runner callback checks to these callbacks.
|
|
14
|
+
|
|
3
15
|
## 0.10.0
|
|
4
16
|
|
|
5
17
|
### Minor Changes
|
package/dist/config-runs.js
CHANGED
|
@@ -1967,6 +1967,8 @@ function viteAliases(setting) {
|
|
|
1967
1967
|
return [];
|
|
1968
1968
|
return setting.items.flatMap((item) => {
|
|
1969
1969
|
const find = settingAt(item, ['find']);
|
|
1970
|
+
if (find?.kind === 'unknown')
|
|
1971
|
+
return [{ find: /./, replacements: [], replacesName: false }];
|
|
1970
1972
|
const replacements = stringOf(settingAt(item, ['replacement']));
|
|
1971
1973
|
const name = find?.kind === 'value' && typeof find.value === 'string' ? find.value : null;
|
|
1972
1974
|
const pattern = find?.kind === 'regex' ? regExp(find.source, find.flags) : null;
|
package/dist/config.d.ts
CHANGED
|
@@ -50,7 +50,7 @@ export declare function settingAt(setting: Setting, keys: readonly string[]): Se
|
|
|
50
50
|
* Vite's `mergeConfig(base, over)`: objects merge key by key, lists are joined with a single setting taken as a list
|
|
51
51
|
* of one, and `null` or `undefined` keeps the other side.
|
|
52
52
|
*/
|
|
53
|
-
export declare function mergeDeep(base: Setting, over: Setting): Setting;
|
|
53
|
+
export declare function mergeDeep(base: Setting, over: Setting, rootPath?: string): Setting;
|
|
54
54
|
/** The config a scanned file uses, read once however many files use it. */
|
|
55
55
|
export interface ConfigFile {
|
|
56
56
|
/** The config's absolute path. */
|
package/dist/config.js
CHANGED
|
@@ -232,7 +232,7 @@ function either(a, b, at) {
|
|
|
232
232
|
* Vite's `mergeConfig(base, over)`: objects merge key by key, lists are joined with a single setting taken as a list
|
|
233
233
|
* of one, and `null` or `undefined` keeps the other side.
|
|
234
234
|
*/
|
|
235
|
-
export function mergeDeep(base, over) {
|
|
235
|
+
export function mergeDeep(base, over, rootPath = '') {
|
|
236
236
|
if (isNullish(over))
|
|
237
237
|
return base;
|
|
238
238
|
if (isNullish(base) || over.kind === 'unknown')
|
|
@@ -249,10 +249,46 @@ export function mergeDeep(base, over) {
|
|
|
249
249
|
const keys = new Map(base.kind === 'object' && !over.rest ? base.keys : []);
|
|
250
250
|
for (const [key, value] of over.keys) {
|
|
251
251
|
const existing = child(base, key);
|
|
252
|
-
keys.set(key, existing
|
|
252
|
+
keys.set(key, existing
|
|
253
|
+
? key === 'alias' && (rootPath === '' || rootPath === 'resolve')
|
|
254
|
+
? mergeAliases(existing, value)
|
|
255
|
+
: mergeDeep(existing, value, rootPath ? `${rootPath}.${key}` : key)
|
|
256
|
+
: value);
|
|
253
257
|
}
|
|
254
258
|
return { kind: 'object', keys, rest: over.rest ?? (base.kind === 'object' ? base.rest : base) };
|
|
255
259
|
}
|
|
260
|
+
/** Vite puts overriding list aliases first and normalizes object aliases when either side is a list. */
|
|
261
|
+
function mergeAliases(base, over) {
|
|
262
|
+
if (isNullish(over))
|
|
263
|
+
return base;
|
|
264
|
+
if (isNullish(base))
|
|
265
|
+
return over;
|
|
266
|
+
if (base.kind === 'object' && over.kind === 'object') {
|
|
267
|
+
return {
|
|
268
|
+
kind: 'object',
|
|
269
|
+
keys: new Map([...(over.rest ? [] : base.keys), ...over.keys]),
|
|
270
|
+
rest: over.rest ?? base.rest,
|
|
271
|
+
};
|
|
272
|
+
}
|
|
273
|
+
const entries = (setting) => {
|
|
274
|
+
if (setting.kind === 'list')
|
|
275
|
+
return setting.items;
|
|
276
|
+
if (setting.kind !== 'object')
|
|
277
|
+
return [setting];
|
|
278
|
+
return [
|
|
279
|
+
...[...setting.keys].map(([find, replacement]) => ({
|
|
280
|
+
kind: 'object',
|
|
281
|
+
keys: new Map([
|
|
282
|
+
['find', { kind: 'value', value: find }],
|
|
283
|
+
['replacement', replacement],
|
|
284
|
+
]),
|
|
285
|
+
rest: null,
|
|
286
|
+
})),
|
|
287
|
+
...(setting.rest ? [setting.rest] : []),
|
|
288
|
+
];
|
|
289
|
+
};
|
|
290
|
+
return { kind: 'list', items: [...entries(over), ...entries(base)] };
|
|
291
|
+
}
|
|
256
292
|
/** Works out a config's settings from its code, following the modules it imports them from. */
|
|
257
293
|
class ConfigCode {
|
|
258
294
|
/** The modules read for the config besides itself, in the order they were first followed. */
|
package/dist/dependency-hash.js
CHANGED
|
@@ -1491,11 +1491,13 @@ export function fileDependencies(graph, main, extraction, types, report, runsWit
|
|
|
1491
1491
|
let units = suiteUnits.get(suite);
|
|
1492
1492
|
if (!units) {
|
|
1493
1493
|
// A describe without a callback has no tests in it.
|
|
1494
|
-
const fn = suite.declaration.fn;
|
|
1494
|
+
const fn = (suite.declaration.fn ?? suite.declaration.hashed);
|
|
1495
|
+
// Its load code is listed separately; following a named reference would pull in sibling test bodies too.
|
|
1496
|
+
const callback = suite.declaration.fn ? [] : suite.call.arguments.slice(-1);
|
|
1495
1497
|
units = [
|
|
1496
1498
|
graph.unit(moduleOf(suite.frame), [suite.call, ...bodyNodes(fn).filter(isLoadCode)],
|
|
1497
1499
|
// Offsets in another file could match these by chance.
|
|
1498
|
-
[fn, ...suite.cuts, ...(suite.frame === main ? registered : [])], types),
|
|
1500
|
+
[fn, ...callback, ...suite.cuts, ...(suite.frame === main ? registered : [])], types),
|
|
1499
1501
|
...registering(suite.registeredBy),
|
|
1500
1502
|
];
|
|
1501
1503
|
suiteUnits.set(suite, units);
|
package/dist/diff.js
CHANGED
|
@@ -76,6 +76,10 @@ function changed(before, after, hashesComparable) {
|
|
|
76
76
|
return false;
|
|
77
77
|
if (key === 'tags')
|
|
78
78
|
return stable([...before.tags].sort()) !== stable([...after.tags].sort());
|
|
79
|
+
if (key === 'annotations' || key === 'steps') {
|
|
80
|
+
const content = (test) => test[key].map((item) => Object.fromEntries(Object.entries(item).filter(([name]) => name !== 'lineStart')));
|
|
81
|
+
return stable(content(before)) !== stable(content(after));
|
|
82
|
+
}
|
|
79
83
|
return stable(before[key]) !== stable(after[key]);
|
|
80
84
|
})
|
|
81
85
|
.sort();
|
package/dist/extract.js
CHANGED
|
@@ -1300,10 +1300,7 @@ class Walker {
|
|
|
1300
1300
|
this.declaredIn.set(test, context.declaredIn);
|
|
1301
1301
|
this.cut(context.scope, call);
|
|
1302
1302
|
// A function declared in the file and passed by name runs as the test body too.
|
|
1303
|
-
|
|
1304
|
-
if (body) {
|
|
1305
|
-
if (!declaration.fn)
|
|
1306
|
-
this.walkedAtCall.add(body);
|
|
1303
|
+
this.withDeclarationBody(declaration, call, (body) => {
|
|
1307
1304
|
this.withCase(body, args, () => {
|
|
1308
1305
|
this.visitCallback(body, {
|
|
1309
1306
|
...context,
|
|
@@ -1316,7 +1313,29 @@ class Walker {
|
|
|
1316
1313
|
helper: null,
|
|
1317
1314
|
});
|
|
1318
1315
|
});
|
|
1316
|
+
});
|
|
1317
|
+
}
|
|
1318
|
+
/** Named callbacks keep their lexical scopes and use the same traversal bounds as directly called helpers. */
|
|
1319
|
+
withDeclarationBody(declaration, call, walk) {
|
|
1320
|
+
const fn = declaration.fn ?? declaration.hashed;
|
|
1321
|
+
if (!fn)
|
|
1322
|
+
return;
|
|
1323
|
+
if (declaration.fn) {
|
|
1324
|
+
walk(fn);
|
|
1325
|
+
return;
|
|
1326
|
+
}
|
|
1327
|
+
this.walkedAtCall.add(fn);
|
|
1328
|
+
if (this.callStack.includes(fn) || this.callStack.length >= MAX_DEPTH) {
|
|
1329
|
+
this.report(problem('test-in-function', call, 'The named callback recurses or exceeds the helper depth limit, so its nested tests are not followed here.'));
|
|
1330
|
+
return;
|
|
1319
1331
|
}
|
|
1332
|
+
if (!this.withinLimit({ fn, frame: this.frame }, call))
|
|
1333
|
+
return;
|
|
1334
|
+
const saved = this.scopes.splice(0, this.scopes.length, ...this.scopeChain(fn));
|
|
1335
|
+
this.callStack.push(fn);
|
|
1336
|
+
walk(fn);
|
|
1337
|
+
this.callStack.pop();
|
|
1338
|
+
this.scopes.splice(0, this.scopes.length, ...saved);
|
|
1320
1339
|
}
|
|
1321
1340
|
/** Runs `walk` with a case's arguments bound to the parameters of its callback, as the runner calls it. */
|
|
1322
1341
|
withCase(fn, args, walk) {
|
|
@@ -1366,8 +1385,7 @@ class Walker {
|
|
|
1366
1385
|
this.suites.push(suite);
|
|
1367
1386
|
this.cut(context.scope, call);
|
|
1368
1387
|
this.suiteFrames.set(suite, this.frame);
|
|
1369
|
-
|
|
1370
|
-
if (fn) {
|
|
1388
|
+
this.withDeclarationBody(declaration, call, (fn) => {
|
|
1371
1389
|
this.withCase(fn, args, () => {
|
|
1372
1390
|
this.visitCallback(fn, {
|
|
1373
1391
|
...context,
|
|
@@ -1385,7 +1403,7 @@ class Walker {
|
|
|
1385
1403
|
expandedAt: this.expandedAt(context, index === null ? null : call.start),
|
|
1386
1404
|
});
|
|
1387
1405
|
});
|
|
1388
|
-
}
|
|
1406
|
+
});
|
|
1389
1407
|
}
|
|
1390
1408
|
/** The statement a call forms, such as `test(...);`, or the call itself when it is part of a larger expression. */
|
|
1391
1409
|
statement(call) {
|
|
@@ -115,6 +115,7 @@ export class JasmineAdapter extends SuiteAdapter {
|
|
|
115
115
|
// `undefined` given as the function is no function, as when none is given.
|
|
116
116
|
const body = written?.type === 'Identifier' && written.name === 'undefined' ? undefined : written;
|
|
117
117
|
const fn = isFunctionNode(body) ? body : null;
|
|
118
|
+
const callback = fn ?? namedFunction(this.file, context.scopes, body ?? undefined);
|
|
118
119
|
const line = this.file.source.line(call.start);
|
|
119
120
|
// A spec without a function is pending, unless it is focused: `fit` needs one.
|
|
120
121
|
const isSkipped = flags.has('skip') || (kind === 'test' && body === undefined);
|
|
@@ -127,7 +128,7 @@ export class JasmineAdapter extends SuiteAdapter {
|
|
|
127
128
|
mode: null,
|
|
128
129
|
details: { tags: [], annotations: [], locks: [], meta: null, run: {} },
|
|
129
130
|
fn,
|
|
130
|
-
hashed:
|
|
131
|
+
hashed: callback,
|
|
131
132
|
isParameterized: false,
|
|
132
133
|
caseCount: null,
|
|
133
134
|
cases: null,
|
|
@@ -168,16 +169,16 @@ export class JasmineAdapter extends SuiteAdapter {
|
|
|
168
169
|
const refusal = this.refusal('test-without-body', call, `${callee}() has no function`, context);
|
|
169
170
|
return refused(call, refusal, context, () => declared);
|
|
170
171
|
}
|
|
171
|
-
if (
|
|
172
|
-
const refusal = this.refusal('async-describe',
|
|
172
|
+
if (callback?.async) {
|
|
173
|
+
const refusal = this.refusal('async-describe', callback, 'The describe callback is async, which Jasmine refuses', context);
|
|
173
174
|
return refused(call, refusal, context, () => declared);
|
|
174
175
|
}
|
|
175
|
-
if (
|
|
176
|
-
const refusal = this.refusal('describe-throws',
|
|
176
|
+
if (callback && declaresNothing(callback)) {
|
|
177
|
+
const refusal = this.refusal('describe-throws', callback, 'The describe declares no spec or describe, which Jasmine refuses', context);
|
|
177
178
|
return refused(call, refusal, context, () => declared);
|
|
178
179
|
}
|
|
179
|
-
if (
|
|
180
|
-
const refusal = this.refusal('describe-throws',
|
|
180
|
+
if (callback && functionLength(callback) > 0) {
|
|
181
|
+
const refusal = this.refusal('describe-throws', callback, 'The describe callback takes arguments, which Jasmine refuses', context);
|
|
181
182
|
return refused(call, refusal, context, () => declared);
|
|
182
183
|
}
|
|
183
184
|
return declared;
|
package/dist/frameworks/jest.js
CHANGED
|
@@ -156,6 +156,7 @@ export class JestAdapter extends SuiteAdapter {
|
|
|
156
156
|
const spread = args.some((arg) => arg.type === 'SpreadElement');
|
|
157
157
|
const body = spread ? undefined : args.at(1);
|
|
158
158
|
const fn = isFunctionNode(body) ? body : null;
|
|
159
|
+
const callback = fn ?? namedFunction(this.file, context.scopes, body);
|
|
159
160
|
const table = links.find((link) => link.name === 'each') ?? null;
|
|
160
161
|
const line = this.file.source.line(call.start);
|
|
161
162
|
const declared = (given = fn) => {
|
|
@@ -166,7 +167,7 @@ export class JestAdapter extends SuiteAdapter {
|
|
|
166
167
|
mode: flags.has('concurrent') && !flags.has('skip') ? 'parallel' : null,
|
|
167
168
|
details: { tags: [], annotations: [], locks: [], meta: null, run: {} },
|
|
168
169
|
fn: given,
|
|
169
|
-
hashed: given ??
|
|
170
|
+
hashed: given ?? callback,
|
|
170
171
|
isParameterized: table !== null,
|
|
171
172
|
caseCount: table ? this.caseCount(table, context, problems) : null,
|
|
172
173
|
cases: table ? this.tableCases(table, title, context) : null,
|
|
@@ -211,12 +212,12 @@ export class JestAdapter extends SuiteAdapter {
|
|
|
211
212
|
const refusal = problem('describe-throws', call, `${head}() has an empty table or one that isn't a table, so its describe throws, and Jest fails the file.`, head);
|
|
212
213
|
return refused(call, refusal, context, declared);
|
|
213
214
|
}
|
|
214
|
-
if (kind === 'describe' &&
|
|
215
|
-
const refusal = problem('async-describe',
|
|
215
|
+
if (kind === 'describe' && callback?.async) {
|
|
216
|
+
const refusal = problem('async-describe', callback, 'The describe callback is async, and Jest throws when a describe returns a promise, so it fails the file.');
|
|
216
217
|
return refused(call, refusal, context, declared);
|
|
217
218
|
}
|
|
218
|
-
if (kind === 'describe' &&
|
|
219
|
-
const returned = describeReturns(
|
|
219
|
+
if (kind === 'describe' && callback) {
|
|
220
|
+
const returned = describeReturns(callback);
|
|
220
221
|
if (returned) {
|
|
221
222
|
const refusal = problem(returned === 'promise' ? 'async-describe' : 'describe-throws', call, returned === 'promise'
|
|
222
223
|
? 'The describe callback returns a promise, and Jest throws when a describe returns one, so it fails the file.'
|
|
@@ -47,8 +47,10 @@ export declare class PlaywrightAdapter implements Adapter {
|
|
|
47
47
|
* destructured one works as it does on the object; a test object built with a destructured `extend` is not followed.
|
|
48
48
|
*/
|
|
49
49
|
private alias;
|
|
50
|
-
/** The members of `test` a value holds: none for a test object, or those of a
|
|
50
|
+
/** The members of `test` a value holds: none for a test object, or those of a declaring function. */
|
|
51
51
|
private members;
|
|
52
|
+
/** Function-valued branches stay distinct until a logical fallback rules out non-functions. */
|
|
53
|
+
private choices;
|
|
52
54
|
/** Follows the import of `name` once, and reports it once when it can't be followed and `report` is set. */
|
|
53
55
|
private follow;
|
|
54
56
|
/** Whether an argument is, or works out to, a string, as a title is. Spread arguments are handled before. */
|
|
@@ -22,6 +22,7 @@ const STATES = new Map([
|
|
|
22
22
|
['fail', 'expectedToFail'],
|
|
23
23
|
['fail.only', 'expectedToFail'],
|
|
24
24
|
]);
|
|
25
|
+
const TEST_DECLARATIONS = new Set(['', 'only', ...STATES.keys()]);
|
|
25
26
|
/** Members of `test` that are known but don't declare or modify tests. */
|
|
26
27
|
const OTHER_MEMBERS = new Set(['use', 'slow', 'setTimeout', 'extend']);
|
|
27
28
|
/** Members that set how the tests run where they are called. */
|
|
@@ -118,9 +119,20 @@ class PlaywrightBindings {
|
|
|
118
119
|
(followsCalls && this.holdsTestObject(node.name)));
|
|
119
120
|
case 'MemberExpression':
|
|
120
121
|
return propertyName(node) === 'test' && this.isModule(node.object);
|
|
121
|
-
case 'ConditionalExpression':
|
|
122
|
-
|
|
123
|
-
|
|
122
|
+
case 'ConditionalExpression': {
|
|
123
|
+
const branches = [node.consequent, node.alternate].map((expression) => ({
|
|
124
|
+
expression,
|
|
125
|
+
isObject: this.isTestObject(expression, followsCalls),
|
|
126
|
+
}));
|
|
127
|
+
// Keep inference through unknown factories, but a known member such as describe or skip is not an object.
|
|
128
|
+
return (branches.some((branch) => branch.isObject) &&
|
|
129
|
+
branches.every(({ expression, isObject }) => {
|
|
130
|
+
if (isObject)
|
|
131
|
+
return true;
|
|
132
|
+
const chain = readChain(expression);
|
|
133
|
+
return !chain || chain.links.length === 0 || !this.isTestObject(chain.base, followsCalls);
|
|
134
|
+
}));
|
|
135
|
+
}
|
|
124
136
|
case 'CallExpression': {
|
|
125
137
|
const callee = unwrap(node.callee);
|
|
126
138
|
if (callee.type === 'MemberExpression' && propertyName(callee) === 'extend') {
|
|
@@ -250,7 +262,7 @@ export class PlaywrightAdapter {
|
|
|
250
262
|
if (links.some((link) => link.args ?? link.template)) {
|
|
251
263
|
return this.invalid(call, names, "is not part of Playwright's API", context);
|
|
252
264
|
}
|
|
253
|
-
if (key
|
|
265
|
+
if (TEST_DECLARATIONS.has(key)) {
|
|
254
266
|
return this.testCall(call, key, context);
|
|
255
267
|
}
|
|
256
268
|
const describe = DESCRIBES.get(key);
|
|
@@ -296,6 +308,10 @@ export class PlaywrightAdapter {
|
|
|
296
308
|
...members.map((name) => ({ name, args: null, template: null })),
|
|
297
309
|
...links,
|
|
298
310
|
];
|
|
311
|
+
if (base.type === 'ConditionalExpression' || base.type === 'LogicalExpression') {
|
|
312
|
+
const members = this.members(base, lookup);
|
|
313
|
+
return members && withMembers(members);
|
|
314
|
+
}
|
|
299
315
|
if (base.type === 'Identifier') {
|
|
300
316
|
// A local variable or parameter with the same name, such as `(test) => test.result()`, is not Playwright's.
|
|
301
317
|
const declaration = this.file.values.declarationOf(base.name, scopes);
|
|
@@ -389,20 +405,43 @@ export class PlaywrightAdapter {
|
|
|
389
405
|
}
|
|
390
406
|
return members && [...members, ...destructured];
|
|
391
407
|
}
|
|
392
|
-
/** The members of `test` a value holds: none for a test object, or those of a
|
|
408
|
+
/** The members of `test` a value holds: none for a test object, or those of a declaring function. */
|
|
393
409
|
members(expression, lookup) {
|
|
410
|
+
const choices = this.choices(expression, lookup);
|
|
411
|
+
if (!choices || choices.mayBeOther || choices.members.length === 0)
|
|
412
|
+
return null;
|
|
413
|
+
return choices.members.slice(1).reduce(sharedMembers, choices.members[0]);
|
|
414
|
+
}
|
|
415
|
+
/** Function-valued branches stay distinct until a logical fallback rules out non-functions. */
|
|
416
|
+
choices(expression, lookup) {
|
|
394
417
|
const node = unwrap(expression);
|
|
395
418
|
if (node.type === 'ConditionalExpression') {
|
|
396
|
-
|
|
397
|
-
|
|
419
|
+
const [yes, no] = [this.choices(node.consequent, lookup), this.choices(node.alternate, lookup)];
|
|
420
|
+
if (!yes || !no)
|
|
421
|
+
return null;
|
|
422
|
+
return { members: [...yes.members, ...no.members], mayBeOther: yes.mayBeOther || no.mayBeOther };
|
|
423
|
+
}
|
|
424
|
+
if (node.type === 'LogicalExpression') {
|
|
425
|
+
const [left, right] = [this.choices(node.left, lookup), this.choices(node.right, lookup)];
|
|
426
|
+
const isFunction = left !== null && !left.mayBeOther;
|
|
427
|
+
if (node.operator === '&&')
|
|
428
|
+
return isFunction ? right : { members: right?.members ?? [], mayBeOther: true };
|
|
429
|
+
if (isFunction)
|
|
430
|
+
return left;
|
|
431
|
+
return {
|
|
432
|
+
members: [...(left?.members ?? []), ...(right?.members ?? [])],
|
|
433
|
+
mayBeOther: right?.mayBeOther ?? true,
|
|
434
|
+
};
|
|
398
435
|
}
|
|
399
436
|
if (this.bindings.isTestObject(node, false))
|
|
400
|
-
return [];
|
|
437
|
+
return { members: [[]], mayBeOther: false };
|
|
401
438
|
const chain = readChain(node);
|
|
402
439
|
if (!chain || chain.links.some((link) => link.args ?? link.template))
|
|
403
440
|
return null;
|
|
404
441
|
const members = this.testLinks(chain, [], lookup)?.map((link) => link.name);
|
|
405
|
-
return members && (members.
|
|
442
|
+
return members && (TEST_DECLARATIONS.has(members.join('.')) || DESCRIBES.has(members.join('.')))
|
|
443
|
+
? { members: [members], mayBeOther: false }
|
|
444
|
+
: null;
|
|
406
445
|
}
|
|
407
446
|
/** Follows the import of `name` once, and reports it once when it can't be followed and `report` is set. */
|
|
408
447
|
follow(name, report) {
|
|
@@ -610,7 +649,7 @@ export class PlaywrightAdapter {
|
|
|
610
649
|
const args = call.arguments;
|
|
611
650
|
if (args.length === 0)
|
|
612
651
|
return { kind: 'other' };
|
|
613
|
-
const anonymous = isFunctionNode(args[0]);
|
|
652
|
+
const anonymous = isFunctionNode(args[0]) || (args.length === 1 && namedFunction(this.file, context.scopes, args[0]) !== null);
|
|
614
653
|
const problems = [];
|
|
615
654
|
let title = null;
|
|
616
655
|
if (!anonymous) {
|
|
@@ -619,9 +658,10 @@ export class PlaywrightAdapter {
|
|
|
619
658
|
if (read.problem)
|
|
620
659
|
problems.push(read.problem);
|
|
621
660
|
}
|
|
622
|
-
const fn = anonymous ? args[0] : findFunction(args, 1);
|
|
623
|
-
|
|
624
|
-
|
|
661
|
+
const fn = anonymous ? (isFunctionNode(args[0]) ? args[0] : null) : findFunction(args, 1);
|
|
662
|
+
const callback = fn ?? namedFunction(this.file, context.scopes, args.at(-1));
|
|
663
|
+
if (callback?.async && containsAwait(callback)) {
|
|
664
|
+
problems.push(problem('async-describe', callback, 'The describe callback awaits, but Playwright does not wait for it; tests declared after the first await end up in the describe around it, or are not collected.'));
|
|
625
665
|
}
|
|
626
666
|
const line = this.file.source.line(call.start);
|
|
627
667
|
return {
|
|
@@ -634,7 +674,7 @@ export class PlaywrightAdapter {
|
|
|
634
674
|
passesDown: null,
|
|
635
675
|
details: this.details(!anonymous && args.length === 3 ? args[1] : undefined, context, problems, title?.text ?? ''),
|
|
636
676
|
fn,
|
|
637
|
-
hashed:
|
|
677
|
+
hashed: callback,
|
|
638
678
|
isParameterized: false,
|
|
639
679
|
caseCount: null,
|
|
640
680
|
cases: null,
|
package/dist/records.js
CHANGED
|
@@ -252,6 +252,12 @@ class RecordBuilder {
|
|
|
252
252
|
...extraction.suites.filter((suite) => suite.declaration.isOnly).map((suite) => suite.scope.parent),
|
|
253
253
|
];
|
|
254
254
|
this.focusedBelow = new Set(focusedAt.flatMap((scope) => outward(scope)));
|
|
255
|
+
// A named callback can place a child before its calling parent in source order.
|
|
256
|
+
for (const { scope, declaration } of extraction.suites) {
|
|
257
|
+
const parents = outward(scope).slice(1, -1).reverse();
|
|
258
|
+
// Mark describe ids so that a describe and test with the same title in the same place differ.
|
|
259
|
+
this.suiteIds.set(scope, this.id(['describe', this.describeTitles(parents), declaration.title?.withoutTags ?? '']));
|
|
260
|
+
}
|
|
255
261
|
const suites = extraction.suites.map((suite) => this.suite(suite));
|
|
256
262
|
const tests = extraction.tests.map((test) => this.test(test, suites));
|
|
257
263
|
for (const item of problems) {
|
|
@@ -327,12 +333,10 @@ class RecordBuilder {
|
|
|
327
333
|
this.forbidOnly(pending.site ?? call, pending.site ? null : call);
|
|
328
334
|
const parents = outward(scope).slice(1, -1).reverse();
|
|
329
335
|
const title = declaration.title;
|
|
330
|
-
|
|
331
|
-
const id = this.id(['describe', this.describeTitles(parents), title?.withoutTags ?? '']);
|
|
332
|
-
this.suiteIds.set(scope, id);
|
|
336
|
+
const id = this.suiteIds.get(scope);
|
|
333
337
|
const chosen = chooseState(scope.states.map((setting) => ({ setting, source: 'suite' })));
|
|
334
338
|
const state = chosen?.setting.state;
|
|
335
|
-
const fn = declaration.fn;
|
|
339
|
+
const fn = declaration.fn ?? declaration.hashed;
|
|
336
340
|
return {
|
|
337
341
|
id,
|
|
338
342
|
parentId: parents.length > 0 ? this.suiteIds.get(parents[parents.length - 1]) : null,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "test-inventory",
|
|
3
|
-
"version": "0.10.
|
|
3
|
+
"version": "0.10.1",
|
|
4
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",
|