test-inventory 0.10.4 → 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 +106 -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 +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 +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 +15 -1
  35. package/dist/node-scripts.js +140 -13
  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 +15 -5
  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/extract.js CHANGED
@@ -2,7 +2,7 @@ import { childNodes, isFunctionNode, isImportMetaVitest, propertyName, returnVal
2
2
  import { commonJsExport, exportName } from "./frameworks/bindings.js";
3
3
  import { problem, readCount } from "./frameworks/common.js";
4
4
  import { snippet, splitLines } from "./source.js";
5
- import { isScopeNode } from "./values.js";
5
+ import { bindingNames, isScopeNode } from "./values.js";
6
6
  /** How many helpers deep a call is followed into the functions it calls, far more than real suites nest. */
7
7
  const MAX_DEPTH = 16;
8
8
  /**
@@ -175,7 +175,10 @@ class Walker {
175
175
  * time the helper is, and the first walk, from where the helper is called, places it.
176
176
  */
177
177
  callSites = new Map();
178
- /** The function with a name each test is declared in, which registers the test when it is called. */
178
+ /**
179
+ * The function with a name each test is declared in, which registers the test when it is called, and the helper call
180
+ * in it that registers the test, if any.
181
+ */
179
182
  declaredIn = new Map();
180
183
  deferred = [];
181
184
  isDeferred = new Set();
@@ -237,6 +240,7 @@ class Walker {
237
240
  isInFunction: false,
238
241
  helper: null,
239
242
  declaredIn: null,
243
+ calledIn: null,
240
244
  quiet: false,
241
245
  registeredBy: null,
242
246
  });
@@ -697,8 +701,14 @@ class Walker {
697
701
  context.test?.problems.push(...api.problems.map((item) => this.here(item)));
698
702
  return true;
699
703
  case 'invalid': {
700
- // Code that runs after the file loads, or only when a condition holds, can't be sure to stop it loading.
701
- const afterLoad = context.test !== null || context.hookScope !== null || context.helper !== null || context.isInCondition;
704
+ // Code that runs after the file loads, only when a condition holds, or in a function the scan can't place, which
705
+ // runs only if something calls it, can't be sure to stop it loading.
706
+ const afterLoad = context.test !== null ||
707
+ context.hookScope !== null ||
708
+ context.helper !== null ||
709
+ context.declaredIn !== null ||
710
+ context.calledIn !== null ||
711
+ context.isInCondition;
702
712
  this.report({ ...api.problem, afterLoad: afterLoad || api.problem.afterLoad, scope: context.scope });
703
713
  // Under a condition, the call either never runs or fails the file, so it declares nothing either way.
704
714
  return api.declaration && !context.isInCondition ? this.handle(call, api.declaration, context) : true;
@@ -726,12 +736,20 @@ class Walker {
726
736
  */
727
737
  helperCall(call, context) {
728
738
  const callee = unwrap(call.callee);
739
+ const runsHere = !context.test && !context.hookScope && !context.helper && this.callStack.length < MAX_DEPTH;
740
+ if (callee.type === 'MemberExpression') {
741
+ const object = unwrap(callee.object);
742
+ const member = propertyName(callee);
743
+ const imported = runsHere && object.type === 'Identifier' && member !== null
744
+ ? this.importedFunction(object.name, this.scopes, this.frame, member)
745
+ : null;
746
+ return imported && !this.callStack.includes(imported.fn) ? this.withinLimit(imported, call) : null;
747
+ }
729
748
  if (callee.type !== 'Identifier')
730
749
  return null;
731
750
  const fn = this.functionNamed(callee.name, this.scopes);
732
751
  if (!fn) {
733
- const runsHere = !context.test && !context.hookScope && !context.helper;
734
- const imported = runsHere && this.callStack.length < MAX_DEPTH ? this.importedFunction(callee.name, this.scopes) : null;
752
+ const imported = runsHere ? this.importedFunction(callee.name, this.scopes) : null;
735
753
  return imported && !this.callStack.includes(imported.fn) ? this.withinLimit(imported, call) : null;
736
754
  }
737
755
  const sites = this.callSites.get(fn) ?? new Map();
@@ -750,7 +768,9 @@ class Walker {
750
768
  guards: context.guards,
751
769
  });
752
770
  }
753
- else if (!this.callStack.includes(fn) && this.callStack.length < MAX_DEPTH) {
771
+ else if (context.declaredIn === null && !this.callStack.includes(fn) && this.callStack.length < MAX_DEPTH) {
772
+ // From a describe in a function walked where it is written, the call only counts as one of the function's calls:
773
+ // walking it there would depend on which of the two functions the file declares first.
754
774
  return this.withinLimit({ fn, frame: this.frame }, call);
755
775
  }
756
776
  return null;
@@ -794,14 +814,20 @@ class Walker {
794
814
  returnsOf: (name, at) => this.returnsOf(name, at, frame),
795
815
  };
796
816
  }
797
- /** The function a name imported from a local module stands for, in the file that writes it; null otherwise. */
798
- importedFunction(name, scopes, from = this.frame) {
817
+ /**
818
+ * The function a name imported from a local module stands for, in the file that writes it; null otherwise. With a
819
+ * `member`, the function is that export of a module the name holds whole, as `checks.validatesQuantity` after
820
+ * `import * as checks` or `const checks = require('./checks')`.
821
+ */
822
+ importedFunction(name, scopes, from = this.frame, member = null) {
799
823
  const source = from.values.importSource(name, scopes);
800
824
  if (source === null)
801
825
  return null;
802
826
  const imported = from.values.importedName(name, scopes);
803
- const frame = this.openFrom(from, source);
804
- return frame ? this.exportedFunction(frame, imported, new Set(), 0) : null;
827
+ const whole = imported === null || from.values.declarationOf(name, scopes)?.type === 'VariableDeclarator';
828
+ const exported = member === null ? imported : whole ? member : null;
829
+ const frame = exported === null ? null : this.openFrom(from, source);
830
+ return frame ? this.exportedFunction(frame, exported, new Set(), 0) : null;
805
831
  }
806
832
  /** A module a file imports, read as a frame once; null when it can't be read or parsed. */
807
833
  openFrom(frame, source) {
@@ -894,14 +920,18 @@ class Walker {
894
920
  ...context,
895
921
  isInFunction: true,
896
922
  declaredIn: null,
923
+ calledIn: context.declaredIn ? { fn: context.declaredIn, call } : context.calledIn,
897
924
  registeredBy: context.registeredBy ?? call,
898
925
  });
899
- });
926
+ }, spread === -1);
900
927
  this.callStack.pop();
