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
@@ -5,7 +5,7 @@ import picomatch from 'picomatch';
5
5
  import { globSync } from 'tinyglobby';
6
6
  import { mergeDeep, settingAt, unknownText, } from "./config.js";
7
7
  import { atLeast } from "./frameworks/common.js";
8
- import { nodeTestCommands, scriptsRunBy } from "./node-scripts.js";
8
+ import { mochaArguments, nodeTestCommands, runnerCommands, scriptsRunBy, } from "./node-scripts.js";
9
9
  import { durationOf } from "./frameworks/mocha.js";
10
10
  import { VITEST_BENCHMARK_INCLUDE, VITEST_INCLUDE, VITEST_TYPECHECK_INCLUDE, vitestExclude, } from "./vitest-defaults.js";
11
11
  const PLAYWRIGHT_TEST_MATCH = '**/*.@(spec|test).?(c|m)[jt]s?(x)';
@@ -33,7 +33,13 @@ const NO_DEFAULTS = {
33
33
  tags: null,
34
34
  };
35
35
  const ASSUMED = 'the scan takes its files to be run';
36
+ /** The runners whose config a package.json script may name, which the scan then reads as one more that runs files. */
37
+ const SCRIPT_RUNNERS = new Set(['vitest', 'jest', 'playwright', 'cypress', 'webdriverio', 'mocha']);
36
38
  const NOT_FOUND = "the scan can't tell which files it runs; give patterns to scan them";
39
+ const UNNAMED = 'the scan lists the files the config runs, but not which of its browser projects run them';
40
+ const CANDIDATES = 'the scan lists candidate files from the readable top-level file settings; project membership is unknown and tests may be missing; give patterns to select other files';
41
+ /** The runners whose unknown file selection is an error in discovery, as tests may be missing; candidates may remain. */
42
+ const CANDIDATE_RUNNERS = new Set(['playwright', 'vitest']);
37
43
  function emptySettings() {
38
44
  return { kind: 'object', keys: new Map(), rest: null };
39
45
  }
