test-inventory 0.10.4 → 0.11.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.
Files changed (50) hide show
  1. package/CHANGELOG.md +116 -0
  2. package/README.md +6 -4
  3. package/dist/cli.d.ts +7 -4
  4. package/dist/cli.js +18 -6
  5. package/dist/config-runs.d.ts +30 -4
  6. package/dist/config-runs.js +193 -38
  7. package/dist/config.d.ts +7 -6
  8. package/dist/config.js +260 -26
  9. package/dist/dependency-hash.d.ts +9 -1
  10. package/dist/dependency-hash.js +128 -13
  11. package/dist/diff.js +7 -2
  12. package/dist/extract.js +75 -17
  13. package/dist/files.js +2 -1
  14. package/dist/filter.js +1 -0
  15. package/dist/framework-version.d.ts +6 -0
  16. package/dist/framework-version.js +37 -9
  17. package/dist/frameworks/bindings.d.ts +9 -0
  18. package/dist/frameworks/bindings.js +28 -5
  19. package/dist/frameworks/bun.js +2 -2
  20. package/dist/frameworks/common.d.ts +12 -3
  21. package/dist/frameworks/common.js +30 -12
  22. package/dist/frameworks/jasmine.js +11 -3
  23. package/dist/frameworks/jest.js +11 -7
  24. package/dist/frameworks/mocha.js +3 -3
  25. package/dist/frameworks/node.js +6 -4
  26. package/dist/frameworks/playwright.d.ts +11 -3
  27. package/dist/frameworks/playwright.js +101 -32
  28. package/dist/frameworks/test-functions.d.ts +13 -7
  29. package/dist/frameworks/test-functions.js +41 -27
  30. package/dist/frameworks/vitest.js +11 -6
  31. package/dist/imported-values.js +12 -3
  32. package/dist/index.d.ts +2 -0
  33. package/dist/index.js +1 -0
  34. package/dist/model.d.ts +4 -1
  35. package/dist/node-scripts.d.ts +15 -1
  36. package/dist/node-scripts.js +140 -13
  37. package/dist/parse.d.ts +3 -0
  38. package/dist/parse.js +33 -0
  39. package/dist/records.js +7 -4
  40. package/dist/resolve.d.ts +3 -1
  41. package/dist/resolve.js +48 -15
  42. package/dist/run-commands.d.ts +20 -0
  43. package/dist/run-commands.js +107 -0
  44. package/dist/scan.js +15 -5
  45. package/dist/types.d.ts +9 -1
  46. package/dist/values.d.ts +25 -4
  47. package/dist/values.js +131 -22
  48. package/package.json +15 -7
  49. package/schema/diff-v1.json +12 -1
  50. package/schema/v1.json +9 -1