901
928
  this.scopes.splice(0, this.scopes.length, ...saved);
902
- // What the module's own imports couldn't resolve is reported at the call, as it is why tests may be missing.
929
+ // What the module's own imports couldn't resolve is reported at the call, as it is why tests may be missing. Another
930
+ // runner's module it imports matters only to a function that uses it: a module of shared helpers may import one.
903
931
  if (frame !== caller) {
904
932
  for (const item of frame.adapter.problems.filter((found) => !this.moduleProblems.has(found))) {
933
+ if (item.code === 'framework-mismatch' && !usesImport(fn, frame.parsed.program, item.node))
934
+ continue;
905
935
  this.moduleProblems.add(item);
906
936
  this.report(item);
907
937
  }
@@ -1201,14 +1231,20 @@ class Walker {
1201
1231
  * else than where they are written: the runner adds a test to the describe around each call.
1202
1232
  */
1203
1233
  checkFunctionTests(exported) {
1204
- for (const [test, innermost] of this.declaredIn) {
1234
+ for (const [test, { fn: innermost, call }] of this.declaredIn) {
1205
1235
  let why = null;
1206
1236
  for (let fn = innermost; fn && !why; fn = this.written.get(fn).declaredIn) {
1207
1237
  why = this.misplaced(fn, exported);
1208
1238
  }
1209
1239
  if (!why)
1210
1240
  continue;
1211
- test.problems.push(problem('test-in-function', test.call, `The test is declared in a function, and ${why}. The runner registers the test at each call of the function, in the describe around the call; it is listed once, where it is written.`));
1241
+ const registers = 'The runner registers the test at each call of the function, in the describe around the call';
1242
+ if (call) {
1243
+ const helper = `${snippet(this.main.parsed.source.slice(call.callee.start, call.callee.end))}()`;
1244
+ test.problems.push(problem('test-in-function', test.site, `The test is registered by ${helper} in a function, and ${why}. ${registers}; it is listed where ${helper} is called.`));
1245
+ continue;
1246
+ }
1247
+ test.problems.push(problem('test-in-function', test.call, `The test is declared in a function, and ${why}. ${registers}; it is listed once, where it is written.`));
1212
1248
  }
1213
1249
  }
1214
1250
  nested(call, context, isTest) {
@@ -1296,8 +1332,9 @@ class Walker {
1296
1332
  problems: [...declaration.problems, ...empty].map((item) => this.here(item)),
1297
1333
  };
1298
1334
  this.tests.push(test);
1299
- if (context.declaredIn)
1300
- this.declaredIn.set(test, context.declaredIn);
1335
+ const placedBy = context.declaredIn ? { fn: context.declaredIn, call: null } : context.calledIn;
1336
+ if (placedBy)
1337
+ this.declaredIn.set(test, placedBy);
1301
1338
  this.cut(context.scope, call);
1302
1339
  // A function declared in the file and passed by name runs as the test body too.
1303
1340
  this.withDeclarationBody(declaration, call, (body) => {
@@ -1448,3 +1485,24 @@ function isConfigured(expression) {
1448
1485
  const object = unwrap(callee.object);
1449
1486
  return object.type === 'Identifier' && object.name === 'expect';
1450
1487
  }
1488
+ /**
1489
+ * Whether a function uses a name that the import at `at` in the program binds. A framework-mismatch problem is on an
1490
+ * import declaration, on one of its specifiers when the name comes from another module that imports the runner, or on
1491
+ * a `require()` declarator.
1492
+ */
1493
+ function usesImport(fn, program, at) {
1494
+ const find = (node) => node.start === at.start && node.end === at.end
1495
+ ? node
1496
+ : childNodes(node)
1497
+ .filter((child) => child.start <= at.start && at.end <= child.end)
1498
+ .map(find)
1499
+ .find((found) => found !== undefined);
1500
+ const node = program.body.map(find).find((found) => found !== undefined);
1501
+ const names = new Set(node.type === 'ImportDeclaration'
1502
+ ? node.specifiers.map((specifier) => specifier.local.name)
1503
+ : node.type === 'VariableDeclarator'
1504
+ ? bindingNames(node.id)
1505
+ : [node.local.name]);
1506
+ const uses = (node) => (node.type === 'Identifier' && names.has(node.name)) || childNodes(node).some(uses);
1507
+ return uses(fn.body);
1508
+ }
package/dist/files.js CHANGED
@@ -106,7 +106,8 @@ export async function findFiles(root, patterns, ignore, framework, platform = pr
106
106
  }
107
107
  const candidates = [];
108
108
  // The default sort compares UTF-16 code units, so the order is the same on every machine and locale.
109
- for (const match of matches.map((item) => item.replaceAll('\\', '/')).sort()) {
109
+ // Only on Windows is a backslash a separator; elsewhere it is part of a file's name.
110
+ for (const match of matches.map((item) => normalizePattern(item, platform)).sort()) {
110
111
  if (!EXTENSIONS.test(match)) {
111
112
  diagnostics.push(fileDiagnostic('unsupported-file', match, 'The file is not JavaScript or TypeScript, so it was not read.'));
112
113
  continue;
package/dist/filter.js CHANGED
@@ -17,6 +17,7 @@ const TEST_KEYS = Object.keys({
17
17
  dependencyHash: true,
18
18
  dependencies: true,
19
19
  hasUnfollowedDependencies: true,
20
+ unfollowedDependencies: true,
20
21
  suiteId: true,
21
22
  parentTestId: true,
22
23
  suitePath: true,
@@ -20,6 +20,12 @@ export declare function folders(root: string): string[];
20
20
  * below the root that declares it and holds one of the scanned `files` is read the same way, from its own folder up.
21
21
  */
22
22
  export declare function detectFrameworkVersion(root: string, framework: Framework, files: readonly string[]): DetectedVersion | null;
23
+ /**
24
+ * For a runner whose config the scan reads only in the root, the folder below the root nearest it with one, outside
25
+ * `ignore`, to run the scan from, or null when there is none; undefined for a runner whose configs below the root are
26
+ * read too.
27
+ */
28
+ export declare function configFolderBelow(root: string, framework: Framework, ignore: readonly string[]): string | null | undefined;
23
29
  /**
24
30
  * The runner a project uses, for a scan without `framework`: the one whose package a package.json in the root or a
25
31
  * folder below it, outside `ignore`, lists, or whose config is there. Only when none is found there do the package.json files above the
@@ -2,7 +2,7 @@ import { readFileSync } from 'node:fs';
2
2
  import path from 'node:path';
3
3
  import { globSync } from 'tinyglobby';
4
4
  import { nodeTestCommands } from "./node-scripts.js";
5
- import { OptionsError } from "./options.js";
5
+ import { majorMinor, OptionsError } from "./options.js";
6
6
  /** The package of each runner; `node:test` ships with Node.js. */
7
7
  const PACKAGES = {
8
8
  playwright: '@playwright/test',
@@ -39,13 +39,13 @@ export const FRAMEWORK_NAMES = {
39
39
  };
40
40
  /** Oldest supported version of each framework, as major, minor and for Bun, whose 1.2.23 changed how it runs tests, patch. */
41
41
  export const OLDEST = {
42
- playwright: [1, 42],
43
- vitest: [3, 0],
44
- jest: [29, 0],
42
+ playwright: [1, 31],
43
+ vitest: [1, 0],
44
+ jest: [27, 0],
45
45
  mocha: [10, 0],
46
- jasmine: [4, 0],
47
- cypress: [13, 0],
48
- webdriverio: [9, 0],
46
+ jasmine: [3, 0],
47
+ cypress: [10, 0],
48
+ webdriverio: [7, 0],
49
49
  node: [22, 0],
50
50
  bun: [1, 2, 23],
51
51
  };
@@ -86,11 +86,15 @@ function installedVersion(folder, name) {
86
86
  /** The version a lockfile in a folder records, and the lockfile's name. */
87
87
  function lockedVersion(folder, name) {
88
88
  const npm = readJson(path.join(folder, 'package-lock.json'));
89
- const fromNpm = npm?.packages?.[`node_modules/${name}`]?.version ?? npm?.dependencies?.[name]?.version;
89
+ const recorded = npm?.packages?.[`node_modules/${name}`]?.version ?? npm?.dependencies?.[name]?.version ?? null;
90
+ // npm 5 records the tarball of some packages in place of their version, and a git dependency's source.
91
+ const tarball = new RegExp(`/-/${escape(path.posix.basename(name))}-(\\d+\\.\\d+\\.\\d+[^/]*)\\.tgz$`);
92
+ const fromNpm = majorMinor(recorded) ? recorded : (tarball.exec(recorded ?? '')?.[1] ?? null);
90
93
  if (fromNpm)
91
94
  return { version: fromNpm, file: 'package-lock.json' };
92
95
  const pnpm = readText(path.join(folder, 'pnpm-lock.yaml'));
93
- const fromPnpm = pnpm && new RegExp(`^\\s+'?/?${escape(name)}@(\\d+\\.\\d+\\.\\d+[^:'(\\s]*)`, 'm').exec(pnpm);
96
+ // A key ends at the version: `vitest@5.0.0>happy-dom` in `overrides` selects a package below the runner.
97
+ const fromPnpm = pnpm && new RegExp(`^\\s+'?/?${escape(name)}@(\\d+\\.\\d+\\.\\d+[^:'(\\s>]*)['(:]`, 'm').exec(pnpm);
94
98
  if (fromPnpm)
95
99
  return { version: fromPnpm[1], file: 'pnpm-lock.yaml' };
96
100
  const yarn = readText(path.join(folder, 'yarn.lock'));
@@ -255,6 +259,30 @@ function isConfig(root, file, framework) {
255
259
  // A file that can't be read gives null, which holds no table.
256
260
  return framework !== 'bun' || /^\s*\[test\]/m.test(String(readText(path.join(root, file))));
257
261
  }
262
+ /** The configs of the runners the scan reads a config of only in the root, below it, and the folder each is run from. */
263
+ const ROOT_CONFIGS = {
264
+ cypress: { glob: '*/**/cypress.config.*', folder: (file) => path.dirname(file) },
265
+ webdriverio: { glob: '*/**/wdio.conf.*', folder: (file) => path.dirname(file) },
266
+ // Jasmine is run from the folder that holds `spec/support/jasmine.json`.
267
+ jasmine: { glob: '*/**/spec/support/jasmine.*', folder: (file) => path.dirname(path.dirname(path.dirname(file))) },
268
+ };
269
+ /**
270
+ * For a runner whose config the scan reads only in the root, the folder below the root nearest it with one, outside
271
+ * `ignore`, to run the scan from, or null when there is none; undefined for a runner whose configs below the root are
272
+ * read too.
273
+ */
274
+ export function configFolderBelow(root, framework, ignore) {
275
+ const configs = ROOT_CONFIGS[framework];
276
+ if (!configs)
277
+ return undefined;
278
+ const depth = (file) => file.split('/').length;
279
+ // The nearest, and of those as near the first by name, whatever order the file system lists them in.
280
+ const nearest = globSync(configs.glob, { cwd: root, ignore: ['**/node_modules/**', '**/.git/**', ...ignore] })
281
+ .filter((file) => isConfig(root, file, framework))
282
+ .sort()
283
+ .reduce((best, file) => (best === null || depth(file) < depth(best) ? file : best), null);
284
+ return nearest === null ? null : configs.folder(nearest);
285
+ }
258
286
  /**
259
287
  * Whether a package.json lists a runner, or for Jest or Mocha has a `jest` or `mocha` key, its config, or for
260
288
  * `node:test` has a script that runs `node --test`.
@@ -97,9 +97,16 @@ export type FollowImport = (source: string, imported: string, exported?: Exporte
97
97
  export interface Framework {
98
98
  name: string;
99
99
  isSource: (source: string) => boolean;
100
+ /** Whether a module is another runner's, which makes a file whose test object comes from it that runner's. */
101
+ isMismatched: (source: string) => boolean;
100
102
  /** The test objects of a followed module, which uses `follow` for the names it imports from other modules. */
101
103
  testObjects: (program: Program, follow: FollowImport) => TestObjects;
102
104
  }
105
+ /**
106
+ * Whether a module on a runner's list of other runners' modules is one, as `bun:test` in a Vitest scan: not when the
107
+ * file's reader finds a local file for it, as for a config that maps it to a shim of its own.
108
+ */
109
+ export declare function mismatchedFor(listed: ReadonlySet<string>, readModule: ModuleReader | null): (source: string) => boolean;
103
110
  /** Shared with the walk of imported helpers, so that a module both read and walked is parsed once. */
104
111
  export declare function parseModule(module: ModuleSource): ParsedFile;
105
112
  /**
@@ -116,6 +123,8 @@ interface Followed {
116
123
  start?: unknown;
117
124
  /** The module writes a function under the name, a helper that registers tests itself, which the walk follows. */
118
125
  isHelper?: boolean;
126
+ /** Another runner's module the chain ends at, as `@playwright/test` in a Jest scan. */
127
+ mismatch?: string;
119
128
  }
120
129
  /** Follows the import of `name` in a test file, with the diagnostic to report when it isn't a test object. */
121
130
  export declare function followImport(name: string, imported: ModuleImport, readModule: ModuleReader | null, file: FileContext, framework: Framework): {
@@ -253,6 +253,9 @@ export function exportsTestObject(program, name, objects, exported = 'test objec
253
253
  return own.source === null ? local(own.local) : objects.reexports(own.source, own.local, exported);
254
254
  }
255
255
  const commonJs = exported === 'test object' && name !== 'default' ? commonJsExport(program, name) : null;
256
+ // `module.exports = { describe }` passes a describe function on, as `export { describe }` does.
257
+ if (commonJs?.type === 'Identifier')
258
+ return local(commonJs.name);
256
259
  if (commonJs)
257
260
  return objects.isTestObject(commonJs);
258
261
  return program.body.some((statement) => {
@@ -403,6 +406,13 @@ export function importsFrom(program, matches) {
403
406
  (statement.type === 'ExportNamedDeclaration' && statement.source !== null && matches(statement.source.value)) ||
404
407
  requires(statement));
405
408
  }
409
+ /**
410
+ * Whether a module on a runner's list of other runners' modules is one, as `bun:test` in a Vitest scan: not when the
411
+ * file's reader finds a local file for it, as for a config that maps it to a shim of its own.
412
+ */
413
+ export function mismatchedFor(listed, readModule) {
414
+ return (source) => listed.has(source) && (readModule === null || 'reason' in readModule(source));
415
+ }
406
416
  /** Parsed modules, kept while their source is, so that a fixtures file many tests import is parsed once. */
407
417
  const parsedModules = new WeakMap();
408
418
  /** Shared with the walk of imported helpers, so that a module both read and walked is parsed once. */
@@ -423,6 +433,8 @@ const MAX_DEPTH = 16;
423
433
  * however many imports lead to it, as fixtures files that build on several others share their bases.
424
434
  */
425
435
  export function followModule(source, name, readModule, framework, exported = 'test object', path = [], followed = new Map()) {
436
+ if (framework.isMismatched(source))
437
+ return { exported: false, reason: null, mismatch: source };
426
438
  // Without a reader, as in scanSource, nothing can be read.
427
439
  const module = readModule ? readModule(source) : { reason: 'could not be read' };
428
440
  if ('reason' in module)
@@ -464,8 +476,13 @@ function followExports(module, name, framework, exported, within, followed) {
464
476
  // A helper function re-exported, as `import helper from './a'; export { helper }`, is no broken test object.
465
477
  if (followed.isHelper && origin.how === 're-exports')
466
478
  return followed;
479
+ const from = `${origin.how} it from '${origin.source}'`;
480
+ if (followed.mismatch) {
481
+ const via = followed.reason ? `${from}, which ${followed.reason}` : from;
482
+ return { exported: false, reason: via, mismatch: followed.mismatch };
483
+ }
467
484
  const end = followed.reason ?? unrecognized(origin.exported);
468
- return { exported: false, reason: `${origin.how} it from '${origin.source}', which ${end}` };
485
+ return { exported: false, reason: `${from}, which ${end}` };
469
486
  }
470
487
  if (importsFrom(program, framework.isSource))
471
488
  return { exported: false, reason: unrecognized(exported) };
@@ -505,9 +522,15 @@ function creatingCall(program, name, source) {
505
522
  }
506
523
  /** Follows the import of `name` in a test file, with the diagnostic to report when it isn't a test object. */
507
524
  export function followImport(name, imported, readModule, file, framework) {
508
- const { exported, reason, start } = followModule(imported.source, imported.imported, readModule, framework);
509
- const problemFound = reason
510
- ? problem('unresolved-test-import', imported.node, `'${name}' is imported from '${imported.source}', which ${reason}; tests that use it are missing.`, snippet(text(file, imported.node)))
511
- : null;
525
+ const { exported, reason, start, mismatch } = followModule(imported.source, imported.imported, readModule, framework);
526
+ // An import straight from another runner's module is reported where the file imports it.
527
+ const message = reason === null
528
+ ? null
529
+ : mismatch
530
+ ? `'${name}' is imported from '${imported.source}', which ${reason}, another runner's module, but the scan is for ${framework.name}.`
531
+ : `'${name}' is imported from '${imported.source}', which ${reason}; tests that use it are missing.`;
532
+ const problemFound = message === null
533
+ ? null
534
+ : problem(mismatch ? 'framework-mismatch' : 'unresolved-test-import', imported.node, message, snippet(text(file, imported.node)));
512
535
  return { exported, problem: problemFound, start };
513
536
  }
@@ -2,7 +2,7 @@ import { isFunctionNode, unwrap } from "../ast.js";
2
2
  import { bunCaseTitle } from "../case-titles.js";
3
3
  import { snippet } from "../source.js";
4
4
  import { requiredModule } from "./bindings.js";
5
- import { atLeast, hookFunction, namedFunction, problem, readChain, readCondition, readCount, readOptions, readTitle, refused, text, unresolvedOptions, } from "./common.js";
5
+ import { atLeast, hookFunction, namedFunction, problem, readChain, readCondition, readCount, readOptions, readTitle, refused, text, unresolvedOptions, wrappedFunction, } from "./common.js";
6
6
  import { SuiteAdapter } from "./test-functions.js";
7
7
  const SOURCE = 'bun:test';
8
8
  /** Bun rewrites imports of these to `bun:test` in its test files. */
@@ -136,7 +136,7 @@ export class BunAdapter extends SuiteAdapter {
136
136
  mode: this.mode(links, context),
137
137
  details: { tags: [], annotations: [], locks: [], meta: null, run },
138
138
  fn,
139
- hashed: fn ?? namedFunction(this.file, context.scopes, body),
139
+ hashed: fn ?? namedFunction(this.file, context.scopes, body) ?? wrappedFunction(body),
140
140
  isParameterized: table !== null,
141
141
  caseCount: table ? this.caseCount(table, problems, context) : null,
142
142
  cases: table ? this.tableCases(table, title, context) : null,
@@ -56,11 +56,14 @@ export declare function returnedTestObject(file: FileContext, call: CallExpressi
56
56
  * `shared` combines two; null when it may return something else.
57
57
  */
58
58
  export declare function returnedFunction<T>(returns: Returns, shared: (a: T | null, b: T | null) => T | null): T | null;
59
+ /** Whether a call is shaped like a test declaration, `name('title', fn)`, with a title written in place. */
60
+ export declare function looksLikeDeclaration(args: readonly Argument[]): boolean;
59
61
  /**
60
- * Whether a call on a name imported from a local file is shaped like a test declaration, `name('title', fn)`, and
61
- * so worth following to see if the name is a custom test object.
62
+ * Whether a call takes a declaration's arguments, a title of any kind and a body, as `test(TITLES.fill, fn)`. Enough
63
+ * to follow an imported name to its module, where what it is gets decided, whatever the title of the call that comes
64
+ * first.
62
65
  */
63
- export declare function looksLikeDeclaration(args: readonly Argument[]): boolean;
66
+ export declare function hasDeclarationArguments(args: readonly Argument[]): boolean;
64
67
  /**
65
68
  * A call the runner refuses. Shaped like a declaration outside any test or hook, it is also declared, without what
66
69
  * makes it fail, so that its tests, and those of a describe, are listed as not loaded rather than missing. Inside a
@@ -76,6 +79,12 @@ export declare function refused(call: CallExpression, refusal: Problem, context:
76
79
  export declare function mayDeclareTests(name: string, links: Link[]): boolean;
77
80
  /** A function declared in the file and passed by name, as in `test('fills an order', checkFill)`; null otherwise. */
78
81
  export declare function namedFunction(file: FileContext, scopes: readonly Node[], node: Argument | undefined): FunctionNode | null;
82
+ /**
83
+ * The function a test or describe passes through a wrapper, as in `test('fills an order', withBroker(async () => {}))`:
84
+ * the only function written among the wrapper call's arguments; null otherwise. The runner calls what the wrapper
85
+ * returns, so this function's parameters are the wrapper's to fill, not fixtures.
86
+ */
87
+ export declare function wrappedFunction(node: Argument | undefined): FunctionNode | null;
79
88
  export declare function findFunction(args: readonly Argument[], from?: number): FunctionNode | null;
80
89
  /** A hook's function: written in the call, or declared in the file and passed by name, as in `beforeEach(signIn)`. */
81
90
  export declare function hookFunction(file: FileContext, scopes: readonly Node[], args: readonly Argument[]): FunctionNode | null;
@@ -1,6 +1,8 @@
1
1
  import { isFunctionNode, isStringLiteral, propertyKey, propertyName, unwrap } from "../ast.js";
2
2
  import { snippet } from "../source.js";
3
3
  import { isKey } from "../values.js";
4
+ /** The methods every function has, which no runner's API adds to its test functions. */
5
+ const FUNCTION_METHODS = new Set(['bind', 'call', 'apply']);
4
6
  export function readChain(callee) {
5
7
  const node = unwrap(callee);
6
8
  switch (node.type) {
@@ -13,7 +15,8 @@ export function readChain(callee) {
13
15
  case 'MemberExpression': {
14
16
  const chain = readChain(node.object);
15
17
  const name = propertyName(node);
16
- if (!chain || name === null)
18
+ // `it.only.bind(it)` makes a function from a test function, and calls nothing of the runner's API.
19
+ if (!chain || name === null || FUNCTION_METHODS.has(name))
17
20
  return null;
18
21
  chain.links.push({ name, args: null, template: null });
19
22
  return chain;
@@ -116,19 +119,23 @@ function isTitleShaped(node) {
116
119
  }
117
120
  return isTitleLiteral(node);
118
121
  }
122
+ /** Whether a call is shaped like a test declaration, `name('title', fn)`, with a title written in place. */
123
+ export function looksLikeDeclaration(args) {
124
+ return isTitleShaped(args.at(0)) && hasDeclarationArguments(args);
125
+ }
119
126
  /**
120
- * Whether a call on a name imported from a local file is shaped like a test declaration, `name('title', fn)`, and
121
- * so worth following to see if the name is a custom test object.
127
+ * Whether a call takes a declaration's arguments, a title of any kind and a body, as `test(TITLES.fill, fn)`. Enough
128
+ * to follow an imported name to its module, where what it is gets decided, whatever the title of the call that comes
129
+ * first.
122
130
  */
123
- export function looksLikeDeclaration(args) {
124
- const last = args.at(-1);
125
- // The body is the last argument, a function or a function passed by name, or a function before a timeout, as in
126
- // Vitest's `test('title', fn, 30_000)`.
127
- const body = isFunctionNode(last) ||
128
- last?.type === 'Identifier' ||
129
- last?.type === 'MemberExpression' ||
130
- (args.length === 3 && isFunctionNode(args[1]));
131
- return isTitleShaped(args.at(0)) && args.length >= 2 && args.length <= 3 && body;
131
+ export function hasDeclarationArguments(args) {
132
+ // The body is the last argument, a function or a function passed by name, or such a function before a timeout, as in
133
+ // `test('title', fn, 30_000)` or `test('title', checkFill, 10_000)`.
134
+ const body = isBody(args.at(-1)) || (args.length === 3 && isBody(args[1]));
135
+ return args.length >= 2 && args.length <= 3 && body;
136
+ }
137
+ function isBody(arg) {
138
+ return isFunctionNode(arg) || arg?.type === 'Identifier' || arg?.type === 'MemberExpression';
132
139
  }
133
140
  /**
134
141
  * A call the runner refuses. Shaped like a declaration outside any test or hook, it is also declared, without what
@@ -161,6 +168,17 @@ export function mayDeclareTests(name, links) {
161
168
  export function namedFunction(file, scopes, node) {
162
169
  return node?.type === 'Identifier' ? file.values.functionOf(node.name, scopes) : null;
163
170
  }
171
+ /**
172
+ * The function a test or describe passes through a wrapper, as in `test('fills an order', withBroker(async () => {}))`:
173
+ * the only function written among the wrapper call's arguments; null otherwise. The runner calls what the wrapper
174
+ * returns, so this function's parameters are the wrapper's to fill, not fixtures.
175
+ */
176
+ export function wrappedFunction(node) {
177
+ if (node?.type !== 'CallExpression')
178
+ return null;
179
+ const functions = node.arguments.filter((arg) => isFunctionNode(arg));
180
+ return functions.length === 1 ? functions[0] : null;
181
+ }
164
182
  export function findFunction(args, from = 0) {
165
183
  for (const arg of args.slice(from)) {
166
184
  if (isFunctionNode(arg))
@@ -1,6 +1,6 @@
1
1
  import { isFunctionNode, unwrap } from "../ast.js";
2
2
  import { snippet } from "../source.js";
3
- import { atLeast, hookFunction, namedFunction, problem, readChain, readCount, readReason, readTitle, refused, text, } from "./common.js";
3
+ import { atLeast, hookFunction, namedFunction, problem, readChain, readCount, readReason, readTitle, refused, text, wrappedFunction, } from "./common.js";
4
4
  import { SuiteAdapter } from "./test-functions.js";
5
5
  const HOOKS = ['beforeEach', 'afterEach', 'beforeAll', 'afterAll'];
6
6
  const JASMINE = {
@@ -8,7 +8,15 @@ const JASMINE = {
8
8
  // Jasmine has no module to import its functions from: they are globals, set by the jasmine command, Karma or a
9
9
  // browser page.
10
10
  source: 'jasmine-core',
11
- mismatched: new Set(['@playwright/test', 'playwright/test', 'vitest', '@jest/globals', 'mocha']),
11
+ mismatched: new Set([
12
+ '@playwright/test',
13
+ 'playwright/test',
14
+ 'vitest',
15
+ '@jest/globals',
16
+ 'mocha',
17
+ 'node:test',
18
+ 'bun:test',
19
+ ]),
12
20
  starts: new Map([
13
21
  ['describe', { kind: 'describe', links: [] }],
14
22
  ['xdescribe', { kind: 'describe', links: ['skip'] }],
@@ -128,7 +136,7 @@ export class JasmineAdapter extends SuiteAdapter {
128
136
  mode: null,
129
137
  details: { tags: [], annotations: [], locks: [], meta: null, run: {} },
130
138
  fn,
131
- hashed: callback,
139
+ hashed: callback ?? wrappedFunction(body ?? undefined),
132
140
  isParameterized: false,
133
141
  caseCount: null,
134
142
  cases: null,
@@ -2,13 +2,13 @@ import { isFunctionNode, propertyName, returnValues, unwrap } from "../ast.js";
2
2
  import { jestKeysTitle, jestRowTitle } from "../case-titles.js";
3
3
  import { snippet } from "../source.js";
4
4
  import { requiredModule } from "./bindings.js";
5
- import { atLeast, findFunction, hookFunction, namedFunction, problem, readChain, readCount, readOptions, readTitle, refused, text, } from "./common.js";
5
+ import { atLeast, findFunction, hookFunction, namedFunction, problem, readChain, readCount, readOptions, readTitle, refused, text, wrappedFunction, } from "./common.js";
6
6
  import { SuiteAdapter } from "./test-functions.js";
7
7
  const SOURCE = '@jest/globals';
8
8
  const JEST = {
9
9
  name: 'Jest',
10
10
  source: SOURCE,
11
- mismatched: new Set(['@playwright/test', 'playwright/test', 'vitest']),
11
+ mismatched: new Set(['@playwright/test', 'playwright/test', 'vitest', 'mocha', 'node:test', 'bun:test']),
12
12
  starts: new Map([
13
13
  ['test', { kind: 'test', links: [] }],
14
14
  ['it', { kind: 'test', links: [] }],
@@ -29,8 +29,9 @@ const JEST = {
29
29
  required: null,
30
30
  };
31
31
  /**
32
- * The chains Jest's `test` and `describe` have, read from `jest-circus` 29.0, 29.7 and 30.5, where they are the same.
33
- * Each is a fixed path: `test.concurrent.only` exists, `test.only.concurrent` doesn't.
32
+ * The chains Jest's `test` and `describe` have, read from `jest-circus` 27.5, 28.0, 29.0, 29.7 and 30.5, where they are
33
+ * the same but for `failing`, which 28.1 added. Each is a fixed path: `test.concurrent.only` exists,
34
+ * `test.only.concurrent` doesn't.
34
35
  */
35
36
  const CHAINS = {
36
37
  test: new Set([
@@ -132,11 +133,14 @@ export class JestAdapter extends SuiteAdapter {
132
133
  const isTable = (link, index) => link.name === 'each' && index === links.length - 1;
133
134
  const called = (link) => link.args !== null || link.template !== null;
134
135
  const path = links.map((link) => link.name).join('.');
135
- const valid = CHAINS[kind].has(path) && links.every((link, index) => called(link) === isTable(link, index));
136
+ // jest-circus 28.1 added `failing`; 28.0 asks for circus `^28.0.3`, which installs it too.
137
+ const isTooNew = links.some((link) => link.name === 'failing') && !atLeast(this.file.version, 28, 0);
138
+ const valid = CHAINS[kind].has(path) && !isTooNew && links.every((link, index) => called(link) === isTable(link, index));
136
139
  if (valid)
137
140
  return this.declaration(call, kind, links, context);
138
141
  const callee = snippet(text(this.file, call.callee));
139
- const refusal = problem('invalid-chain', call, `${callee} is not part of Jest's API; the call throws, and Jest fails the file.`, callee);
142
+ const reason = isTooNew && CHAINS[kind].has(path) ? 'needs Jest 28 or newer' : "is not part of Jest's API";
143
+ const refusal = problem('invalid-chain', call, `${callee} ${reason}; the call throws, and Jest fails the file.`, callee);
140
144
  // Which of its parts the chain means is not known, so it declares a plain test or describe.
141
145
  return refused(call, refusal, context, () => this.declaration(call, kind, [], context));
142
146
  }
@@ -167,7 +171,7 @@ export class JestAdapter extends SuiteAdapter {
167
171
  mode: flags.has('concurrent') && !flags.has('skip') ? 'parallel' : null,
168
172
  details: { tags: [], annotations: [], locks: [], meta: null, run: {} },
169
173
  fn: given,
170
- hashed: given ?? callback,
174
+ hashed: given ?? callback ?? wrappedFunction(body),
171
175
  isParameterized: table !== null,
172
176
  caseCount: table ? this.caseCount(table, context, problems) : null,
173
177
  cases: table ? this.tableCases(table, title, context) : null,
@@ -1,10 +1,10 @@
1
1
  import { isFunctionNode, propertyName, unwrap } from "../ast.js";
2
2
  import { snippet } from "../source.js";
3
3
  import { requiredModule } from "./bindings.js";
4
- import { atLeast, hookFunction, namedFunction, problem, readChain, readCount, readTitle, refused, text, } from "./common.js";
4
+ import { atLeast, hookFunction, namedFunction, problem, readChain, readCount, readTitle, refused, text, wrappedFunction, } from "./common.js";
5
5
  import { SuiteAdapter } from "./test-functions.js";
6
6
  const SOURCE = 'mocha';
7
- const MISMATCHED = new Set(['@playwright/test', 'playwright/test', 'vitest', '@jest/globals']);
7
+ const MISMATCHED = new Set(['@playwright/test', 'playwright/test', 'vitest', '@jest/globals', 'node:test', 'bun:test']);
8
8
  const MODIFIERS = new Set(['only', 'skip']);
9
9
  /** Which of `test` and `describe` each global is, and the modifier it carries, by interface. */
10
10
  const STARTS = {
@@ -221,7 +221,7 @@ export class MochaAdapter extends SuiteAdapter {
221
221
  problems.push(titleProblem);
222
222
  const { body, options } = this.splitArguments(args);
223
223
  const fn = isFunctionNode(body) ? body : null;
224
- const hashed = fn ?? namedFunction(this.file, context.scopes, body);
224
+ const hashed = fn ?? namedFunction(this.file, context.scopes, body) ?? wrappedFunction(body);
225
225
  const line = this.file.source.line(call.start);
226
226
  // A test without a function is pending, which Mocha reports as skipped.
227
227
  const isSkipped = flags.has('skip') || (kind === 'test' && body === undefined);