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
@@ -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);
@@ -1,7 +1,7 @@
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 { hookFunction, namedFunction, problem, readChain, readCount, readOptions, readReason, readStrings, readTitle, refused, text, unresolvedOption, unresolvedOptions, } from "./common.js";
4
+ import { hookFunction, namedFunction, problem, readChain, readCount, readOptions, readReason, readStrings, readTitle, refused, text, unresolvedOption, unresolvedOptions, wrappedFunction, } from "./common.js";
5
5
  import { SuiteAdapter } from "./test-functions.js";
6
6
  const MODIFIERS = new Set(['skip', 'todo', 'only', 'expectFailure']);
7
7
  const PRECEDENCE = ['skip', 'todo', 'expectedToFail'];
@@ -9,7 +9,7 @@ const TEST = { kind: 'test', links: [] };
9
9
  const NODE = {
10
10
  name: 'node:test',
11
11
  source: 'node:test',
12
- mismatched: new Set(['@playwright/test', 'playwright/test', 'vitest', '@jest/globals', 'mocha']),
12
+ mismatched: new Set(['@playwright/test', 'playwright/test', 'vitest', '@jest/globals', 'mocha', 'bun:test']),
13
13
  starts: new Map([
14
14
  ['test', TEST],
15
15
  ['it', TEST],
@@ -113,11 +113,13 @@ export class NodeAdapter extends SuiteAdapter {
113
113
  return refused(call, problem('invalid-chain', call, message, callee), context, () => this.declaration(call, kind, [], context));
114
114
  }
115
115
  declaration(call, kind, links, context) {
116
- const named = (node) => namedFunction(this.file, context.scopes, node) !== null;
116
+ const last = call.arguments.at(-1);
117
+ // A wrapper call is the function only last, where node:test takes it; before that, a call gives the options.
118
+ const named = (node) => namedFunction(this.file, context.scopes, node) !== null || (node === last && wrappedFunction(node) !== null);
117
119
  const { name, options, body } = splitArguments(call.arguments, named);
118
120
  const problems = [];
119
121
  const fn = isFunctionNode(body) ? body : null;
120
- const hashed = fn ?? namedFunction(this.file, context.scopes, body);
122
+ const hashed = fn ?? namedFunction(this.file, context.scopes, body) ?? wrappedFunction(body);
121
123
  let title = { text: '<anonymous>', withoutTags: '<anonymous>', isDynamic: false };
122
124
  // Without a name, Node.js names the test after its function, which takes the name of the variable that holds it.
123
125
  const fnName = fn?.id?.name ?? (body?.type === 'Identifier' ? body.name : null);
@@ -16,6 +16,8 @@ export declare class PlaywrightAdapter implements Adapter {
16
16
  /** Variables and names of functions read as test objects on trust, each reported once. */
17
17
  private readonly assumed;
18
18
  private readonly aliases;
19
+ /** Playwright as followed modules are read, with the modules that are another runner's for this file's reader. */
20
+ private readonly framework;
19
21
  constructor(program: Program, file: FileContext, readModule: ModuleReader | null);
20
22
  classify(call: CallExpression, context: CallContext): ApiCall | null;
21
23
  /**
@@ -35,9 +37,10 @@ export declare class PlaywrightAdapter implements Adapter {
35
37
  private assumeLocal;
36
38
  private looksLikeTest;
37
39
  /**
38
- * Whether a call through an imported name is worth following to the module: shaped like a test, or any call with a
39
- * title and a body through a name that reads like a test function, as `it.effect('title', fn)` on a test object that
40
- * a package extends.
40
+ * Whether a call through an imported name is worth following to the module: shaped like a test, a direct call with a
41
+ * title of any kind and a body, as `test(TITLES.fill, fn)`, or such a call through any member of a name that reads
42
+ * like a test function, as `it.effect('title', fn)` on a test object that a package extends. What the name is gets
43
+ * decided there, so it doesn't depend on which call comes first.
41
44
  */
42
45
  private worthFollowing;
43
46
  /**
@@ -73,6 +76,11 @@ export declare class PlaywrightAdapter implements Adapter {
73
76
  /** `test.step(title, body)` in a test body; a title that can't be worked out is kept as source text. */
74
77
  private step;
75
78
  private modifier;
79
+ /**
80
+ * Before Playwright 1.42, `test.fail(title, body)` and `test.skip()`, `fixme()` or `fail()` with details declare no
81
+ * test: Playwright reads the title as the condition, and the rest as the reason.
82
+ */
83
+ private titleAsCondition;
76
84
  /**
77
85
  * From Playwright 1.65, `test.skip(description)` with a string: the string is the reason, and still a condition, so
78
86
  * an empty one applies nothing. A template literal with text of its own is never empty.
@@ -1,8 +1,26 @@
1
1
  import { childNodes, isFunctionNode, propertyKey, propertyName, unwrap } from "../ast.js";
2
2
  import { snippet } from "../source.js";
3
- import { allDeclarators, bindAll, exportName, followImport, followModule, moduleImports, ModuleFunctions, requiredModule, } from "./bindings.js";
4
- import { atLeast, boundMembers, findFunction, hookFunction, isTestName, isTitleLiteral, localTestObject, looksLikeDeclaration, mayDeclareTests, mayHoldTestObject, namedFunction, origin, problem, readChain, destructuredNames, takesWhole, readCondition, readCount, readOptions, readReason, readStrings, readTitle, refused, returnedFunction, returnedTestObject, text, unresolvedOption, unresolvedOptions, } from "./common.js";
5
- const MISMATCHED_SOURCES = new Set(['vitest', '@jest/globals']);
3
+ import { allDeclarators, bindAll, exportName, followImport, followModule, mismatchedFor, moduleImports, ModuleFunctions, requiredModule, } from "./bindings.js";
4
+ import { atLeast, boundMembers, findFunction, hookFunction, isTestName, isTitleLiteral, localTestObject, hasDeclarationArguments, looksLikeDeclaration, mayDeclareTests, mayHoldTestObject, namedFunction, origin, problem, readChain, destructuredNames, takesWhole, readCondition, readCount, readOptions, readReason, readStrings, readTitle, refused, returnedFunction, returnedTestObject, text, unresolvedOption, unresolvedOptions, wrappedFunction, } from "./common.js";
5
+ /**
6
+ * What `@playwright/test` exports besides `test` and `expect`, which its `test.js` assigns onto the original `test`
7
+ * function: library calls such as `playwright.chromium.launch()`, not tests.
8
+ */
9
+ const MODULE_EXPORTS = new Set([
10
+ 'defineConfig',
11
+ 'mergeTests',
12
+ 'mergeExpects',
13
+ 'chromium',
14
+ 'firefox',
15
+ 'webkit',
16
+ 'selectors',
17
+ 'devices',
18
+ 'errors',
19
+ 'request',
20
+ '_electron',
21
+ '_android',
22
+ ]);
23
+ const MISMATCHED_SOURCES = new Set(['vitest', '@jest/globals', 'mocha', 'node:test', 'bun:test']);
6
24
  // Maps rather than object literals, so names such as `constructor` don't match inherited properties.
7
25
  const DESCRIBES = new Map([
8
26
  ['describe', {}],
@@ -44,6 +62,8 @@ const ADDED_IN = new Map([
44
62
  ['step.skip', [1, 50]],
45
63
  ['abort', [1, 60]],
46
64
  ]);
65
+ /** The version that added the details of tests and describes, `{ tag, annotation }`, and `test.fail(title, body)`. */
66
+ const DETAILS_ADDED_IN = [1, 42];
47
67
  function isPlaywrightSource(source) {
48
68
  return (source === '@playwright/test' ||
49
69
  source === 'playwright/test' ||
@@ -66,15 +86,15 @@ class PlaywrightBindings {
66
86
  follow;
67
87
  /** The module's functions and the variables they may build test objects in; see `ModuleFunctions`. */
68
88
  functions;
69
- constructor(program, follow) {
70
- this.imported = moduleImports(program, (source) => isPlaywrightSource(source) || MISMATCHED_SOURCES.has(source));
89
+ constructor(program, follow, isMismatched) {
90
+ this.imported = moduleImports(program, (source) => isPlaywrightSource(source) || isMismatched(source));
71
91
  this.follow = follow;
72
92
  this.functions = new ModuleFunctions(program, this.imported, follow);
73
93
  for (const statement of program.body) {
74
94
  if (statement.type !== 'ImportDeclaration' || statement.importKind === 'type')
75
95
  continue;
76
96
  const source = statement.source.value;
77
- if (MISMATCHED_SOURCES.has(source)) {
97
+ if (isMismatched(source)) {
78
98
  this.mismatches.push(problem('framework-mismatch', statement, `The file imports '${source}', but the scan is for Playwright.`));
79
99
  }
80
100
  if (!isPlaywrightSource(source))
@@ -214,11 +234,6 @@ class PlaywrightBindings {
214
234
  return true;
215
235
  }
216
236
  }
217
- const PLAYWRIGHT = {
218
- name: 'Playwright',
219
- isSource: isPlaywrightSource,
220
- testObjects: (program, follow) => new PlaywrightBindings(program, follow),
221
- };
222
237
  export class PlaywrightAdapter {
223
238
  problems;
224
239
  fileTags = [];
@@ -234,21 +249,30 @@ export class PlaywrightAdapter {
234
249
  /** Variables and names of functions read as test objects on trust, each reported once. */
235
250
  assumed = new Set();
236
251
  aliases = new Map();
252
+ /** Playwright as followed modules are read, with the modules that are another runner's for this file's reader. */
253
+ framework;
237
254
  constructor(program, file, readModule) {
238
255
  this.file = file;
239
256
  this.readModule = readModule;
257
+ const isMismatched = mismatchedFor(MISMATCHED_SOURCES, readModule);
258
+ this.framework = {
259
+ name: 'Playwright',
260
+ isSource: isPlaywrightSource,
261
+ isMismatched,
262
+ testObjects: (followedProgram, follow) => new PlaywrightBindings(followedProgram, follow, isMismatched),
263
+ };
240
264
  // A test object the file builds from an imported one, as in `const test = base.extend({...})`, is followed
241
265
  // quietly: a call through the import itself is what reports an import that can't be followed.
242
266
  const followed = new Map();
243
267
  this.bindings = new PlaywrightBindings(program, (source, imported, exported = 'test object') => {
244
268
  const key = `${source}\0${exported}\0${imported}`;
245
269
  if (!followed.has(key)) {
246
- followed.set(key, followModule(source, imported, readModule, PLAYWRIGHT, exported).exported);
270
+ followed.set(key, followModule(source, imported, readModule, this.framework, exported).exported);
247
271
  }
248
272
  return followed.get(key) === true;
249
- });
273
+ }, isMismatched);
250
274
  this.problems = [...this.bindings.mismatches];
251
- this.imports = moduleImports(program, (source) => isPlaywrightSource(source) || MISMATCHED_SOURCES.has(source));
275
+ this.imports = moduleImports(program, (source) => isPlaywrightSource(source) || isMismatched(source));
252
276
  }
253
277
  classify(call, context) {
254
278
  const chain = readChain(call.callee);
@@ -257,7 +281,7 @@ export class PlaywrightAdapter {
257
281
  return null;
258
282
  const names = links.map((link) => link.name);
259
283
  const key = names.join('.');
260
- if (key === 'defineConfig' &&
284
+ if (MODULE_EXPORTS.has(names[0]) &&
261
285
  chain &&
262
286
  (this.bindings.isModule(chain.base) ||
263
287
  (chain.base.type === 'Identifier' && this.bindings.moduleTests.has(chain.base.name)))) {
@@ -281,6 +305,11 @@ export class PlaywrightAdapter {
281
305
  return this.testCall(call, key, context);
282
306
  }
283
307
  const describe = DESCRIBES.get(key);
308
+ if (describe && call.arguments.length === 3 && !atLeast(this.file.version, ...DETAILS_ADDED_IN)) {
309
+ const callee = snippet(text(this.file, call.callee));
310
+ const message = `${callee}(title, details, body) needs Playwright 1.42 or newer; the call throws, so Playwright fails to load the file and runs no tests at all.`;
311
+ return refused(call, problem('invalid-chain', call, message, callee), context, () => this.describeCall(call, describe, context));
312
+ }
284
313
  if (describe)
285
314
  return this.describeCall(call, describe, context);
286
315
  if (key === 'describe.configure')
@@ -396,12 +425,13 @@ export class PlaywrightAdapter {
396
425
  return links.length === 0 ? looksLikeDeclaration(args) : TEST_MEMBERS.has(links[0].name);
397
426
  }
398
427
  /**
399
- * Whether a call through an imported name is worth following to the module: shaped like a test, or any call with a
400
- * title and a body through a name that reads like a test function, as `it.effect('title', fn)` on a test object that
401
- * a package extends.
428
+ * Whether a call through an imported name is worth following to the module: shaped like a test, a direct call with a
429
+ * title of any kind and a body, as `test(TITLES.fill, fn)`, or such a call through any member of a name that reads
430
+ * like a test function, as `it.effect('title', fn)` on a test object that a package extends. What the name is gets
431
+ * decided there, so it doesn't depend on which call comes first.
402
432
  */
403
433
  worthFollowing(name, links, args) {
404
- return this.looksLikeTest(links, args) || (isTestName(name) && looksLikeDeclaration(args));
434
+ return (this.looksLikeTest(links, args) || ((links.length === 0 || isTestName(name)) && hasDeclarationArguments(args)));
405
435
  }
406
436
  /**
407
437
  * The members of `test` a variable holds: those of a describe function, as in `const serialDescribe =
@@ -473,7 +503,7 @@ export class PlaywrightAdapter {
473
503
  const imported = this.imports.get(name);
474
504
  let result = this.followed.get(name);
475
505
  if (!result) {
476
- result = followImport(name, imported, this.readModule, this.file, PLAYWRIGHT);
506
+ result = followImport(name, imported, this.readModule, this.file, this.framework);
477
507
  this.followed.set(name, result);
478
508
  if (result.exported) {
479
509
  this.bindings.testNames.add(name);
@@ -521,10 +551,16 @@ export class PlaywrightAdapter {
521
551
  }
522
552
  else {
523
553
  // skip, fixme and fail: (title, body) declares a test, (condition, description) changes the state of others.
554
+ // Playwright tells them apart by whether the last argument is a function, passed by name or not.
524
555
  declares =
525
- isFunctionNode(last) || (this.isTitle(args[0], context) && !this.isTitle(args[args.length - 1], context));
526
- }
527
- if (!declares && declarationOnly) {
556
+ isFunctionNode(last) ||
557
+ namedFunction(this.file, context.scopes, last) !== null ||
558
+ (this.isTitle(args[0], context) && !this.isTitle(args[args.length - 1], context));
559
+ }
560
+ const hasDetails = atLeast(this.file.version, ...DETAILS_ADDED_IN);
561
+ // Before Playwright 1.42, which reads the details of a test, nothing checks that a test has a body.
562
+ const isBodyless = !declares && declarationOnly && !hasDetails && args.length === 1 && !isFunctionNode(first);
563
+ if (!declares && declarationOnly && !isBodyless) {
528
564
  const callee = snippet(text(this.file, call.callee));
529
565
  return {
530
566
  kind: 'invalid',
@@ -532,9 +568,17 @@ export class PlaywrightAdapter {
532
568
  };
533
569
  }
534
570
  const state = STATES.get(key) ?? null;
535
- if (!declares)
571
+ if (!declares && !isBodyless)
536
572
  return this.modifier(call, state, context);
573
+ if (!hasDetails && !declarationOnly && (key === 'fail' || args.length === 3)) {
574
+ return this.titleAsCondition(call, state, context);
575
+ }
537
576
  const problems = [];
577
+ if (isBodyless) {
578
+ const callee = snippet(text(this.file, call.callee));
579
+ const message = `${callee}() has no test body, so the test fails when it runs.`;
580
+ problems.push({ ...problem('test-without-body', call, message), level: 'warning' });
581
+ }
538
582
  const { title, problem: titleProblem } = readTitle(this.file, context.scopes, args[0], {
539
583
  stripTags: true,
540
584
  functionNames: false,
@@ -543,23 +587,28 @@ export class PlaywrightAdapter {
543
587
  problems.push(titleProblem);
544
588
  const line = this.file.source.line(call.start);
545
589
  const fn = isFunctionNode(last) ? last : null;
546
- const hashed = fn ?? namedFunction(this.file, context.scopes, last);
547
- this.checkFixtureArguments(hashed);
590
+ const callback = fn ?? namedFunction(this.file, context.scopes, last);
591
+ this.checkFixtureArguments(callback);
592
+ if (args.length === 3 && !hasDetails) {
593
+ const callee = snippet(text(this.file, call.callee));
594
+ const message = `${callee}(title, details, body) needs Playwright 1.42 or newer; before it, Playwright takes the details for the body, so the test fails when it runs, without their tags and annotations.`;
595
+ problems.push({ ...problem('invalid-chain', call, message, callee), level: 'warning' });
596
+ }
548
597
  return {
549
598
  kind: 'test',
550
599
  title,
551
600
  states: state ? [{ state, condition: null, reason: null, hasDynamicReason: false, line }] : [],
552
601
  isOnly: key.endsWith('only'),
553
602
  mode: null,
554
- details: this.details(args.length === 3 ? args[1] : undefined, context, problems, title.text),
603
+ details: this.details(args.length === 3 && hasDetails ? args[1] : undefined, context, problems, title.text),
555
604
  fn,
556
- hashed,
605
+ hashed: callback ?? wrappedFunction(last),
557
606
  isParameterized: false,
558
607
  caseCount: null,
559
608
  cases: null,
560
609
  testContext: null,
561
- fixtures: destructuredNames(hashed, 0),
562
- takesAllFixtures: takesWhole(hashed, 0),
610
+ fixtures: destructuredNames(callback, 0),
611
+ takesAllFixtures: takesWhole(callback, 0),
563
612
  usesBench: false,
564
613
  problems,
565
614
  };
@@ -649,6 +698,23 @@ export class PlaywrightAdapter {
649
698
  problems,
650
699
  };
651
700
  }
701
+ /**
702
+ * Before Playwright 1.42, `test.fail(title, body)` and `test.skip()`, `fixme()` or `fail()` with details declare no
703
+ * test: Playwright reads the title as the condition, and the rest as the reason.
704
+ */
705
+ titleAsCondition(call, state, context) {
706
+ const callee = snippet(text(this.file, call.callee));
707
+ const form = call.arguments.length === 3 ? 'title, details, body' : 'title, body';
708
+ const message = `${callee}(${form}) needs Playwright 1.42 or newer; before it, Playwright reads the title as a condition and applies ${callee}() to every test in the scope.`;
709
+ return {
710
+ kind: 'modifier',
711
+ state,
712
+ condition: readCondition(this.file, context.scopes, call.arguments[0]),
713
+ reason: null,
714
+ hasDynamicReason: false,
715
+ problems: [problem('skip-without-body', call, message, snippet(text(this.file, call)))],
716
+ };
717
+ }
652
718
  /**
653
719
  * From Playwright 1.65, `test.skip(description)` with a string: the string is the reason, and still a condition, so
654
720
  * an empty one applies nothing. A template literal with text of its own is never empty.
@@ -697,9 +763,12 @@ export class PlaywrightAdapter {
697
763
  mode: kind.mode ?? null,
698
764
  isShuffled: false,
699
765
  passesDown: null,
700
- details: this.details(!anonymous && args.length === 3 ? args[1] : undefined, context, problems, title?.text ?? ''),
766
+ // Before Playwright 1.42 a describe has no tags: the report gives a test only those of its own title.
767
+ details: atLeast(this.file.version, ...DETAILS_ADDED_IN)
768
+ ? this.details(!anonymous && args.length === 3 ? args[1] : undefined, context, problems, title?.text ?? '')
769
+ : this.details(undefined, context, problems, ''),
701
770
  fn,
702
- hashed: callback,
771
+ hashed: callback ?? wrappedFunction(args.at(-1)),
703
772
  isParameterized: false,
704
773
  caseCount: null,
705
774
  cases: null,
@@ -75,7 +75,7 @@ export declare class SuiteBindings implements TestObjects {
75
75
  private readonly declared;
76
76
  /** Whether the module is one a scanned file imports from, where no walk reads its globals and chains. */
77
77
  private readonly isFollowed;
78
- constructor(program: Program, dialect: Dialect, follow: FollowImport, isFollowed?: boolean);
78
+ constructor(program: Program, dialect: Dialect, follow: FollowImport, isMismatched: (source: string) => boolean, isFollowed?: boolean);
79
79
  isTestName(name: string): boolean;
80
80
  /**
81
81
  * `followsCalls` is cleared where a call is not followed to what it returns: while the names are bound, so that only
@@ -131,17 +131,21 @@ export declare abstract class SuiteAdapter implements Adapter {
131
131
  private readonly aliases;
132
132
  /** First members that show a name imported from a local file is used as the framework's `test`. */
133
133
  private readonly testMembers;
134
+ /** Whether a module is another runner's, unless the config maps it to a local file. */
135
+ private readonly isMismatched;
134
136
  constructor(parsed: ParsedFile, file: FileContext, readModule: ModuleReader | null, dialect: Dialect, testMembers: Iterable<string>);
135
137
  abstract classify(call: CallExpression, context: CallContext): ApiCall | null;
136
138
  /** Whether a variable that holds a test function may hold this link after it, as `const skipOnCi = test.skipIf(isCI)`. */
137
139
  protected abstract isAliasLink(kind: Kind, link: Link): boolean;
138
140
  protected abstract hook(call: CallExpression, name: keyof HookCounts, context: CallContext): ApiCall;
139
- testFunction(expression: Expression, scopes: readonly Node[], returnsOf: CallContext['returnsOf']): TestFunction | null;
141
+ /** With `held` false, the expression is a name being called, not a value kept to be called later. */
142
+ testFunction(expression: Expression, scopes: readonly Node[], returnsOf: CallContext['returnsOf'], held?: boolean): TestFunction | null;
140
143
  /**
141
144
  * The function a chain calls and the links after it, or null when it isn't the framework's. An import that can't be
142
- * followed is reported only outside test and hook bodies, where a call can declare tests.
145
+ * followed is reported only outside test and hook bodies, where a call can declare tests. A chain `held` as a value,
146
+ * as a branch of `?:` or what a function returns, is called later with arguments not known here.
143
147
  */
144
- protected resolve(chain: Chain, args: readonly Argument[], lookup: Lookup): TestFunction | null;
148
+ protected resolve(chain: Chain, args: readonly Argument[], lookup: Lookup, held?: boolean): TestFunction | null;
145
149
  private start;
146
150
  /**
147
151
  * What a chain on the framework's module starts with: the member it names, or for a module that can be called, as
@@ -182,9 +186,11 @@ export declare abstract class SuiteAdapter implements Adapter {
182
186
  private assumeLocal;
183
187
  private looksLikeTest;
184
188
  /**
185
- * Whether a call through an imported name is worth following to the module: shaped like a test, or any call with a
186
- * title and a body through a name that reads like a test function, as `it.effect('title', fn)` on a test object that
187
- * a package extends.
189
+ * Whether a call through an imported name is worth following to the module: shaped like a test, a direct call with a
190
+ * title of any kind and a body, as `test(TITLES.fill, fn)`, or such a call through any member of a name that reads
191
+ * like a test function, as `it.effect('title', fn)` on a test object that a package extends. A name that reads like
192
+ * one and is held as a value, as in `open ? test : test.skip`, is followed too. What the name is gets decided there,
193
+ * so it doesn't depend on which call comes first.
188
194
  */
189
195
  private worthFollowing;
190
196
  /** The framework as followed modules are read. */
@@ -1,7 +1,7 @@
1
1
  import { propertyKey, propertyName, unwrap } from "../ast.js";
2
2
  import { bindingNames } from "../values.js";
3
- import { allDeclarators, bindAll, exportName, followImport, followModule, moduleImports, ModuleFunctions, ownExport, requiredModule, topLevelDeclarators, } from "./bindings.js";
4
- import { boundMembers, isTestName, localTestObject, looksLikeDeclaration, mayDeclareTests, mayHoldTestObject, problem, readChain, returnedFunction, returnedTestObject, } from "./common.js";
3
+ import { allDeclarators, bindAll, commonJsExport, exportName, followImport, followModule, mismatchedFor, moduleImports, ModuleFunctions, ownExport, requiredModule, topLevelDeclarators, } from "./bindings.js";
4
+ import { boundMembers, isTestName, localTestObject, hasDeclarationArguments, looksLikeDeclaration, mayDeclareTests, mayHoldTestObject, problem, readChain, returnedFunction, returnedTestObject, } from "./common.js";
5
5
  /** What a test function chosen at run time, as in `isCI ? it.skip : it`, is either way: only the links both have. */
6
6
  export function shared(a, b) {
7
7
  if (!a || a.kind !== b?.kind)
@@ -51,19 +51,19 @@ export class SuiteBindings {
51
51
  declared;
52
52
  /** Whether the module is one a scanned file imports from, where no walk reads its globals and chains. */
53
53
  isFollowed;
54
- constructor(program, dialect, follow, isFollowed = false) {
54
+ constructor(program, dialect, follow, isMismatched, isFollowed = false) {
55
55
  this.dialect = dialect;
56
56
  this.program = program;
57
57
  this.isFollowed = isFollowed;
58
58
  this.declared = topLevelNames(program);
59
- this.imported = moduleImports(program, (source) => isOwnModule(dialect, source) || dialect.mismatched.has(source));
59
+ this.imported = moduleImports(program, (source) => isOwnModule(dialect, source) || isMismatched(source));
60
60
  this.follow = follow;
61
61
  this.functions = new ModuleFunctions(program, this.imported, follow);
62
62
  for (const statement of program.body) {
63
63
  if (statement.type !== 'ImportDeclaration' || statement.importKind === 'type')
64
64
  continue;
65
65
  const source = statement.source.value;
66
- if (dialect.mismatched.has(source)) {
66
+ if (isMismatched(source)) {
67
67
  this.problems.push(problem('framework-mismatch', statement, `The file imports '${source}', but the scan is for ${dialect.name}.`));
68
68
  }
69
69
  if (!isOwnModule(dialect, source))
@@ -180,6 +180,10 @@ export class SuiteBindings {
180
180
  const own = ownExport(this.program, name);
181
181
  if (own?.kind === 'default')
182
182
  return this.startOf(own.value);
183
+ // `module.exports = { suite: describe }` or `module.exports.suite = describe` holds what it is set to.
184
+ const commonJs = own ? null : commonJsExport(this.program, name);
185
+ if (commonJs)
186
+ return this.startOf(commonJs);
183
187
  const local = own?.kind === 'specifier' ? own.local : name;
184
188
  return this.starts.get(local) ?? null;
185
189
  }
@@ -270,11 +274,14 @@ export class SuiteAdapter {
270
274
  aliases = new Map();
271
275
  /** First members that show a name imported from a local file is used as the framework's `test`. */
272
276
  testMembers;
277
+ /** Whether a module is another runner's, unless the config maps it to a local file. */
278
+ isMismatched;
273
279
  constructor(parsed, file, readModule, dialect, testMembers) {
274
280
  this.file = file;
275
281
  this.readModule = readModule;
276
282
  this.dialect = dialect;
277
283
  this.testMembers = new Set([...testMembers, ...dialect.starts.keys()]);
284
+ this.isMismatched = mismatchedFor(dialect.mismatched, readModule);
278
285
  // A test object the file builds from an imported one, as in `const it = base.extend({...})`, is followed quietly:
279
286
  // a call through the import itself is what reports an import that can't be followed.
280
287
  const followed = new Map();
@@ -284,19 +291,21 @@ export class SuiteAdapter {
284
291
  followed.set(key, followModule(source, imported, readModule, this.framework(), exported).exported);
285
292
  }
286
293
  return followed.get(key) === true;
287
- });
294
+ }, this.isMismatched);
288
295
  this.problems = [...this.bindings.problems];
289
- this.imports = moduleImports(parsed.program, (source) => isOwnModule(dialect, source) || dialect.mismatched.has(source));
296
+ this.imports = moduleImports(parsed.program, (source) => isOwnModule(dialect, source) || this.isMismatched(source));
290
297
  }
291
- testFunction(expression, scopes, returnsOf) {
292
- return this.aliasOf(expression, { scopes, inBody: false, returnsOf });
298
+ /** With `held` false, the expression is a name being called, not a value kept to be called later. */
299
+ testFunction(expression, scopes, returnsOf, held = true) {
300
+ return this.aliasOf(expression, { scopes, inBody: false, returnsOf }, held);
293
301
  }
294
302
  /**
295
303
  * The function a chain calls and the links after it, or null when it isn't the framework's. An import that can't be
296
- * followed is reported only outside test and hook bodies, where a call can declare tests.
304
+ * followed is reported only outside test and hook bodies, where a call can declare tests. A chain `held` as a value,
305
+ * as a branch of `?:` or what a function returns, is called later with arguments not known here.
297
306
  */
298
- resolve(chain, args, lookup) {
299
- const start = this.start(chain, args, lookup);
307
+ resolve(chain, args, lookup, held = false) {
308
+ const start = this.start(chain, args, lookup, held);
300
309
  if (!start)
301
310
  return null;
302
311
  let kind = start.kind;
@@ -313,7 +322,7 @@ export class SuiteAdapter {
313
322
  }
314
323
  return { kind, links };
315
324
  }
316
- start(chain, args, lookup) {
325
+ start(chain, args, lookup, held) {
317
326
  const { base, links: chainLinks } = chain;
318
327
  const { scopes, inBody } = lookup;
319
328
  // `require('@jest/globals').test(...)`: the module itself, called in place.
@@ -363,7 +372,7 @@ export class SuiteAdapter {
363
372
  : null;
364
373
  }
365
374
  const followed = this.imports.get(base.name)?.node === declaration &&
366
- this.worthFollowing(base.name, chainLinks, args) &&
375
+ this.worthFollowing(base.name, chainLinks, args, held) &&
367
376
  this.follow(base.name, !inBody && mayDeclareTests(base.name, chainLinks));
368
377
  if (!followed && !this.bindings.declarations.has(declaration)) {
369
378
  const alias = declaration.type === 'VariableDeclarator' ? this.alias(declaration, base.name, lookup) : null;
@@ -420,7 +429,7 @@ export class SuiteAdapter {
420
429
  if (alias === undefined) {
421
430
  // Set first, so a variable defined through itself ends the lookup.
422
431
  this.aliases.set(declarator, null);
423
- alias = declarator.init ? this.aliasOf(declarator.init, lookup) : null;
432
+ alias = declarator.init ? this.aliasOf(declarator.init, lookup, true) : null;
424
433
  this.aliases.set(declarator, alias);
425
434
  }
426
435
  return alias && { kind: alias.kind, links: [...alias.links, ...links(destructured)] };
@@ -442,8 +451,8 @@ export class SuiteAdapter {
442
451
  members = members.slice(1);
443
452
  return members;
444
453
  }
445
- aliasOf(expression, lookup) {
446
- const functions = this.choices(expression, lookup)?.functions ?? [];
454
+ aliasOf(expression, lookup, held = false) {
455
+ const functions = this.choices(expression, lookup, held)?.functions ?? [];
447
456
  if (functions.length === 0)
448
457
  return null;
449
458
  // Only the modifiers every choice has apply.
@@ -454,16 +463,16 @@ export class SuiteAdapter {
454
463
  * function is never falsy, so `test.skip || test` and `test.skip ?? test` hold `test.skip`, while
455
464
  * `process.env.CI && test.skip || test` may hold either. Both branches of `?:` have to be test functions.
456
465
  */
457
- choices(expression, lookup) {
466
+ choices(expression, lookup, held) {
458
467
  const node = unwrap(expression);
459
468
  if (node.type === 'ConditionalExpression') {
460
- const [yes, no] = [this.choices(node.consequent, lookup), this.choices(node.alternate, lookup)];
469
+ const [yes, no] = [this.choices(node.consequent, lookup, true), this.choices(node.alternate, lookup, true)];
461
470
  if (!yes || !no)
462
471
  return null;
463
472
  return { functions: [...yes.functions, ...no.functions], mayBeOther: yes.mayBeOther || no.mayBeOther };
464
473
  }
465
474
  if (node.type === 'LogicalExpression') {
466
- const [left, right] = [this.choices(node.left, lookup), this.choices(node.right, lookup)];
475
+ const [left, right] = [this.choices(node.left, lookup, true), this.choices(node.right, lookup, true)];
467
476
  const isFunction = left !== null && !left.mayBeOther;
468
477
  if (node.operator === '&&')
469
478
  return isFunction ? right : { functions: right?.functions ?? [], mayBeOther: true };
@@ -479,7 +488,7 @@ export class SuiteAdapter {
479
488
  // the `only` it carries.
480
489
  if (chain && chain.links.length > 0 && this.dialect.modifiers.size === 0)
481
490
  return null;
482
- const resolved = chain ? this.resolve(chain, [], lookup) : null;
491
+ const resolved = chain ? this.resolve(chain, [], lookup, held) : null;
483
492
  const isAlias = resolved?.links.every((link) => this.isAliasLink(resolved.kind, link));
484
493
  return resolved && isAlias ? { functions: [resolved], mayBeOther: false } : null;
485
494
  }
@@ -519,12 +528,16 @@ export class SuiteAdapter {
519
528
  return chainLinks.length === 0 ? looksLikeDeclaration(args) : this.testMembers.has(chainLinks[0].name);
520
529
  }
521
530
  /**
522
- * Whether a call through an imported name is worth following to the module: shaped like a test, or any call with a
523
- * title and a body through a name that reads like a test function, as `it.effect('title', fn)` on a test object that
524
- * a package extends.
531
+ * Whether a call through an imported name is worth following to the module: shaped like a test, a direct call with a
532
+ * title of any kind and a body, as `test(TITLES.fill, fn)`, or such a call through any member of a name that reads
533
+ * like a test function, as `it.effect('title', fn)` on a test object that a package extends. A name that reads like
534
+ * one and is held as a value, as in `open ? test : test.skip`, is followed too. What the name is gets decided there,
535
+ * so it doesn't depend on which call comes first.
525
536
  */
526
- worthFollowing(name, chainLinks, args) {
527
- return this.looksLikeTest(chainLinks, args) || (isTestName(name) && looksLikeDeclaration(args));
537
+ worthFollowing(name, chainLinks, args, held) {
538
+ return ((held && isTestName(name)) ||
539
+ this.looksLikeTest(chainLinks, args) ||
540
+ ((chainLinks.length === 0 || isTestName(name)) && hasDeclarationArguments(args)));
528
541
  }
529
542
  /** The framework as followed modules are read. */
530
543
  framework() {
@@ -532,7 +545,8 @@ export class SuiteAdapter {
532
545
  return {
533
546
  name: dialect.name,
534
547
  isSource: (source) => isOwnModule(dialect, source),
535
- testObjects: (program, follow) => new SuiteBindings(program, dialect, follow, true),
548
+ isMismatched: this.isMismatched,
549
+ testObjects: (program, follow) => new SuiteBindings(program, dialect, follow, this.isMismatched, true),
536
550
  };
537
551
  }
538
552
  /** Follows the import of `name` once, and reports it once when it can't be followed and `report` is set. */