test-inventory 0.10.3 → 0.11.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.
Files changed (49) hide show
  1. package/CHANGELOG.md +114 -0
  2. package/README.md +6 -4
  3. package/dist/cli.d.ts +1 -1
  4. package/dist/cli.js +18 -6
  5. package/dist/config-runs.d.ts +58 -4
  6. package/dist/config-runs.js +340 -42
  7. package/dist/config.d.ts +14 -6
  8. package/dist/config.js +273 -28
  9. package/dist/dependency-hash.d.ts +9 -1
  10. package/dist/dependency-hash.js +128 -13
  11. package/dist/diff.js +2 -0
  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/index.d.ts +2 -0
  32. package/dist/index.js +1 -0
  33. package/dist/model.d.ts +4 -1
  34. package/dist/node-scripts.d.ts +30 -0
  35. package/dist/node-scripts.js +247 -1
  36. package/dist/parse.d.ts +3 -0
  37. package/dist/parse.js +33 -0
  38. package/dist/records.js +7 -4
  39. package/dist/resolve.d.ts +3 -1
  40. package/dist/resolve.js +48 -15
  41. package/dist/run-commands.d.ts +20 -0
  42. package/dist/run-commands.js +107 -0
  43. package/dist/scan.js +24 -6
  44. package/dist/types.d.ts +9 -1
  45. package/dist/values.d.ts +21 -3
  46. package/dist/values.js +112 -13
  47. package/package.json +1 -1
  48. package/schema/diff-v1.json +12 -1
  49. 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,6 +458,41 @@ 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
498
  return resolved.ok ? resolved : { ok: false, importedFrom: source };
@@ -565,11 +623,13 @@ export class Values {
565
623
  }
566
624
  return members;
567
625
  }
626
+ /** A name's binding, and the scopes from the outermost to the one that declares it. */
568
627
  lookup(name, scopes) {
569
628
  for (let index = scopes.length - 1; index >= 0; index--) {
570
- const binding = this.bindings(scopes[index], scopes.slice(0, index + 1)).get(name);
629
+ const declaredIn = scopes.slice(0, index + 1);
630
+ const binding = this.bindings(scopes[index], declaredIn).get(name);
571
631
  if (binding)
572
- return { binding };
632
+ return { binding, scopes: declaredIn };
573
633
  }
574
634
  return null;
575
635
  }
@@ -643,7 +703,7 @@ function rootName(node) {
643
703
  * Names assigned to or changed anywhere in `body`, its functions included: `x = ...`, `x++`, `[x] = ...`,
644
704
  * `for (x of ...)`, `x.push(...)`.
645
705
  */
646
- function assignedNames(body) {
706
+ export function assignedNames(body) {
647
707
  const names = new Set();
648
708
  const targets = (target) => {
649
709
  switch (target?.type) {
@@ -855,19 +915,38 @@ function collectBindings(scope, scopes) {
855
915
  break;
856
916
  }
857
917
  };
918
+ // A `var` in a nested block belongs to the whole function or module, as in `case 'x': var context = ...`.
919
+ const hoist = (body) => {
920
+ for (const declarator of nestedVars(body)) {
921
+ for (const name of bindingNames(declarator.id))
922
+ if (!bindings.has(name))
923
+ bindings.set(name, { kind: 'other', declaration: declarator });
924
+ }
925
+ };
858
926
  switch (scope.type) {
859
927
  case 'Program':
928
+ for (const statement of scope.body)
929
+ declare(statement);
930
+ hoist(scope);
931
+ break;
860
932
  case 'BlockStatement':
861
933
  case 'StaticBlock':
862
934
  case 'TSModuleBlock':
863
935
  for (const statement of scope.body)
864
936
  declare(statement);
865
937
  break;
938
+ case 'SwitchStatement':
939
+ for (const item of scope.cases)
940
+ for (const statement of item.consequent)
941
+ declare(statement);
942
+ break;
866
943
  case 'FunctionDeclaration':
867
944
  case 'FunctionExpression':
868
945
  case 'ArrowFunctionExpression':
869
946
  for (const parameter of scope.params)
870
947
  other(bindingNames(parameter), scope);
948
+ // Only a TypeScript overload has no body, and no walk goes into one.
949
+ hoist(scope.body);
871
950
  break;
872
951
  case 'ForStatement':
873
952
  declare(scope.init);
@@ -882,6 +961,26 @@ function collectBindings(scope, scopes) {
882
961
  }
883
962
  return bindings;
884
963
  }
964
+ /** The `var` declarators in the blocks below a scope, outside the functions, classes and namespaces in it. */
965
+ function nestedVars(scope) {
966
+ const found = [];
967
+ // Only statements hold declarations, so expressions, however deep, are not walked.
968
+ const visit = (node) => {
969
+ if (node.type === 'VariableDeclaration') {
970
+ if (node.kind === 'var')
971
+ found.push(...node.declarations);
972
+ return;
973
+ }
974
+ if (!/Statement$|^(SwitchCase|CatchClause|ExportNamedDeclaration)$/.test(node.type))
975
+ return;
976
+ for (const child of childNodes(node))
977
+ visit(child);
978
+ };
979
+ for (const child of childNodes(scope))
980
+ if (child.type !== 'VariableDeclaration')
981
+ visit(child);
982
+ return found;
983
+ }
885
984
  /** `Object.keys(x)`, `Object.values(x)` or `Object.entries(x)`, which list as many items as `x` has keys. */
886
985
  function isObjectListing(call) {
887
986
  const callee = unwrap(call.callee);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "test-inventory",
3
- "version": "0.10.3",
3
+ "version": "0.11.0",
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",
@@ -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",