@@ -119,9 +125,16 @@ export class ConfigRuns {
119
125
  jestDefaults = null;
120
126
  mochaDefaults = null;
121
127
  nodeRuns = null;
128
+ /** What the `node --test` scripts of a folder's package.json run, by the folder; null for none. */
129
+ nodeFolders = new Map();
122
130
  bunFiles = null;
123
131
  /** The Vitest configs whose projects are being found, with their names, to stop at one whose projects name itself. */
124
132
  expanding = new Map();
133
+ /** The routes the scripts of a folder's package.json give the runner, by the folder. */
134
+ scriptRoutes = new Map();
135
+ /** The projects of a route, by its config and the folder it runs from. */
136
+ routeProjects = new Map();
137
+ candidateProjects = new Map();
125
138
  constructor(configs, framework, version, findsFiles) {
126
139
  this.configs = configs;
127
140
  this.framework = framework;
@@ -137,7 +150,25 @@ export class ConfigRuns {
137
150
  const placement = this.place(file);
138
151
  return { ...placement, tags: this.configTags(placement.config) };
139
152
  }
153
+ /**
154
+ * A file the configs the runner finds by name leave out may still run through a config a package.json script names,
155
+ * as `vitest --config vitest.integration.config.ts`; when a script's config can't be read, the scan can't tell.
156
+ */
140
157
  place(file) {
158
+ const placement = this.placeByConfigs(file);
159
+ // With globs every file they match runs, so only a scan that finds its files asks scripts about an unknown one.
160
+ const unknown = placement.runs === null;
161
+ if (placement.runs || (unknown && !this.findsFiles) || !SCRIPT_RUNNERS.has(this.framework))
162
+ return placement;
163
+ const routed = this.placeByScripts(file);
164
+ // Without a config found by name, or with one the scan can't read, only a script's config that runs it says more.
165
+ if (unknown)
166
+ return routed !== null && routed !== 'unknown' ? routed : placement;
167
+ if (routed === 'unknown')
168
+ return { ...placement, runs: null, projects: null };
169
+ return routed ?? placement;
170
+ }
171
+ placeByConfigs(file) {
141
172
  if (this.framework === 'mocha')
142
173
  return this.placeMocha(file);
143
174
  if (this.framework === 'jasmine')
@@ -166,8 +197,7 @@ export class ConfigRuns {
166
197
  }
167
198
  const unknown = around.flatMap((config) => this.projectsOf(config)).find((project) => project.unknown);
168
199
  if (unknown?.unknown) {
169
- this.configs.reportUnknown(unknown.unknown.setting, unknown.unknown.key, this.findsFiles ? NOT_FOUND : ASSUMED);
170
- return { config: unknown.config, settings: unknown.settings, runs: null, projects: null };
200
+ return this.unknownPlacement(unknown, file);
171
201
  }
172
202
  const nearest = around.at(-1) ?? null;
173
203
  if (nearest === null && this.framework === 'jest') {
@@ -183,6 +213,200 @@ export class ConfigRuns {
183
213
  projects: nearest ? [] : null,
184
214
  };
185
215
  }
216
+ /** Retains candidates without claiming a project runs them when the runner constructs its projects at runtime. */
217
+ unknownPlacement(project, file) {
218
+ const { setting, key } = project.unknown;
219
+ const { config, settings } = project;
220
+ // Without globs, a setting that only names the projects leaves the files known; with them, every file runs anyway.
221
+ const known = this.findsFiles && 'known' in project ? project.known : undefined;
222
+ if (known) {
223
+ this.configs.reportUnknown(setting, key, UNNAMED);
224
+ return { config, settings, runs: known(file), projects: null };
225
+ }
226
+ // Candidates come only with the error that says tests may be missing, which needs the place the setting is written.
227
+ const candidates = this.findsFiles && setting.where ? this.candidatesOf(project) : undefined;
228
+ const effect = !this.findsFiles ? ASSUMED : candidates ? CANDIDATES : NOT_FOUND;
229
+ const level = this.findsFiles && CANDIDATE_RUNNERS.has(this.framework) ? 'error' : 'warning';
230
+ this.configs.reportUnknown(setting, key, effect, level);
231
+ return {
232
+ config,
233
+ settings,
234
+ runs: null,
235
+ projects: null,
236
+ ...(candidates ? { candidate: candidates(file) === 'test' } : {}),
237
+ };
238
+ }
239
+ /** The files readable top-level file settings select for a project the scan can't work out; undefined for none. */
240
+ candidatesOf(project) {
241
+ if ('candidates' in project)
242
+ return project.candidates;
243
+ const { config } = project;
244
+ if (this.framework !== 'playwright' || project.unknown?.key !== 'projects' || config.settings.kind !== 'object') {
245
+ return undefined;
246
+ }
247
+ let candidates = this.candidateProjects.get(config);
248
+ if (!candidates) {
249
+ candidates = this.playwrightProject(config, emptySettings(), true);
250
+ this.candidateProjects.set(config, candidates);
251
+ }
252
+ return candidates.runs ?? undefined;
253
+ }
254
+ /**
255
+ * The placement the first route that runs a file gives it, from the package.json scripts in its folder and those above
256
+ * it, nearest first; `unknown`, reported, when none runs it and one can't be read; null when none runs it.
257
+ */
258
+ placeByScripts(file) {
259
+ const unknown = [];
260
+ for (let folder = path.dirname(file);; folder = path.dirname(folder)) {
261
+ for (const route of this.routesIn(folder)) {
262
+ if ('unknown' in route) {
263
+ unknown.push(route);
264
+ continue;
265
+ }
266
+ const projects = this.projectsOfRoute(route);
267
+ const running = projects.flatMap((project) => {
268
+ const runs = project.runs?.(file);
269
+ return runs ? [{ project, runs }] : [];
270
+ });
271
+ if (running.length > 0) {
272
+ const [{ project, runs }] = running;
273
+ const config = route.config && project.config;
274
+ return { config, settings: project.settings, runs, projects: running.map((item) => item.project.about) };
275
+ }
276
+ const unknownProject = projects.find((project) => project.unknown);
277
+ if (unknownProject?.unknown) {
278
+ if (this.findsFiles && CANDIDATE_RUNNERS.has(this.framework)) {
279
+ return this.unknownPlacement(unknownProject, file);
280
+ }
281
+ this.configs.reportUnknown(unknownProject.unknown.setting, unknownProject.unknown.key, ASSUMED);
282
+ return 'unknown';
283
+ }
284
+ }
285
+ if (folder === this.configs.root)
286
+ break;
287
+ }
288
+ for (const route of unknown)
289
+ this.configs.reportFile(this.configs.relative(route.manifest), route.unknown);
290
+ return unknown.length > 0 ? 'unknown' : null;
291
+ }
292
+ /**
293
+ * The routes the scripts of the package.json in a folder give the runner: the config each command that starts it
294
+ * names, else the one the runner finds in the folder it starts in. Vitest and Cypress start in the folder the command
295
+ * names as their root, else the script's, and read a config path from there; the others read it from the script's.
296
+ */
297
+ routesIn(folder) {
298
+ let routes = this.scriptRoutes.get(folder);
299
+ if (routes)
300
+ return routes;
301
+ routes = [];
302
+ const manifest = path.join(folder, 'package.json');
303
+ let scripts = {};
304
+ try {
305
+ scripts = JSON.parse(readFileSync(manifest, 'utf8')).scripts ?? {};
306
+ }
307
+ catch {
308
+ // No package.json, or one the runner can't start from either.
309
+ }
310
+ const seen = new Set();
311
+ for (const [name, script] of Object.entries(scripts)) {
312
+ if (typeof script !== 'string')
313
+ continue;
314
+ for (const command of runnerCommands(script, this.framework)) {
315
+ const about = `The script ${name} in ${this.configs.relative(manifest)} starts the runner`;
316
+ if (command.unreadable) {
317
+ const unknown = `${about} with a config or root the scan can't read without running it, so it can't tell which files that runs; files the configs it reads leave out aren't reported as not run.`;
318
+ routes.push({ manifest, unknown });
319
+ continue;
320
+ }
321
+ if (this.framework === 'mocha') {
322
+ const route = this.mochaRoute(folder, command.config, command.args);
323
+ if (route === null)
324
+ continue;
325
+ const key = `${route.config?.file ?? ''}\0${JSON.stringify([...route.args.options, route.args.positional])}`;
326
+ if (seen.has(key))
327
+ continue;
328
+ seen.add(key);
329
+ routes.push({ config: route.config, root: folder, mocha: route.args });
330
+ continue;
331
+ }
332
+ const root = command.root === null ? folder : path.resolve(folder, command.root);
333
+ const from = this.framework === 'vitest' || this.framework === 'cypress' ? root : folder;
334
+ let config;
335
+ if (command.config === null)
336
+ config = this.defaultConfigIn(root);
337
+ else {
338
+ const target = path.resolve(from, command.config);
339
+ const stat = statSync(target, { throwIfNoEntry: false });
340
+ // The runner refuses a config that doesn't exist, so the command runs no file.
341
+ if (!stat)
342
+ continue;
343
+ config = stat.isDirectory() ? this.configs.inFolder(target) : this.configs.at(target);
344
+ if (config === null)
345
+ continue;
346
+ }
347
+ // Vitest runs with its defaults without a config; the others refuse to start, or always find one.
348
+ if (config === null && this.framework !== 'vitest')
349
+ continue;
350
+ const key = `${config?.file ?? ''}\0${root}`;
351
+ if (seen.has(key))
352
+ continue;
353
+ seen.add(key);
354
+ routes.push({ config, root });
355
+ }
356
+ }
357
+ this.scriptRoutes.set(folder, routes);
358
+ return routes;
359
+ }
360
+ /**
361
+ * The config a runner started in a folder without one named finds: there only, except that Vitest before 5.0 also
362
+ * looks in the folders above it, and Jest takes the folder's package.json when it finds no config; null for Vitest's
363
+ * defaults.
364
+ */
365
+ defaultConfigIn(folder) {
366
+ const own = this.framework === 'jest' ? this.configs.jestConfigFrom(folder) : this.configs.inFolder(folder);
367
+ if (own || this.framework !== 'vitest' || atLeast(this.version, 5, 0))
368
+ return own;
369
+ // A config above the project's root is outside what the scan reads.
370
+ const { root } = this.configs;
371
+ for (let above = path.dirname(folder); above === root || isInside(root, above); above = path.dirname(above)) {
372
+ const config = this.configs.inFolder(above);
373
+ if (config)
374
+ return config;
375
+ }
376
+ return null;
377
+ }
378
+ /**
379
+ * What Mocha started by a script reads: the config `--config` names, or the `.mocharc` file it finds from the folder
380
+ * up, with the nearest package.json's `mocha` key, and its command line. Null when it names a config that isn't
381
+ * there, which Mocha refuses.
382
+ */
383
+ mochaRoute(folder, named, words) {
384
+ const args = mochaArguments(words);
385
+ const rc = args.options.has('no-config') ? false : named === null ? undefined : path.resolve(folder, named);
386
+ if (rc && !isFileAt(rc))
387
+ return null;
388
+ const manifest = args.options.has('no-package') ? false : args.options.get('package')?.at(-1);
389
+ const config = this.configs.mochaConfig(folder, rc, manifest === undefined ? undefined : manifest && path.resolve(folder, manifest));
390
+ return { config, args };
391
+ }
392
+ /** A route's projects, as the runner started in its folder finds them; Vitest's defaults there without a config. */
393
+ projectsOfRoute(route) {
394
+ const key = `${route.config?.file ?? ''}\0${route.root}\0${JSON.stringify(route.mocha ? [...route.mocha.options, route.mocha.positional] : null)}`;
395
+ let projects = this.routeProjects.get(key);
396
+ if (!projects) {
397
+ const config = route.config ?? this.noConfig(route.root);
398
+ if (route.mocha)
399
+ projects = [this.mochaProject(config, mochaSettings(config.settings, route.mocha), route.root)];
400
+ else if (this.framework === 'vitest')
401
+ projects = this.vitestProjects(config, null, route.root);
402
+ else if (this.framework === 'cypress')
403
+ projects = this.cypressProjects(config, route.root);
404
+ else
405
+ projects = this.projectsOf(config);
406
+ this.routeProjects.set(key, projects);
407
+ }
408
+ return projects;
409
+ }
186
410
  /**
187
411
  * Playwright's config `tag`, from 1.57, which it gives every test before its own tags; null when the scan can't work
188
412
  * it out. That is reported where the config writes `tag`; a config whose settings come from code the scan can't
@@ -246,8 +470,7 @@ export class ConfigRuns {
246
470
  * takes, also in folders below with `recursive`, less those `ignore` matches; and the `file` entries, loaded first.
247
471
  * With globs, every file they match, less `ignore`. A timeout may be written as `'2s'`.
248
472
  */
249
- mochaProject(config, settings) {
250
- const folder = this.configs.root;
473
+ mochaProject(config, settings, folder = this.configs.root) {
251
474
  const lists = {};
252
475
  for (const [key, fallback] of [
253
476
  ['spec', ['./test']],
@@ -400,8 +623,7 @@ export class ConfigRuns {
400
623
  * dot files included, and those in `node_modules` unless a `specPattern` names it; component testing also leaves out
401
624
  * the files e2e's `specPattern` matches. `cypress run` matches each pattern against the whole path, as globby does.
402
625
  */
403
- cypressProjects(config) {
404
- const folder = path.dirname(config.file);
626
+ cypressProjects(config, folder = path.dirname(config.file)) {
405
627
  const types = [
406
628
  ['e2e', ['cypress/e2e/**/*.cy.{js,jsx,ts,tsx}'], ['*.hot-update.js']],
407
629
  ];
@@ -561,27 +783,50 @@ export class ConfigRuns {
561
783
  return { config: null, settings: null, runs: runs ? 'test' : false, projects: null };
562
784
  }
563
785
  /**
564
- * The files `node --test` runs from the root, outside dot folders and `node_modules`: those the arguments of the
565
- * `test` script and the scripts it runs give, or the first script that runs it, each a glob or a path, and from
566
- * Node.js 26.8 a folder for the default patterns inside it; without arguments, the default patterns. They take
567
- * TypeScript files too from Node.js 22.18, which strips types by default.
786
+ * The files `node --test` runs, outside dot folders and `node_modules`: from the root, and from each package below it
787
+ * whose scripts run it, as a monorepo's packages run their own. In each folder, those the arguments of the `test`
788
+ * script and the scripts it runs give, or the first script that runs it, each a glob or a path, and from Node.js 26.8
789
+ * a folder for the default patterns inside it; without arguments, the default patterns. The root runs the default
790
+ * patterns also without such a script. They take TypeScript files too from Node.js 22.18, which strips types by
791
+ * default.
568
792
  */
569
793
  nodeFiles() {
794
+ const { root } = this.configs;
795
+ const fromRoot = this.nodeFolderFiles(root) ?? this.nodeGlobs(root, [[]]);
796
+ return (relative) => {
797
+ const file = path.join(root, relative);
798
+ let runs = fromRoot(relative);
799
+ for (let folder = path.dirname(file); !runs && folder !== root; folder = path.dirname(folder)) {
800
+ runs = this.nodeFolderFiles(folder)?.(posix(path.relative(folder, file))) ?? false;
801
+ }
802
+ return runs && !relative.split('/').includes('node_modules');
803
+ };
804
+ }
805
+ /** The files the `node --test` commands of a folder's package.json scripts run from it; null without such a command. */
806
+ nodeFolderFiles(folder) {
807
+ let runs = this.nodeFolders.get(folder);
808
+ if (runs === undefined) {
809
+ const commands = nodeTestArguments(path.join(folder, 'package.json'));
810
+ runs = commands.length > 0 ? this.nodeGlobs(folder, commands) : null;
811
+ this.nodeFolders.set(folder, runs);
812
+ }
813
+ return runs;
814
+ }
815
+ /** The files node:test commands started in a folder run, each command as the files it gives, from the folder. */
816
+ nodeGlobs(folder, commands) {
570
817
  const extensions = stripsTypes(this.version) ? 'cjs,mjs,js,cts,mts,ts' : 'cjs,mjs,js';
571
818
  const defaults = ['**/*.test', '**/*-test', '**/*_test', '**/test-*', '**/test', '**/test/**/*'].map((glob) => `${glob}.{${extensions}}`);
572
819
  const searchesFolders = atLeast(this.version, 26, 8);
573
- const commands = nodeTestArguments(path.join(this.configs.root, 'package.json'));
574
820
  // Each command runs the files it gives, or without any, those the default patterns match.
575
- const globs = (commands.length > 0 ? commands : [[]]).flatMap((files) => files.length === 0
821
+ const globs = commands.flatMap((files) => files.length === 0
576
822
  ? defaults
577
823
  : files.flatMap((argument) => {
578
- const folder = path.resolve(this.configs.root, argument);
579
- if (!searchesFolders || !existsSync(folder) || !statSync(folder).isDirectory())
824
+ const target = path.resolve(folder, argument);
825
+ if (!searchesFolders || !existsSync(target) || !statSync(target).isDirectory())
580
826
  return [argument];
581
827
  return defaults.map((glob) => `${argument.replace(/\/+$/, '')}/${glob}`);
582
828
  }));
583
- const isMatch = picomatch(globs.map((glob) => path.posix.normalize(posix(glob))));
584
- return (relative) => isMatch(relative) && !relative.split('/').includes('node_modules');
829
+ return picomatch(globs.map((glob) => path.posix.normalize(posix(glob))));
585
830
  }
586
831
  /** WebdriverIO runs the files of the config in the root; without one, it runs nothing, unless it is given files. */
587
832
  placeWebdriverIO(file) {
@@ -740,7 +985,7 @@ export class ConfigRuns {
740
985
  return unknownAt(setting);
741
986
  }
742
987
  /** A project whose files can't be worked out, because of `setting` under `key`: it may run any file. */
743
- unknownProject(config, setting, key) {
988
+ unknownProject(config, setting, key, files = {}) {
744
989
  const about = {
745
990
  name: '',
746
991
  testDir: path.dirname(config.file),
@@ -754,7 +999,7 @@ export class ConfigRuns {
754
999
  runsByDefault: true,
755
1000
  defaults: NO_DEFAULTS,
756
1001
  };
757
- return { config, settings: setting, about, runs: null, unknown: { setting, key } };
1002
+ return { config, settings: setting, about, runs: null, unknown: { setting, key }, ...files };
758
1003
  }
759
1004
  playwrightProjects(config) {
760
1005
  const list = settingAt(config.settings, ['projects']);
@@ -971,9 +1216,9 @@ export class ConfigRuns {
971
1216
  return rules;
972
1217
  }
973
1218
  /** A config for the defaults of a runner started where no config is found. */
974
- noConfig() {
975
- const file = path.join(this.configs.root, 'package.json');
976
- return { file, record: { relativeFilePath: 'package.json', extends: [] }, settings: emptySettings() };
1219
+ noConfig(folder = this.configs.root) {
1220
+ const file = path.join(folder, 'package.json');
1221
+ return { file, record: { relativeFilePath: this.configs.relative(file), extends: [] }, settings: emptySettings() };
977
1222
  }
978
1223
  /**
979
1224
  * Jest's projects: the config itself, or the entries of its `projects`. A path or glob there names a folder, whose
@@ -1162,22 +1407,27 @@ export class ConfigRuns {
1162
1407
  return { settings, refusal: null };
1163
1408
  return { settings: { ...settings, keys: new Map([...base.keys, ...settings.keys]) }, refusal: null };
1164
1409
  }
1165
- vitestProjects(config, container = null) {
1166
- const folder = path.dirname(config.file);
1410
+ vitestProjects(config, container = null, folder = path.dirname(config.file)) {
1167
1411
  const list = settingAt(config.settings, ['test', 'projects']);
1168
1412
  const isVitest3 = this.version !== null && this.version[0] < 4;
1169
1413
  const workspace = isVitest3 ? settingAt(config.settings, ['test', 'workspace']) : null;
1170
- if (workspace)
1171
- return [this.unknownProject(config, unknownAt(workspace), 'test.workspace')];
1172
- if (isVitest3 && VITEST_WORKSPACES.some((name) => existsSync(path.join(folder, name)))) {
1414
+ if (workspace && !isUnset(workspace)) {
1415
+ // A list has no place of its own, so the scan, which doesn't read the list either, reports it on `test`; a
1416
+ // merged `test` has none either.
1417
+ const test = settingAt(config.settings, ['test']);
1418
+ const unknown = workspace.kind === 'unknown' ? workspace : { kind: 'unknown', where: test.where ?? null };
1419
+ return [this.unknownProject(config, unknown, 'test.workspace', this.vitestCandidates(config, folder))];
1420
+ }
1421
+ if (isVitest3 && VITEST_WORKSPACES.some((name) => existsSync(path.join(path.dirname(config.file), name)))) {
1173
1422
  // Vitest 3 takes its projects from a workspace file, which the scan doesn't read.
1174
1423
  return [this.unknownProject(config, { kind: 'unknown', where: null }, 'test.projects')];
1175
1424
  }
1176
1425
  const name = container ?? vitestName(config.settings, '', null);
1177
1426
  if (list === null)
1178
1427
  return this.vitestProject(config, config.settings, folder, null, name);
1179
- if (list.kind !== 'list')
1180
- return [this.unknownProject(config, unknownAt(list), 'test.projects')];
1428
+ if (list.kind !== 'list') {
1429
+ return [this.unknownProject(config, unknownAt(list), 'test.projects', this.vitestCandidates(config, folder))];
1430
+ }
1181
1431
  this.expanding.set(config, name);
1182
1432
  const globs = [];
1183
1433
  // Vitest names an inline project without a name after its place among the entries that aren't paths.
@@ -1209,6 +1459,14 @@ export class ConfigRuns {
1209
1459
  this.expanding.delete(config);
1210
1460
  return projects;
1211
1461
  }
1462
+ /**
1463
+ * The files a config's own file settings select, as candidates for projects the scan can't list, which mostly narrow
1464
+ * them; none when those settings can't be read either.
1465
+ */
1466
+ vitestCandidates(config, folder) {
1467
+ const own = this.vitestFiles(config, config.settings, folder, null, '', false);
1468
+ return own.runs ? { candidates: own.runs } : {};
1469
+ }
1212
1470
  /**
1213
1471
  * A project written in `test.projects`, which inherits the root config as each version of Vitest decides, named
1214
1472
  * after `index` when it has no name of its own.
@@ -1216,7 +1474,7 @@ export class ConfigRuns {
1216
1474
  vitestEntry(config, entry, folder, index, container) {
1217
1475
  if (entry.kind !== 'object') {
1218
1476
  // A function or a promise, read by running the config, or a setting of the wrong type.
1219
- return [this.unknownProject(config, unknownAt(entry), 'test.projects')];
1477
+ return [this.unknownProject(config, unknownAt(entry), 'test.projects', this.vitestCandidates(config, folder))];
1220
1478
  }
1221
1479
  const extended = settingAt(entry, ['extends']);
1222
1480
  let base = emptySettings();
@@ -1283,8 +1541,9 @@ export class ConfigRuns {
1283
1541
  if (project.unknown)
1284
1542
  return [project];
1285
1543
  const enabled = settingAt(settings, ['test', 'browser', 'enabled']);
1286
- if (enabled?.kind === 'unknown')
1287
- return [this.unknownProject(config, enabled, 'test.browser.enabled')];
1544
+ if (enabled?.kind === 'unknown') {
1545
+ return [this.unknownProject(config, enabled, 'test.browser.enabled', { known: project.runs })];
1546
+ }
1288
1547
  if (!(enabled?.kind === 'value' && enabled.value === true))
1289
1548
  return [project];
1290
1549
  const instances = settingAt(settings, ['test', 'browser', 'instances']);
@@ -1292,8 +1551,9 @@ export class ConfigRuns {
1292
1551
  const browsers = items.map((item) => [settingAt(item, ['browser']), settingAt(item, ['name'])]);
1293
1552
  const unknown = browsers.flat().find((setting) => setting?.kind === 'unknown') ??
1294
1553
  (instances?.kind === 'unknown' ? instances : null);
1295
- if (unknown)
1296
- return [this.unknownProject(config, unknownAt(unknown), 'test.browser.instances')];
1554
+ if (unknown) {
1555
+ return [this.unknownProject(config, unknownAt(unknown), 'test.browser.instances', { known: project.runs })];
1556
+ }
1297
1557
  return browsers.map(([browser, name]) => {
1298
1558
  const kind = browser?.kind === 'value' ? String(browser.value) : '';
1299
1559
  const own = name?.kind === 'value' && typeof name.value === 'string' ? name.value : null;
@@ -1336,11 +1596,19 @@ export class ConfigRuns {
1336
1596
  const matchers = [];
1337
1597
  for (const [key, fallback, isExclude] of lists) {
1338
1598
  const setting = settingAt(settings, key.split('.'));
1339
- const found = setting === null || isUnset(setting) ? fallback : patterns(setting, false);
1599
+ let found = setting === null || isUnset(setting) ? fallback : patterns(setting, false);
1600
+ // A list of paths left out only takes files away, so the entries the scan can read are still a good guess.
1601
+ if (!Array.isArray(found) && isExclude) {
1602
+ this.configs.reportUnknown(found, key, 'the scan may list test files that Vitest leaves out');
1603
+ found = strings(setting);
1604
+ }
1340
1605
  if (!Array.isArray(found))
1341
1606
  return this.unknownProject(config, found, key);
1342
- // tinyglobby, which Vitest finds files with, takes an absolute pattern as one in the folder it searches.
1343
- const relative = found.map((glob) => path.isAbsolute(glob) ? posix(path.relative(base, glob)) : glob);
1607
+ // tinyglobby, which Vitest finds files with, takes an absolute pattern as one in the folder it searches; one that
1608
+ // names that folder itself matches no file, and picomatch refuses the empty pattern it becomes.
1609
+ const relative = found
1610
+ .map((glob) => (path.isAbsolute(glob) ? posix(path.relative(base, glob)) : glob))
1611
+ .filter((glob) => glob !== '');
1344
1612
  const isMatch = picomatch(relative, { dot: true });
1345
1613
  // An excluded folder leaves out everything in it, as the glob doesn't enter it.
1346
1614
  matchers.push(isExclude ? (file) => folders(file).some((part) => isMatch(part) || isMatch(`${part}/`)) : isMatch);
@@ -1825,6 +2093,33 @@ function jestGlobs(globs) {
1825
2093
  return matchers.every(({ negated }) => negated) ? kept !== false : kept === true;
1826
2094
  };
1827
2095
  }
2096
+ /**
2097
+ * A config's settings with a Mocha command line's over them: an option given there replaces the config's, and the
2098
+ * specs it gives as positional arguments run along with the `spec` that remains, as Mocha joins them.
2099
+ */
2100
+ function mochaSettings(settings, args) {
2101
+ if (settings.kind !== 'object')
2102
+ return settings;
2103
+ const list = (values) => values.map((value) => ({ kind: 'value', value }));
2104
+ const keys = new Map(settings.keys);
2105
+ for (const name of ['spec', 'extension', 'ignore', 'file']) {
2106
+ const values = args.options.get(name);
2107
+ if (values)
2108
+ keys.set(name, { kind: 'list', items: list(values) });
2109
+ }
2110
+ const ui = args.options.get('ui')?.at(-1);
2111
+ if (ui !== undefined)
2112
+ keys.set('ui', { kind: 'value', value: ui });
2113
+ if (args.options.has('recursive'))
2114
+ keys.set('recursive', { kind: 'value', value: true });
2115
+ const merged = { ...settings, keys };
2116
+ if (args.positional.length === 0)
2117
+ return merged;
2118
+ const spec = settingAt(merged, ['spec']);
2119
+ const rest = spec === null || isUnset(spec) ? [] : spec.kind === 'list' ? spec.items : [spec];
2120
+ keys.set('spec', { kind: 'list', items: [...list(args.positional), ...rest] });
2121
+ return merged;
2122
+ }
1828
2123
  /** Whether a Jest setting is given: `null` and `undefined` leave Jest's default, as a `testMatch: null` beside `testRegex`. */
1829
2124
  function isJestSet(setting) {
1830
2125
  return setting !== null && !isUnset(setting) && !(setting.kind === 'value' && setting.value === null);
@@ -1841,8 +2136,9 @@ function isFileAt(file) {
1841
2136
  * declares tests in a way the scan doesn't read, which is reported on the config, and the file is read as BDD.
1842
2137
  */
1843
2138
  export function mochaInterface(placement, configs) {
1844
- const { config } = placement;
1845
- const ui = config ? settingAt(config.settings, ['ui']) : null;
2139
+ const { config, settings } = placement;
2140
+ // A script's command line sets `ui` in the placement's settings, over its config's.
2141
+ const ui = settings ? settingAt(settings, ['ui']) : null;
1846
2142
  if (ui === null || isUnset(ui))
1847
2143
  return 'bdd';
1848
2144
  if (ui.kind !== 'value') {
@@ -1852,7 +2148,9 @@ export function mochaInterface(placement, configs) {
1852
2148
  if (ui.value === 'bdd' || ui.value === 'tdd')
1853
2149
  return ui.value;
1854
2150
  const message = `The config's ui '${String(ui.value)}' is an interface the scan doesn't read, so it reads the tests as Mocha's default, BDD.`;
1855
- configs.reportConfig(config, message);
2151
+ // A command line without a config file has no config to report it on.
2152
+ if (config)
2153
+ configs.reportConfig(config, message);
1856
2154
  return 'bdd';
1857
2155
  }
1858
2156
  /**
@@ -1869,8 +2167,8 @@ function isSuiteName(settings, item) {
1869
2167
  export function webdriverioInterface(placement, configs) {
1870
2168
  if (placement.config === null || webdriverioFramework(placement, null) === 'jasmine')
1871
2169
  return 'bdd';
1872
- const options = settingAt(placement.config.settings, ['mochaOpts']);
1873
- return mochaInterface({ ...placement, config: { ...placement.config, settings: options ?? emptySettings() } }, configs);
2170
+ const options = settingAt(placement.config.settings, ['mochaOpts']) ?? emptySettings();
2171
+ return mochaInterface({ ...placement, settings: options, config: { ...placement.config, settings: options } }, configs);
1874
2172
  }
1875
2173
  /**
1876
2174
  * The framework a WebdriverIO config runs the specs with: Mocha by default, or Jasmine. Cucumber runs feature files,
package/dist/config.d.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  import type { ModuleReader, Span } from './model.ts';
2
2
  import { type ParsedFile } from './parse.ts';
3
- import type { ConfigRecord, Diagnostic, Framework, ProjectRecord } from './types.ts';
3
+ import type { ConfigRecord, Diagnostic, DiagnosticLevel, Framework, ProjectRecord } from './types.ts';
4
4
  import { Values } from './values.ts';
5
5
  /** A file a config is read from: the config itself, or a module it imports settings from, at `file`. */
6
6
  interface ConfigFrame {
@@ -67,7 +67,7 @@ export declare class Configs {
67
67
  private readonly readerFor;
68
68
  private readonly inFolders;
69
69
  private readonly files;
70
- private mocha;
70
+ private readonly mocha;
71
71
  private readonly used;
72
72
  private readonly reported;
73
73
  private readonly version;
@@ -86,7 +86,7 @@ export declare class Configs {
86
86
  /** The configs that scanned files use, sorted by path, with the projects `projectsOf` gives each. */
87
87
  records(projectsOf: (config: ConfigFile) => ProjectRecord[] | null): ConfigRecord[];
88
88
  /** Reports a setting the scan reads but can't work out, once; `key` names it, and `effect` says what the scan does. */
89
- reportUnknown(setting: Unknown, key: string, effect: string): void;
89
+ reportUnknown(setting: Unknown, key: string, effect: string, level?: DiagnosticLevel): void;
90
90
  /**
91
91
  * Reports, once, a setting the runner mishandles, where it is written, or on its config when the scan built it from
92
92
  * several places; `key` names it.
@@ -95,11 +95,14 @@ export declare class Configs {
95
95
  private reportAt;
96
96
  /** Reports, once, a config the runner reads in a way the scan doesn't follow, or refuses. */
97
97
  reportConfig(config: ConfigFile, message: string): void;
98
+ /** Reports, once, a file the scan reads runner settings from, such as a package.json script, and can't follow. */
99
+ reportFile(relativeFilePath: string, message: string): void;
98
100
  /**
99
- * The config Mocha runs with, started in the root: the first `.mocharc` file from the root up, joined with the `mocha`
100
- * key of the nearest package.json. Null without either.
101
+ * The config Mocha runs with, started in a folder, the root by default: the first `.mocharc` file from there up, or
102
+ * the file `--config` names, joined with the `mocha` key of the nearest package.json, or of the one `--package`
103
+ * names. `false` stands for `--no-config` or `--no-package`, which leave that part out. Null without either.
101
104
  */
102
- mochaConfig(): ConfigFile | null;
105
+ mochaConfig(folder?: string, rcFile?: string | false, manifestFile?: string | false): ConfigFile | null;
103
106
  /**
104
107
  * The config the jasmine command reads, started in the root: the first of `spec/support/jasmine.mjs` (from Jasmine
105
108
  * 5), `.json` and `.js` there; null without one.
@@ -114,6 +117,11 @@ export declare class Configs {
114
117
  inFolder(folder: string): ConfigFile | null;
115
118
  /** Config file names, in the order the runner looks for them; Jest reads `.cts` from 30.0 and `.mts` from 30.4. */
116
119
  private names;
120
+ /**
121
+ * The config Jest started in a folder with a package.json reads: as `jestConfigIn`, with the package.json itself,
122
+ * and so Jest's defaults from that folder, when it has no `jest` key.
123
+ */
124
+ jestConfigFrom(folder: string): ConfigFile | null;
117
125
  /**
118
126
  * The config Jest takes in a folder: a `jest.config` file, else the `package.json` with a `jest` key, which from 30.0
119
127
  * may be the path to the config. A `package.json` without one is a config only in the root, as Jest started there