package/dist/values.js CHANGED
@@ -20,6 +20,7 @@ export function isScopeNode(node) {
20
20
  case 'ForInStatement':
21
21
  case 'ForOfStatement':
22
22
  case 'CatchClause':
23
+ case 'SwitchStatement':
23
24
  return true;
24
25
  default:
25
26
  return false;
@@ -68,13 +69,22 @@ export class Values {
68
69
  /**
69
70
  * Runs `read` with a function's parameters bound to the arguments of one call, worked out where the call is, so that
70
71
  * titles and values built from them resolve, as in `test(\`${side} rejects a zero quantity\`)` inside
71
- * `validatesQuantity('buy')`. `args` stop at a spread argument, after which no position is known. A missing argument
72
- * takes the parameter's default value, worked out in `scopes`, the scopes around the function.
72
+ * `validatesQuantity('buy')`. `args` stop at a spread argument, after which no position is known, and `complete` is
73
+ * false then. A missing argument takes the parameter's default value, worked out in `scopes`, the scopes around the
74
+ * function. A rest parameter, as `...cycles`, holds the arguments left.
73
75
  */
74
- withArguments(fn, args, scopes, read) {
76
+ withArguments(fn, args, scopes, read, complete = true) {
75
77
  const parameters = new Map();
76
78
  for (const [index, parameter] of fn.params.entries()) {
77
- this.bind(parameter, args.at(index), parameters, [...scopes, fn]);
79
+ if (parameter.type === 'RestElement') {
80
+ const rest = args.slice(index);
81
+ const unknown = complete ? rest.find((item) => !item.ok) : UNRESOLVED;
82
+ const value = unknown ?? { ok: true, value: rest.map((item) => item.value) };
83
+ this.bind(parameter.argument, value, parameters, [...scopes, fn]);
84
+ }
85
+ else {
86
+ this.bind(parameter, args.at(index), parameters, [...scopes, fn]);
87
+ }
78
88
  }
79
89
  // A parameter the function assigns to may hold another value by the time it is read.
80
90
  for (const name of this.assignedIn(fn.body))
@@ -280,6 +290,9 @@ export class Values {
280
290
  const namespace = this.namespaceMember(expression, scopes);
281
291
  if (namespace)
282
292
  return namespace;
293
+ const own = this.ownProperty(expression, scopes);
294
+ if (own)
295
+ return own;
283
296
  const object = this.resolve(expression.object, scopes);
284
297
  if (!object.ok)
285
298
  return object;
@@ -314,13 +327,17 @@ export class Values {
314
327
  * A parameter is not its function, though the function declares it.
315
328
  */
316
329
  functionOf(name, scopes) {
317
- const binding = this.lookup(name, scopes)?.binding;
318
- const declaration = binding?.declaration;
330
+ return this.functionWithScopes(name, scopes)?.fn ?? null;
331
+ }
332
+ /** `functionOf()`, with the scopes around the function's declaration, in which its body is read. */
333
+ functionWithScopes(name, scopes) {
334
+ const found = this.lookup(name, scopes);
335
+ const declaration = found?.binding.declaration;
319
336
  // A class is bound like a function, but has no body to walk.
320
- if (binding?.kind === 'function' && declaration?.type === 'FunctionDeclaration')
321
- return declaration;
337
+ const declared = found?.binding.kind === 'function' && declaration?.type === 'FunctionDeclaration';
322
338
  const init = declaration?.type === 'VariableDeclarator' && declaration.init ? unwrap(declaration.init) : null;
323
- return isFunctionNode(init) ? init : null;
339
+ const fn = declared ? declaration : isFunctionNode(init) ? init : null;
340
+ return fn && found ? { fn, scopes: found.scopes } : null;
324
341
  }
325
342
  /** The value a `const` name is declared with, and the scopes around that declaration; null for any other name. */
326
343
  constantOf(name, scopes) {
@@ -426,8 +443,14 @@ export class Values {
426
443
  if (object.type !== 'Identifier')
427
444
  return null;
428
445
  const binding = this.lookup(object.name, scopes)?.binding;
429
- if (binding?.kind !== 'import' || binding.imported !== null)
446
+ if (binding?.kind !== 'import')
447
+ return null;
448
+ // `const fees = require('./fees')` holds the module's exports, as `import * as fees` does.
449
+ const required = binding.imported === 'default' && binding.declaration.type === 'VariableDeclarator';
450
+ if (binding.imported !== null && !required)
430
451
  return null;
452
+ if (required && this.changedAtLoad(scopes[0]).has(object.name))
453
+ return { ok: false, importedFrom: binding.source };
431
454
  const key = expression.computed
432
455
  ? this.resolve(expression.property, scopes)
433
456
  : { ok: true, value: propertyName(expression) };
@@ -435,9 +458,44 @@ export class Values {
435
458
  return { ok: false, importedFrom: binding.source };
436
459
  return this.imported(binding.source, String(key.value));
437
460
  }
461
+ /**
462
+ * A property of an object written out in a constant the module keeps, worked out alone, as `TITLES.fill` in
463
+ * `const TITLES = { fill: 'fills a limit order', format: (venue) => venue }`, whatever its other values are. Null when
464
+ * a spread, a key the scan can't work out, or a getter or method of that name may hold it.
465
+ */
466
+ ownProperty(expression, scopes) {
467
+ const object = unwrap(expression.object);
468
+ if (object.type !== 'Identifier')
469
+ return null;
470
+ const binding = this.lookup(object.name, scopes)?.binding;
471
+ if (binding?.kind !== 'const' || this.changedAtLoad(binding.scopes[0]).has(object.name))
472
+ return null;
473
+ const init = unwrap(binding.init);
474
+ if (init.type !== 'ObjectExpression')
475
+ return null;
476
+ const key = expression.computed
477
+ ? this.resolve(expression.property, scopes)
478
+ : { ok: true, value: propertyName(expression) };
479
+ if (!key.ok || !isKey(key.value))
480
+ return null;
481
+ let found = null;
482
+ for (const property of init.properties) {
483
+ if (property.type === 'SpreadElement')
484
+ return null;
485
+ const name = this.propertyKey(property.key, property.computed, binding.scopes);
486
+ if (!name.ok || !isKey(name.value))
487
+ return null;
488
+ if (String(name.value) !== String(key.value))
489
+ continue;
490
+ if (property.kind !== 'init' || property.method)
491
+ return null;
492
+ found = property.value;
493
+ }
494
+ return found && this.resolve(found, binding.scopes);
495
+ }
438
496
  imported(source, name) {
439
497
  const resolved = name !== null && this.imports ? this.imports(source, name) : UNRESOLVED;
440
- return resolved.ok ? resolved : { ok: false, importedFrom: source };
498
+ return resolved.ok ? resolved : { ...resolved, importedFrom: source };
441
499
  }
442
500
  /**
443
501
  * How many items a list has when not all its values are known, as `[NaN, Infinity]`: a list written out, its spreads
@@ -445,17 +503,15 @@ export class Values {
445
503
  * null otherwise. `seen` stops at a constant defined through itself.
446
504
  */
447
505
  lengthOf(node, scopes, seen = new Set()) {
506
+ const expression = unwrap(node);
507
+ if (expression.type === 'Identifier')
508
+ return this.lengthOfName(expression.name, scopes, seen);
448
509
  const resolved = this.resolve(node, scopes);
449
510
  if (resolved.ok)
450
511
  return Array.isArray(resolved.value) ? resolved.value.length : null;
451
- const expression = unwrap(node);
452
- if (expression.type === 'Identifier') {
453
- const binding = this.lookup(expression.name, scopes)?.binding;
454
- if (binding?.kind !== 'const' || seen.has(expression.name))
455
- return null;
456
- if (this.changedAtLoad(binding.scopes[0]).has(expression.name))
457
- return null;
458
- return this.lengthOf(binding.init, binding.scopes, new Set([...seen, expression.name]));
512
+ if (expression.type === 'MemberExpression') {
513
+ const member = this.namespaceMember(expression, scopes);
514
+ return member?.ok === false ? (member.arrayLength ?? null) : null;
459
515
  }
460
516
  if (expression.type === 'CallExpression' && isObjectListing(expression)) {
461
517
  const target = expression.arguments[0];
@@ -472,6 +528,18 @@ export class Values {
472
528
  }
473
529
  return length;
474
530
  }
531
+ /** How many items a named array holds, including a project import whose values are unknown. */
532
+ lengthOfName(name, scopes, seen = new Set()) {
533
+ const resolved = this.resolveName(name, scopes);
534
+ if (resolved.ok)
535
+ return Array.isArray(resolved.value) ? resolved.value.length : null;
536
+ const binding = this.lookup(name, scopes)?.binding;
537
+ if (binding?.kind === 'import')
538
+ return resolved.arrayLength ?? null;
539
+ if (binding?.kind !== 'const' || seen.has(name) || this.changedAtLoad(binding.scopes[0]).has(name))
540
+ return null;
541
+ return this.lengthOf(binding.init, binding.scopes, new Set([...seen, name]));
542
+ }
475
543
  /** How many keys an object written out has, held in a constant the module doesn't change; null otherwise. */
476
544
  keyCount(node, scopes, seen) {
477
545
  const expression = unwrap(node);
@@ -565,11 +633,13 @@ export class Values {
565
633
  }
566
634
  return members;
567
635
  }
636
+ /** A name's binding, and the scopes from the outermost to the one that declares it. */
568
637
  lookup(name, scopes) {
569
638
  for (let index = scopes.length - 1; index >= 0; index--) {
570
- const binding = this.bindings(scopes[index], scopes.slice(0, index + 1)).get(name);
639
+ const declaredIn = scopes.slice(0, index + 1);
640
+ const binding = this.bindings(scopes[index], declaredIn).get(name);
571
641
  if (binding)
572
- return { binding };
642
+ return { binding, scopes: declaredIn };
573
643
  }
574
644
  return null;
575
645
  }
@@ -643,7 +713,7 @@ function rootName(node) {
643
713
  * Names assigned to or changed anywhere in `body`, its functions included: `x = ...`, `x++`, `[x] = ...`,
644
714
  * `for (x of ...)`, `x.push(...)`.
645
715
  */
646
- function assignedNames(body) {
716
+ export function assignedNames(body) {
647
717
  const names = new Set();
648
718
  const targets = (target) => {
649
719
  switch (target?.type) {
@@ -855,19 +925,38 @@ function collectBindings(scope, scopes) {
855
925
  break;
856
926
  }
857
927
  };
928
+ // A `var` in a nested block belongs to the whole function or module, as in `case 'x': var context = ...`.
929
+ const hoist = (body) => {
930
+ for (const declarator of nestedVars(body)) {
931
+ for (const name of bindingNames(declarator.id))
932
+ if (!bindings.has(name))
933
+ bindings.set(name, { kind: 'other', declaration: declarator });
934
+ }
935
+ };
858
936
  switch (scope.type) {
859
937
  case 'Program':
938
+ for (const statement of scope.body)
939
+ declare(statement);
940
+ hoist(scope);
941
+ break;
860
942
  case 'BlockStatement':
861
943
  case 'StaticBlock':
862
944
  case 'TSModuleBlock':
863
945
  for (const statement of scope.body)
864
946
  declare(statement);
865
947
  break;
948
+ case 'SwitchStatement':
949
+ for (const item of scope.cases)
950
+ for (const statement of item.consequent)
951
+ declare(statement);
952
+ break;
866
953
  case 'FunctionDeclaration':
867
954
  case 'FunctionExpression':
868
955
  case 'ArrowFunctionExpression':
869
956
  for (const parameter of scope.params)
870
957
  other(bindingNames(parameter), scope);
958
+ // Only a TypeScript overload has no body, and no walk goes into one.
959
+ hoist(scope.body);
871
960
  break;
872
961
  case 'ForStatement':
873
962
  declare(scope.init);
@@ -882,6 +971,26 @@ function collectBindings(scope, scopes) {
882
971
  }
883
972
  return bindings;
884
973
  }
974
+ /** The `var` declarators in the blocks below a scope, outside the functions, classes and namespaces in it. */
975
+ function nestedVars(scope) {
976
+ const found = [];
977
+ // Only statements hold declarations, so expressions, however deep, are not walked.
978
+ const visit = (node) => {
979
+ if (node.type === 'VariableDeclaration') {
980
+ if (node.kind === 'var')
981
+ found.push(...node.declarations);
982
+ return;
983
+ }
984
+ if (!/Statement$|^(SwitchCase|CatchClause|ExportNamedDeclaration)$/.test(node.type))
985
+ return;
986
+ for (const child of childNodes(node))
987
+ visit(child);
988
+ };
989
+ for (const child of childNodes(scope))
990
+ if (child.type !== 'VariableDeclaration')
991
+ visit(child);
992
+ return found;
993
+ }
885
994
  /** `Object.keys(x)`, `Object.values(x)` or `Object.entries(x)`, which list as many items as `x` has keys. */
886
995
  function isObjectListing(call) {
887
996
  const callee = unwrap(call.callee);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "test-inventory",
3
- "version": "0.10.4",
3
+ "version": "0.11.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",
@@ -87,7 +87,7 @@
87
87
  "changeset": "changeset"
88
88
  },
89
89
  "dependencies": {
90
- "oxc-parser": "0.157.0",
90
+ "oxc-parser": "0.159.0",
91
91
  "picomatch": "^4.0.7",
92
92
  "tinyglobby": "^0.2.17"
93
93
  },
@@ -97,19 +97,27 @@
97
97
  "@changesets/cli": "^3.0.3",
98
98
  "@types/node": "~22.12.0",
99
99
  "@types/picomatch": "^4.0.3",
100
- "@vitest/coverage-v8": "5.1.0",
100
+ "@vitest/coverage-v8": "5.1.1",
101
101
  "ajv": "^8.20.0",
102
- "eslint": "~10.14.0",
103
- "prettier": "3.9.10",
102
+ "eslint": "~10.15.0",
103
+ "prettier": "3.10.1",
104
104
  "publint": "^0.3.25",
105
105
  "ts-json-schema-generator": "2.9.0",
106
106
  "typedoc": "^0.28.20",
107
107
  "typedoc-plugin-markdown": "^4.14.1",
108
108
  "typedoc-vitepress-theme": "^1.1.4",
109
109
  "typescript": "~6.0.3",
110
- "typescript-eslint": "~8.72.1",
110
+ "typescript-eslint": "~8.73.0",
111
111
  "vitepress": "2.0.0-alpha.21",
112
112
  "vitepress-plugin-llms": "^1.14.0",
113
- "vitest": "5.1.0"
113
+ "vitest": "5.1.1"
114
+ },
115
+ "overrides": {
116
+ "ts-json-schema-generator": {
117
+ "glob": "^14.0.6"
118
+ },
119
+ "vitepress-plugin-llms": {
120
+ "minimatch": "^11.0.9"
121
+ }
114
122
  }
115
123
  }
@@ -201,6 +201,7 @@
201
201
  "dependencyHash",
202
202
  "dependencies",
203
203
  "hasUnfollowedDependencies",
204
+ "unfollowedDependencies",
204
205
  "suiteId",
205
206
  "parentTestId",
206
207
  "suitePath",
@@ -306,6 +307,7 @@
306
307
  "dependencyHash",
307
308
  "dependencies",
308
309
  "hasUnfollowedDependencies",
310
+ "unfollowedDependencies",
309
311
  "suiteId",
310
312
  "parentTestId",
311
313
  "suitePath",
@@ -411,6 +413,7 @@
411
413
  "dependencyHash",
412
414
  "dependencies",
413
415
  "hasUnfollowedDependencies",
416
+ "unfollowedDependencies",
414
417
  "suiteId",
415
418
  "parentTestId",
416
419
  "suitePath",
@@ -527,7 +530,7 @@
527
530
  "type": "null"
528
531
  }
529
532
  ],
530
- "description": "Hash of the test body, ignoring whitespace and comments; null when the test has no body."
533
+ "description": "Hash of the test body, ignoring whitespace and comments: the test function, one passed by name, or the one a wrapper call receives; null when the test has none of these."
531
534
  },
532
535
  "dependencyHash": {
533
536
  "type": "string",
@@ -545,6 +548,13 @@
545
548
  "type": "boolean",
546
549
  "description": "Something the test reaches couldn't be followed, so a change there doesn't change `dependencyHash`."
547
550
  },
551
+ "unfollowedDependencies": {
552
+ "type": "array",
553
+ "items": {
554
+ "type": "string"
555
+ },
556
+ "description": "Where the test reaches what couldn't be followed: the file and line of each place, as `support/venues.ts:2`, sorted; empty when `hasUnfollowedDependencies` is false. A `dependency-not-followed` warning at the place says what it is."
557
+ },
548
558
  "suiteId": {
549
559
  "anyOf": [
550
560
  {
@@ -979,6 +989,7 @@
979
989
  "dependencyHash",
980
990
  "dependencies",
981
991
  "hasUnfollowedDependencies",
992
+ "unfollowedDependencies",
982
993
  "suiteId",
983
994
  "parentTestId",
984
995
  "suitePath",
package/schema/v1.json CHANGED
@@ -772,7 +772,7 @@
772
772
  "type": "null"
773
773
  }
774
774
  ],
775
- "description": "Hash of the test body, ignoring whitespace and comments; null when the test has no body."
775
+ "description": "Hash of the test body, ignoring whitespace and comments: the test function, one passed by name, or the one a wrapper call receives; null when the test has none of these."
776
776
  },
777
777
  "dependencyHash": {
778
778
  "type": "string",
@@ -790,6 +790,13 @@
790
790
  "type": "boolean",
791
791
  "description": "Something the test reaches couldn't be followed, so a change there doesn't change `dependencyHash`."
792
792
  },
793
+ "unfollowedDependencies": {
794
+ "type": "array",
795
+ "items": {
796
+ "type": "string"
797
+ },
798
+ "description": "Where the test reaches what couldn't be followed: the file and line of each place, as `support/venues.ts:2`, sorted; empty when `hasUnfollowedDependencies` is false. A `dependency-not-followed` warning at the place says what it is."
799
+ },
793
800
  "suiteId": {
794
801
  "anyOf": [
795
802
  {
@@ -1224,6 +1231,7 @@
1224
1231
  "dependencyHash",
1225
1232
  "dependencies",
1226
1233
  "hasUnfollowedDependencies",
1234
+ "unfollowedDependencies",
1227
1235
  "suiteId",
1228
1236
  "parentTestId",
1229
1237
  "suitePath",