test-inventory 0.10.4 → 0.11.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +116 -0
- package/README.md +6 -4
- package/dist/cli.d.ts +7 -4
- package/dist/cli.js +18 -6
- package/dist/config-runs.d.ts +30 -4
- package/dist/config-runs.js +193 -38
- package/dist/config.d.ts +7 -6
- package/dist/config.js +260 -26
- package/dist/dependency-hash.d.ts +9 -1
- package/dist/dependency-hash.js +128 -13
- package/dist/diff.js +7 -2
- package/dist/extract.js +75 -17
- package/dist/files.js +2 -1
- package/dist/filter.js +1 -0
- package/dist/framework-version.d.ts +6 -0
- package/dist/framework-version.js +37 -9
- package/dist/frameworks/bindings.d.ts +9 -0
- package/dist/frameworks/bindings.js +28 -5
- package/dist/frameworks/bun.js +2 -2
- package/dist/frameworks/common.d.ts +12 -3
- package/dist/frameworks/common.js +30 -12
- package/dist/frameworks/jasmine.js +11 -3
- package/dist/frameworks/jest.js +11 -7
- package/dist/frameworks/mocha.js +3 -3
- package/dist/frameworks/node.js +6 -4
- package/dist/frameworks/playwright.d.ts +11 -3
- package/dist/frameworks/playwright.js +101 -32
- package/dist/frameworks/test-functions.d.ts +13 -7
- package/dist/frameworks/test-functions.js +41 -27
- package/dist/frameworks/vitest.js +11 -6
- package/dist/imported-values.js +12 -3
- package/dist/index.d.ts +2 -0
- package/dist/index.js +1 -0
- package/dist/model.d.ts +4 -1
- package/dist/node-scripts.d.ts +15 -1
- package/dist/node-scripts.js +140 -13
- package/dist/parse.d.ts +3 -0
- package/dist/parse.js +33 -0
- package/dist/records.js +7 -4
- package/dist/resolve.d.ts +3 -1
- package/dist/resolve.js +48 -15
- package/dist/run-commands.d.ts +20 -0
- package/dist/run-commands.js +107 -0
- package/dist/scan.js +15 -5
- package/dist/types.d.ts +9 -1
- package/dist/values.d.ts +25 -4
- package/dist/values.js +131 -22
- package/package.json +15 -7
- package/schema/diff-v1.json +12 -1
- package/schema/v1.json +9 -1
package/dist/config-runs.js
CHANGED
|
@@ -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, runnerCommands, 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)';
|
|
@@ -34,8 +34,12 @@ const NO_DEFAULTS = {
|
|
|
34
34
|
};
|
|
35
35
|
const ASSUMED = 'the scan takes its files to be run';
|
|
36
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']);
|
|
37
|
+
const SCRIPT_RUNNERS = new Set(['vitest', 'jest', 'playwright', 'cypress', 'webdriverio', 'mocha']);
|
|
38
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']);
|
|
39
43
|
function emptySettings() {
|
|
40
44
|
return { kind: 'object', keys: new Map(), rest: null };
|
|
41
45
|
}
|
|
@@ -121,6 +125,8 @@ export class ConfigRuns {
|
|
|
121
125
|
jestDefaults = null;
|
|
122
126
|
mochaDefaults = null;
|
|
123
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();
|
|
124
130
|
bunFiles = null;
|
|
125
131
|
/** The Vitest configs whose projects are being found, with their names, to stop at one whose projects name itself. */
|
|
126
132
|
expanding = new Map();
|
|
@@ -128,6 +134,7 @@ export class ConfigRuns {
|
|
|
128
134
|
scriptRoutes = new Map();
|
|
129
135
|
/** The projects of a route, by its config and the folder it runs from. */
|
|
130
136
|
routeProjects = new Map();
|
|
137
|
+
candidateProjects = new Map();
|
|
131
138
|
constructor(configs, framework, version, findsFiles) {
|
|
132
139
|
this.configs = configs;
|
|
133
140
|
this.framework = framework;
|
|
@@ -149,9 +156,14 @@ export class ConfigRuns {
|
|
|
149
156
|
*/
|
|
150
157
|
place(file) {
|
|
151
158
|
const placement = this.placeByConfigs(file);
|
|
152
|
-
|
|
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))
|
|
153
162
|
return placement;
|
|
154
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;
|
|
155
167
|
if (routed === 'unknown')
|
|
156
168
|
return { ...placement, runs: null, projects: null };
|
|
157
169
|
return routed ?? placement;
|
|
@@ -185,8 +197,7 @@ export class ConfigRuns {
|
|
|
185
197
|
}
|
|
186
198
|
const unknown = around.flatMap((config) => this.projectsOf(config)).find((project) => project.unknown);
|
|
187
199
|
if (unknown?.unknown) {
|
|
188
|
-
this.
|
|
189
|
-
return { config: unknown.config, settings: unknown.settings, runs: null, projects: null };
|
|
200
|
+
return this.unknownPlacement(unknown, file);
|
|
190
201
|
}
|
|
191
202
|
const nearest = around.at(-1) ?? null;
|
|
192
203
|
if (nearest === null && this.framework === 'jest') {
|
|
@@ -202,6 +213,44 @@ export class ConfigRuns {
|
|
|
202
213
|
projects: nearest ? [] : null,
|
|
203
214
|
};
|
|
204
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
|
+
}
|
|
205
254
|
/**
|
|
206
255
|
* The placement the first route that runs a file gives it, from the package.json scripts in its folder and those above
|
|
207
256
|
* it, nearest first; `unknown`, reported, when none runs it and one can't be read; null when none runs it.
|
|
@@ -226,6 +275,9 @@ export class ConfigRuns {
|
|
|
226
275
|
}
|
|
227
276
|
const unknownProject = projects.find((project) => project.unknown);
|
|
228
277
|
if (unknownProject?.unknown) {
|
|
278
|
+
if (this.findsFiles && CANDIDATE_RUNNERS.has(this.framework)) {
|
|
279
|
+
return this.unknownPlacement(unknownProject, file);
|
|
280
|
+
}
|
|
229
281
|
this.configs.reportUnknown(unknownProject.unknown.setting, unknownProject.unknown.key, ASSUMED);
|
|
230
282
|
return 'unknown';
|
|
231
283
|
}
|
|
@@ -266,6 +318,17 @@ export class ConfigRuns {
|
|
|
266
318
|
routes.push({ manifest, unknown });
|
|
267
319
|
continue;
|
|
268
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
|
+
}
|
|
269
332
|
const root = command.root === null ? folder : path.resolve(folder, command.root);
|
|
270
333
|
const from = this.framework === 'vitest' || this.framework === 'cypress' ? root : folder;
|
|
271
334
|
let config;
|
|
@@ -312,13 +375,29 @@ export class ConfigRuns {
|
|
|
312
375
|
}
|
|
313
376
|
return null;
|
|
314
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
|
+
}
|
|
315
392
|
/** A route's projects, as the runner started in its folder finds them; Vitest's defaults there without a config. */
|
|
316
393
|
projectsOfRoute(route) {
|
|
317
|
-
const key = `${route.config?.file ?? ''}\0${route.root}`;
|
|
394
|
+
const key = `${route.config?.file ?? ''}\0${route.root}\0${JSON.stringify(route.mocha ? [...route.mocha.options, route.mocha.positional] : null)}`;
|
|
318
395
|
let projects = this.routeProjects.get(key);
|
|
319
396
|
if (!projects) {
|
|
320
397
|
const config = route.config ?? this.noConfig(route.root);
|
|
321
|
-
if (
|
|
398
|
+
if (route.mocha)
|
|
399
|
+
projects = [this.mochaProject(config, mochaSettings(config.settings, route.mocha), route.root)];
|
|
400
|
+
else if (this.framework === 'vitest')
|
|
322
401
|
projects = this.vitestProjects(config, null, route.root);
|
|
323
402
|
else if (this.framework === 'cypress')
|
|
324
403
|
projects = this.cypressProjects(config, route.root);
|
|
@@ -391,8 +470,7 @@ export class ConfigRuns {
|
|
|
391
470
|
* takes, also in folders below with `recursive`, less those `ignore` matches; and the `file` entries, loaded first.
|
|
392
471
|
* With globs, every file they match, less `ignore`. A timeout may be written as `'2s'`.
|
|
393
472
|
*/
|
|
394
|
-
mochaProject(config, settings) {
|
|
395
|
-
const folder = this.configs.root;
|
|
473
|
+
mochaProject(config, settings, folder = this.configs.root) {
|
|
396
474
|
const lists = {};
|
|
397
475
|
for (const [key, fallback] of [
|
|
398
476
|
['spec', ['./test']],
|
|
@@ -705,27 +783,50 @@ export class ConfigRuns {
|
|
|
705
783
|
return { config: null, settings: null, runs: runs ? 'test' : false, projects: null };
|
|
706
784
|
}
|
|
707
785
|
/**
|
|
708
|
-
* The files `node --test` runs
|
|
709
|
-
*
|
|
710
|
-
*
|
|
711
|
-
*
|
|
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.
|
|
712
792
|
*/
|
|
713
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) {
|
|
714
817
|
const extensions = stripsTypes(this.version) ? 'cjs,mjs,js,cts,mts,ts' : 'cjs,mjs,js';
|
|
715
818
|
const defaults = ['**/*.test', '**/*-test', '**/*_test', '**/test-*', '**/test', '**/test/**/*'].map((glob) => `${glob}.{${extensions}}`);
|
|
716
819
|
const searchesFolders = atLeast(this.version, 26, 8);
|
|
717
|
-
const commands = nodeTestArguments(path.join(this.configs.root, 'package.json'));
|
|
718
820
|
// Each command runs the files it gives, or without any, those the default patterns match.
|
|
719
|
-
const globs =
|
|
821
|
+
const globs = commands.flatMap((files) => files.length === 0
|
|
720
822
|
? defaults
|
|
721
823
|
: files.flatMap((argument) => {
|
|
722
|
-
const
|
|
723
|
-
if (!searchesFolders || !existsSync(
|
|
824
|
+
const target = path.resolve(folder, argument);
|
|
825
|
+
if (!searchesFolders || !existsSync(target) || !statSync(target).isDirectory())
|
|
724
826
|
return [argument];
|
|
725
827
|
return defaults.map((glob) => `${argument.replace(/\/+$/, '')}/${glob}`);
|
|
726
828
|
}));
|
|
727
|
-
|
|
728
|
-
return (relative) => isMatch(relative) && !relative.split('/').includes('node_modules');
|
|
829
|
+
return picomatch(globs.map((glob) => path.posix.normalize(posix(glob))));
|
|
729
830
|
}
|
|
730
831
|
/** WebdriverIO runs the files of the config in the root; without one, it runs nothing, unless it is given files. */
|
|
731
832
|
placeWebdriverIO(file) {
|
|
@@ -884,7 +985,7 @@ export class ConfigRuns {
|
|
|
884
985
|
return unknownAt(setting);
|
|
885
986
|
}
|
|
886
987
|
/** A project whose files can't be worked out, because of `setting` under `key`: it may run any file. */
|
|
887
|
-
unknownProject(config, setting, key) {
|
|
988
|
+
unknownProject(config, setting, key, files = {}) {
|
|
888
989
|
const about = {
|
|
889
990
|
name: '',
|
|
890
991
|
testDir: path.dirname(config.file),
|
|
@@ -898,7 +999,7 @@ export class ConfigRuns {
|
|
|
898
999
|
runsByDefault: true,
|
|
899
1000
|
defaults: NO_DEFAULTS,
|
|
900
1001
|
};
|
|
901
|
-
return { config, settings: setting, about, runs: null, unknown: { setting, key } };
|
|
1002
|
+
return { config, settings: setting, about, runs: null, unknown: { setting, key }, ...files };
|
|
902
1003
|
}
|
|
903
1004
|
playwrightProjects(config) {
|
|
904
1005
|
const list = settingAt(config.settings, ['projects']);
|
|
@@ -1310,8 +1411,13 @@ export class ConfigRuns {
|
|
|
1310
1411
|
const list = settingAt(config.settings, ['test', 'projects']);
|
|
1311
1412
|
const isVitest3 = this.version !== null && this.version[0] < 4;
|
|
1312
1413
|
const workspace = isVitest3 ? settingAt(config.settings, ['test', 'workspace']) : null;
|
|
1313
|
-
if (workspace)
|
|
1314
|
-
|
|
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
|
+
}
|
|
1315
1421
|
if (isVitest3 && VITEST_WORKSPACES.some((name) => existsSync(path.join(path.dirname(config.file), name)))) {
|
|
1316
1422
|
// Vitest 3 takes its projects from a workspace file, which the scan doesn't read.
|
|
1317
1423
|
return [this.unknownProject(config, { kind: 'unknown', where: null }, 'test.projects')];
|
|
@@ -1319,8 +1425,9 @@ export class ConfigRuns {
|
|
|
1319
1425
|
const name = container ?? vitestName(config.settings, '', null);
|
|
1320
1426
|
if (list === null)
|
|
1321
1427
|
return this.vitestProject(config, config.settings, folder, null, name);
|
|
1322
|
-
if (list.kind !== 'list')
|
|
1323
|
-
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
|
+
}
|
|
1324
1431
|
this.expanding.set(config, name);
|
|
1325
1432
|
const globs = [];
|
|
1326
1433
|
// Vitest names an inline project without a name after its place among the entries that aren't paths.
|
|
@@ -1352,6 +1459,14 @@ export class ConfigRuns {
|
|
|
1352
1459
|
this.expanding.delete(config);
|
|
1353
1460
|
return projects;
|
|
1354
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
|
+
}
|
|
1355
1470
|
/**
|
|
1356
1471
|
* A project written in `test.projects`, which inherits the root config as each version of Vitest decides, named
|
|
1357
1472
|
* after `index` when it has no name of its own.
|
|
@@ -1359,7 +1474,7 @@ export class ConfigRuns {
|
|
|
1359
1474
|
vitestEntry(config, entry, folder, index, container) {
|
|
1360
1475
|
if (entry.kind !== 'object') {
|
|
1361
1476
|
// A function or a promise, read by running the config, or a setting of the wrong type.
|
|
1362
|
-
return [this.unknownProject(config, unknownAt(entry), 'test.projects')];
|
|
1477
|
+
return [this.unknownProject(config, unknownAt(entry), 'test.projects', this.vitestCandidates(config, folder))];
|
|
1363
1478
|
}
|
|
1364
1479
|
const extended = settingAt(entry, ['extends']);
|
|
1365
1480
|
let base = emptySettings();
|
|
@@ -1426,8 +1541,9 @@ export class ConfigRuns {
|
|
|
1426
1541
|
if (project.unknown)
|
|
1427
1542
|
return [project];
|
|
1428
1543
|
const enabled = settingAt(settings, ['test', 'browser', 'enabled']);
|
|
1429
|
-
if (enabled?.kind === 'unknown')
|
|
1430
|
-
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
|
+
}
|
|
1431
1547
|
if (!(enabled?.kind === 'value' && enabled.value === true))
|
|
1432
1548
|
return [project];
|
|
1433
1549
|
const instances = settingAt(settings, ['test', 'browser', 'instances']);
|
|
@@ -1435,8 +1551,9 @@ export class ConfigRuns {
|
|
|
1435
1551
|
const browsers = items.map((item) => [settingAt(item, ['browser']), settingAt(item, ['name'])]);
|
|
1436
1552
|
const unknown = browsers.flat().find((setting) => setting?.kind === 'unknown') ??
|
|
1437
1553
|
(instances?.kind === 'unknown' ? instances : null);
|
|
1438
|
-
if (unknown)
|
|
1439
|
-
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
|
+
}
|
|
1440
1557
|
return browsers.map(([browser, name]) => {
|
|
1441
1558
|
const kind = browser?.kind === 'value' ? String(browser.value) : '';
|
|
1442
1559
|
const own = name?.kind === 'value' && typeof name.value === 'string' ? name.value : null;
|
|
@@ -1479,11 +1596,19 @@ export class ConfigRuns {
|
|
|
1479
1596
|
const matchers = [];
|
|
1480
1597
|
for (const [key, fallback, isExclude] of lists) {
|
|
1481
1598
|
const setting = settingAt(settings, key.split('.'));
|
|
1482
|
-
|
|
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
|
+
}
|
|
1483
1605
|
if (!Array.isArray(found))
|
|
1484
1606
|
return this.unknownProject(config, found, key);
|
|
1485
|
-
// tinyglobby, which Vitest finds files with, takes an absolute pattern as one in the folder it searches
|
|
1486
|
-
|
|
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 !== '');
|
|
1487
1612
|
const isMatch = picomatch(relative, { dot: true });
|
|
1488
1613
|
// An excluded folder leaves out everything in it, as the glob doesn't enter it.
|
|
1489
1614
|
matchers.push(isExclude ? (file) => folders(file).some((part) => isMatch(part) || isMatch(`${part}/`)) : isMatch);
|
|
@@ -1968,6 +2093,33 @@ function jestGlobs(globs) {
|
|
|
1968
2093
|
return matchers.every(({ negated }) => negated) ? kept !== false : kept === true;
|
|
1969
2094
|
};
|
|
1970
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
|
+
}
|
|
1971
2123
|
/** Whether a Jest setting is given: `null` and `undefined` leave Jest's default, as a `testMatch: null` beside `testRegex`. */
|
|
1972
2124
|
function isJestSet(setting) {
|
|
1973
2125
|
return setting !== null && !isUnset(setting) && !(setting.kind === 'value' && setting.value === null);
|
|
@@ -1984,8 +2136,9 @@ function isFileAt(file) {
|
|
|
1984
2136
|
* declares tests in a way the scan doesn't read, which is reported on the config, and the file is read as BDD.
|
|
1985
2137
|
*/
|
|
1986
2138
|
export function mochaInterface(placement, configs) {
|
|
1987
|
-
const { config } = placement;
|
|
1988
|
-
|
|
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;
|
|
1989
2142
|
if (ui === null || isUnset(ui))
|
|
1990
2143
|
return 'bdd';
|
|
1991
2144
|
if (ui.kind !== 'value') {
|
|
@@ -1995,7 +2148,9 @@ export function mochaInterface(placement, configs) {
|
|
|
1995
2148
|
if (ui.value === 'bdd' || ui.value === 'tdd')
|
|
1996
2149
|
return ui.value;
|
|
1997
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.`;
|
|
1998
|
-
|
|
2151
|
+
// A command line without a config file has no config to report it on.
|
|
2152
|
+
if (config)
|
|
2153
|
+
configs.reportConfig(config, message);
|
|
1999
2154
|
return 'bdd';
|
|
2000
2155
|
}
|
|
2001
2156
|
/**
|
|
@@ -2012,8 +2167,8 @@ function isSuiteName(settings, item) {
|
|
|
2012
2167
|
export function webdriverioInterface(placement, configs) {
|
|
2013
2168
|
if (placement.config === null || webdriverioFramework(placement, null) === 'jasmine')
|
|
2014
2169
|
return 'bdd';
|
|
2015
|
-
const options = settingAt(placement.config.settings, ['mochaOpts']);
|
|
2016
|
-
return mochaInterface({ ...placement, config: { ...placement.config, settings: options
|
|
2170
|
+
const options = settingAt(placement.config.settings, ['mochaOpts']) ?? emptySettings();
|
|
2171
|
+
return mochaInterface({ ...placement, settings: options, config: { ...placement.config, settings: options } }, configs);
|
|
2017
2172
|
}
|
|
2018
2173
|
/**
|
|
2019
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.
|
|
@@ -98,10 +98,11 @@ export declare class Configs {
|
|
|
98
98
|
/** Reports, once, a file the scan reads runner settings from, such as a package.json script, and can't follow. */
|
|
99
99
|
reportFile(relativeFilePath: string, message: string): void;
|
|
100
100
|
/**
|
|
101
|
-
* The config Mocha runs with, started in the root: the first `.mocharc` file from
|
|
102
|
-
* key of the nearest package.json
|
|
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.
|
|
103
104
|
*/
|
|
104
|
-
mochaConfig(): ConfigFile | null;
|
|
105
|
+
mochaConfig(folder?: string, rcFile?: string | false, manifestFile?: string | false): ConfigFile | null;
|
|
105
106
|
/**
|
|
106
107
|
* The config the jasmine command reads, started in the root: the first of `spec/support/jasmine.mjs` (from Jasmine
|
|
107
108
|
* 5), `.json` and `.js` there; null without one.
|