test-inventory 0.10.2 → 0.10.3

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 CHANGED
@@ -1,5 +1,15 @@
1
1
  # test-inventory
2
2
 
3
+ ## 0.10.3
4
+
5
+ ### Patch Changes
6
+
7
+ - [#115](https://github.com/Huldoser/test-inventory/pull/115) [`2da89f8`](https://github.com/Huldoser/test-inventory/commit/2da89f84890e2c2ce8a87954263e6ae3f27ce5bc) - Read hooks and suite members on named node:test imports and preserve parameterized declarations chosen between Jest each factories. Avoid false Playwright file-load failures for unknown loop counts, false tests from unresolved destructured wrappers, and async-describe errors caused by awaits inside nested helper declarations. Report Vitest table factories called without their required receiver as file-load failures.
8
+
9
+ - [#115](https://github.com/Huldoser/test-inventory/pull/115) [`2da89f8`](https://github.com/Huldoser/test-inventory/commit/2da89f84890e2c2ce8a87954263e6ae3f27ce5bc) - Keep declarations when a file or imported helper calls a local function named require without arguments. The value reader no longer turns that call into an internal-error that discards the file's tests. Preserve suite, test and hook roles when members are destructured from an already-bound node:test module.
10
+
11
+ - [#115](https://github.com/Huldoser/test-inventory/pull/115) [`2da89f8`](https://github.com/Huldoser/test-inventory/commit/2da89f84890e2c2ce8a87954263e6ae3f27ce5bc) - Recognize defineConfig on Playwright's original package export, including default and CommonJS imports, instead of reporting an invalid-chain error that marks the file's tests notLoaded. Keep extended test functions distinct from the package export.
12
+
3
13
  ## 0.10.2
4
14
 
5
15
  ### Patch Changes
@@ -34,6 +34,7 @@ const NODE = {
34
34
  defaultImport: null,
35
35
  required: null,
36
36
  callable: TEST,
37
+ moduleMembers: new Set(['test', 'it']),
37
38
  // Every other export of node:test on Node.js 26; the hooks are read as hooks.
38
39
  others: new Set([
39
40
  'after',
@@ -54,6 +54,8 @@ function isPlaywrightSource(source) {
54
54
  /** The names a file binds to Playwright's `test`, its namespace and `mergeTests`. */
55
55
  class PlaywrightBindings {
56
56
  testNames = new Set();
57
+ /** The package's original test function also carries exports such as defineConfig; extended tests do not. */
58
+ moduleTests = new Set();
57
59
  namespaces = new Set();
58
60
  mergeTestsNames = new Set();
59
61
  /** The import specifiers and declarators that bind those names, to tell them from local names that shadow them. */
@@ -84,9 +86,11 @@ class PlaywrightBindings {
84
86
  }
85
87
  else if (specifier.type === 'ImportDefaultSpecifier') {
86
88
  this.testNames.add(specifier.local.name);
89
+ this.moduleTests.add(specifier.local.name);
87
90
  }
88
91
  else if (exportName(specifier.imported) === 'test') {
89
92
  this.testNames.add(specifier.local.name);
93
+ this.moduleTests.add(specifier.local.name);
90
94
  }
91
95
  else if (exportName(specifier.imported) === 'mergeTests') {
92
96
  this.mergeTestsNames.add(specifier.local.name);
@@ -187,6 +191,9 @@ class PlaywrightBindings {
187
191
  }
188
192
  if (this.isTestObject(init, false)) {
189
193
  this.testNames.add(id.name);
194
+ const node = unwrap(init);
195
+ if (node.type === 'Identifier' && this.moduleTests.has(node.name))
196
+ this.moduleTests.add(id.name);
190
197
  return true;
191
198
  }
192
199
  return false;
@@ -197,8 +204,10 @@ class PlaywrightBindings {
197
204
  if (property.type === 'RestElement' || property.value.type !== 'Identifier')
198
205
  continue;
199
206
  const key = propertyKey(property);
200
- if (key === 'test')
207
+ if (key === 'test') {
201
208
  this.testNames.add(property.value.name);
209
+ this.moduleTests.add(property.value.name);
210
+ }
202
211
  if (key === 'mergeTests')
203
212
  this.mergeTestsNames.add(property.value.name);
204
213
  }
@@ -248,6 +257,12 @@ export class PlaywrightAdapter {
248
257
  return null;
249
258
  const names = links.map((link) => link.name);
250
259
  const key = names.join('.');
260
+ if (key === 'defineConfig' &&
261
+ chain &&
262
+ (this.bindings.isModule(chain.base) ||
263
+ (chain.base.type === 'Identifier' && this.bindings.moduleTests.has(chain.base.name)))) {
264
+ return { kind: 'other' };
265
+ }
251
266
  const addedIn = ADDED_IN.get(key);
252
267
  if (addedIn && !atLeast(this.file.version, ...addedIn)) {
253
268
  return this.invalid(call, names, `needs Playwright ${addedIn.join('.')} or newer`, context);
@@ -367,6 +382,8 @@ export class PlaywrightAdapter {
367
382
  assumeLocal(declaration, name, links, args) {
368
383
  if (declaration.type !== 'VariableDeclarator' || !mayHoldTestObject(declaration) || !isTestName(name))
369
384
  return false;
385
+ if (declaration.id.type !== 'Identifier')
386
+ return false;
370
387
  if (!this.looksLikeTest(links, args))
371
388
  return false;
372
389
  if (!this.assumed.has(declaration)) {
@@ -396,6 +413,14 @@ export class PlaywrightAdapter {
396
413
  const destructured = boundMembers(declarator.id, name);
397
414
  if (!destructured)
398
415
  return null;
416
+ const init = declarator.init ? unwrap(declarator.init) : null;
417
+ if (destructured.length > 0 && TEST_MEMBERS.has(destructured[0]) && init?.type === 'Identifier') {
418
+ const imported = this.imports.get(init.name);
419
+ if (imported?.node === this.file.values.declarationOf(init.name, lookup.scopes) &&
420
+ !this.follow(init.name, !lookup.inBody)) {
421
+ return null;
422
+ }
423
+ }
399
424
  let members = this.aliases.get(declarator);
400
425
  if (members === undefined) {
401
426
  // Set first, so a variable defined through itself ends the lookup.
@@ -817,7 +842,7 @@ function containsAwait(fn) {
817
842
  const visit = (node) => {
818
843
  if (node.type === 'AwaitExpression' || (node.type === 'ForOfStatement' && node.await))
819
844
  return true;
820
- if (node !== fn && isFunctionNode(node))
845
+ if (node !== fn && (node.type === 'FunctionDeclaration' || isFunctionNode(node)))
821
846
  return false;
822
847
  return childNodes(node).some(visit);
823
848
  };
@@ -45,6 +45,8 @@ export interface Dialect {
45
45
  aliases?: ReadonlySet<string>;
46
46
  /** What the module is when called, as `node:test`'s default export and `require()` are its `test`. */
47
47
  callable?: Start;
48
+ /** Named exports that are the callable module itself, as node:test's `test` and `it`. */
49
+ moduleMembers?: ReadonlySet<string>;
48
50
  /** The module's other members, which a chain on the callable module may start with and is then no test. */
49
51
  others?: ReadonlySet<string>;
50
52
  /** Whether the functions must be imported, as the runner sets no globals; `starts` are then exports only. */
@@ -161,6 +163,8 @@ export declare abstract class SuiteAdapter implements Adapter {
161
163
  * `each` and `skipIf`, return a test function only when called, so their calls are never read through a variable.
162
164
  */
163
165
  private alias;
166
+ /** Members taken from a bound module retain its exported kinds, rather than becoming test modifiers. */
167
+ private moduleAlias;
164
168
  private aliasOf;
165
169
  /**
166
170
  * The test functions a value may hold, and whether it may also hold something else, as `process.env.CI` may. A test
@@ -11,7 +11,20 @@ export function shared(a, b) {
11
11
  return other?.name === link.name && !link.args && !link.template && !other.args && !other.template;
12
12
  };
13
13
  const differs = a.links.findIndex((link, index) => !same(link, index));
14
- return { kind: a.kind, links: differs === -1 ? a.links : a.links.slice(0, differs) };
14
+ const common = differs === -1 ? a.links : a.links.slice(0, differs);
15
+ const table = a.links.at(-1);
16
+ const otherTable = b.links.at(-1);
17
+ if (table &&
18
+ (table.name === 'each' || table.name === 'for') &&
19
+ otherTable?.name === table.name &&
20
+ !table.args &&
21
+ !table.template &&
22
+ !otherTable.args &&
23
+ !otherTable.template &&
24
+ !common.includes(table)) {
25
+ return { kind: a.kind, links: [...common, table] };
26
+ }
27
+ return { kind: a.kind, links: common };
15
28
  }
16
29
  function links(names) {
17
30
  return names.map((name) => ({ name, args: null, template: null }));
@@ -189,6 +202,10 @@ export class SuiteBindings {
189
202
  return (node.type === 'Identifier' && this.namespaces.has(node.name)) || this.dialect.isModule(node);
190
203
  }
191
204
  bindMember(imported, local) {
205
+ if (this.dialect.moduleMembers?.has(imported)) {
206
+ this.bindModule(local);
207
+ return;
208
+ }
192
209
  const start = this.dialect.starts.get(imported);
193
210
  const hook = this.dialect.hooks.get(imported);
194
211
  if (start)
@@ -303,6 +320,18 @@ export class SuiteAdapter {
303
320
  if (base.type === 'CallExpression' && this.dialect.isModule(base))
304
321
  return this.member(chainLinks);
305
322
  if (base.type === 'CallExpression') {
323
+ const callee = unwrap(base.callee);
324
+ if (callee.type === 'ConditionalExpression' || callee.type === 'LogicalExpression') {
325
+ const chosen = this.aliasOf(callee, lookup);
326
+ const last = chosen?.links.at(-1);
327
+ if (!chosen || !last || last.args || last.template)
328
+ return null;
329
+ return {
330
+ kind: chosen.kind,
331
+ index: 0,
332
+ modifiers: [...chosen.links.slice(0, -1), { ...last, args: base.arguments }],
333
+ };
334
+ }
306
335
  const returned = this.returned(base, chainLinks, args, lookup);
307
336
  return returned && { kind: returned.kind, index: 0, modifiers: returned.links };
308
337
  }
@@ -326,6 +355,13 @@ export class SuiteAdapter {
326
355
  // A parameter's declaration is its function: `describe('market orders', (test) => { test(...) })`.
327
356
  if (this.suiteParameters.get(declaration) === base.name)
328
357
  return { kind: 'test', index: 0 };
358
+ const moduleAlias = declaration.type === 'VariableDeclarator' ? this.moduleAlias(declaration, base.name, lookup) : null;
359
+ if (moduleAlias) {
360
+ const member = this.member([...links(moduleAlias), ...chainLinks]);
361
+ return member && member.index >= moduleAlias.length
362
+ ? { ...member, index: member.index - moduleAlias.length }
363
+ : null;
364
+ }
329
365
  const followed = this.imports.get(base.name)?.node === declaration &&
330
366
  this.worthFollowing(base.name, chainLinks, args) &&
331
367
  this.follow(base.name, !inBody && mayDeclareTests(base.name, chainLinks));
@@ -389,6 +425,23 @@ export class SuiteAdapter {
389
425
  }
390
426
  return alias && { kind: alias.kind, links: [...alias.links, ...links(destructured)] };
391
427
  }
428
+ /** Members taken from a bound module retain its exported kinds, rather than becoming test modifiers. */
429
+ moduleAlias(declarator, name, lookup) {
430
+ if (!declarator.init)
431
+ return null;
432
+ const init = unwrap(declarator.init);
433
+ if (!this.bindings.isNamespace(init))
434
+ return null;
435
+ if (init.type === 'Identifier') {
436
+ const declaration = this.file.values.declarationOf(init.name, lookup.scopes);
437
+ if (declaration === null || !this.bindings.declarations.has(declaration))
438
+ return null;
439
+ }
440
+ let members = boundMembers(declarator.id, name);
441
+ while (members && this.dialect.moduleMembers?.has(members[0]))
442
+ members = members.slice(1);
443
+ return members;
444
+ }
392
445
  aliasOf(expression, lookup) {
393
446
  const functions = this.choices(expression, lookup)?.functions ?? [];
394
447
  if (functions.length === 0)
@@ -512,6 +565,12 @@ export class SuiteAdapter {
512
565
  if (callee.type !== 'Identifier')
513
566
  return null;
514
567
  const declaration = this.file.values.declarationOf(callee.name, context.scopes);
568
+ const members = declaration?.type === 'VariableDeclarator' ? this.moduleAlias(declaration, callee.name, context) : null;
569
+ if (members?.length === 1) {
570
+ const hook = this.dialect.hooks.get(members[0]);
571
+ if (hook)
572
+ return this.hook(call, hook, context);
573
+ }
515
574
  const hook = declaration === null
516
575
  ? this.dialect.hooks.get(callee.name)
517
576
  : this.bindings.declarations.has(declaration) && this.bindings.hooks.get(callee.name);
@@ -179,14 +179,31 @@ export class VitestAdapter extends SuiteAdapter {
179
179
  */
180
180
  unboundCall(call, context) {
181
181
  const callee = unwrap(call.callee);
182
- if (callee.type !== 'Identifier')
182
+ if (callee.type === 'CallExpression')
183
+ return this.unboundCall(callee, context);
184
+ if (callee.type === 'Identifier') {
185
+ const found = this.destructuredMember(callee.name, context);
186
+ if (found && readsItsFunction(found.kind, found.member, this.file.version)) {
187
+ const from = snippet(text(this.file, found.from));
188
+ const message = `${callee.name} is destructured from ${from}, so it loses the test object it reads, and Vitest fails the file.`;
189
+ return { kind: 'invalid', problem: problem('invalid-chain', call, message, callee.name) };
190
+ }
191
+ }
192
+ if (callee.type !== 'Identifier' &&
193
+ callee.type !== 'ConditionalExpression' &&
194
+ callee.type !== 'LogicalExpression' &&
195
+ callee.type !== 'SequenceExpression') {
196
+ return null;
197
+ }
198
+ const chosen = this.testFunction(callee, context.scopes, (name, scopes) => context.returnsOf(name, scopes));
199
+ const member = chosen?.links.at(-1);
200
+ if (!chosen || !member || member.args || member.template)
183
201
  return null;
184
- const found = this.destructuredMember(callee.name, context);
185
- if (!found || !readsItsFunction(found.kind, found.member, this.file.version))
202
+ if (!readsItsFunction(chosen.kind, member.name, this.file.version))
186
203
  return null;
187
- const from = snippet(text(this.file, found.from));
188
- const message = `${callee.name} is destructured from ${from}, so it loses the test object it reads, and Vitest fails the file.`;
189
- return { kind: 'invalid', problem: problem('invalid-chain', call, message, callee.name) };
204
+ const source = snippet(text(this.file, callee));
205
+ const message = `${source} is called without the test or describe function it reads as this, so Vitest fails the file.`;
206
+ return { kind: 'invalid', problem: problem('invalid-chain', call, message, source) };
190
207
  }
191
208
  chainCall(call, context) {
192
209
  const chain = readChain(call.callee);
package/dist/records.js CHANGED
@@ -650,7 +650,7 @@ class RecordBuilder {
650
650
  const titles = describes.flatMap((scope) => suiteOf(scope).declaration.title?.text ?? []).reverse();
651
651
  // In a loop, a title path that never changes is registered again on each pass.
652
652
  const repeated = playwright &&
653
- test.passes.some((passes) => passes === null || passes > 1) &&
653
+ test.passes.some((passes) => passes !== null && passes > 1) &&
654
654
  describes.every((scope) => !suiteOf(scope).declaration.title?.isDynamic);
655
655
  if (repeated) {
656
656
  const message = 'The test is declared in a loop with the same title on each pass, so Playwright fails to load the file and runs no tests at all.';
package/dist/values.js CHANGED
@@ -897,7 +897,7 @@ function localRequire(expression) {
897
897
  const node = unwrap(expression);
898
898
  if (node.type !== 'CallExpression' || node.callee.type !== 'Identifier' || node.callee.name !== 'require')
899
899
  return null;
900
- const [argument] = node.arguments;
901
- const isLocal = argument.type === 'Literal' && typeof argument.value === 'string' && /^\.\.?\//.test(argument.value);
900
+ const argument = node.arguments.at(0);
901
+ const isLocal = argument?.type === 'Literal' && typeof argument.value === 'string' && /^\.\.?\//.test(argument.value);
902
902
  return isLocal ? argument.value : null;
903
903
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "test-inventory",
3
- "version": "0.10.2",
3
+ "version": "0.10.3",
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",