test-inventory 0.12.0 → 0.12.2
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 +145 -0
- package/README.md +3 -1
- package/dist/ast.d.ts +7 -2
- package/dist/ast.js +43 -3
- package/dist/case-titles.d.ts +5 -11
- package/dist/case-titles.js +69 -55
- package/dist/config-runs.d.ts +19 -2
- package/dist/config-runs.js +380 -91
- package/dist/config.d.ts +0 -5
- package/dist/config.js +0 -7
- package/dist/dependency-hash.js +1 -32
- package/dist/diagnostics.js +17 -2
- package/dist/diff.d.ts +2 -45
- package/dist/extract.d.ts +13 -3
- package/dist/extract.js +837 -89
- package/dist/frameworks/bun.js +47 -24
- package/dist/frameworks/common.d.ts +4 -2
- package/dist/frameworks/common.js +10 -11
- package/dist/frameworks/jasmine-registration.d.ts +47 -0
- package/dist/frameworks/jasmine-registration.js +632 -0
- package/dist/frameworks/jasmine.d.ts +7 -1
- package/dist/frameworks/jasmine.js +65 -70
- package/dist/frameworks/jest.d.ts +2 -2
- package/dist/frameworks/jest.js +126 -51
- package/dist/frameworks/test-functions.js +3 -1
- package/dist/frameworks/vitest.d.ts +2 -3
- package/dist/frameworks/vitest.js +80 -16
- package/dist/generator-steps.d.ts +56 -0
- package/dist/generator-steps.js +254 -0
- package/dist/model.d.ts +37 -5
- package/dist/mutation-arrays.d.ts +25 -0
- package/dist/mutation-arrays.js +229 -0
- package/dist/mutation-calls.d.ts +33 -0
- package/dist/mutation-calls.js +774 -0
- package/dist/mutation-order.d.ts +19 -0
- package/dist/mutation-order.js +55 -0
- package/dist/mutation-references.d.ts +109 -0
- package/dist/mutation-references.js +462 -0
- package/dist/mutation-returns.d.ts +13 -0
- package/dist/mutation-returns.js +71 -0
- package/dist/node-scripts.d.ts +6 -1
- package/dist/node-scripts.js +79 -11
- package/dist/options.d.ts +2 -0
- package/dist/options.js +6 -1
- package/dist/records.d.ts +5 -3
- package/dist/records.js +81 -28
- package/dist/scan-file.d.ts +18 -4
- package/dist/scan-file.js +44 -5
- package/dist/scan-source.js +2 -1
- package/dist/scan.js +30 -13
- package/dist/types.d.ts +45 -1
- package/dist/values.d.ts +72 -18
- package/dist/values.js +651 -172
- package/dist/vitest-concurrency.d.ts +16 -0
- package/dist/vitest-concurrency.js +55 -0
- package/package.json +6 -6
- package/schema/v1.json +1 -0
package/dist/config-runs.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import { existsSync, readFileSync, statSync } from 'node:fs';
|
|
1
|
+
import { existsSync, readFileSync, realpathSync, statSync } from 'node:fs';
|
|
2
|
+
import { createRequire } from 'node:module';
|
|
2
3
|
import path from 'node:path';
|
|
3
4
|
import { pathToFileURL } from 'node:url';
|
|
4
5
|
import picomatch from 'picomatch';
|
|
@@ -94,6 +95,31 @@ function playwrightMatcher(list) {
|
|
|
94
95
|
return isMatch(unix) || expressions.some((expression) => matches(expression, file) || matches(expression, unix));
|
|
95
96
|
};
|
|
96
97
|
}
|
|
98
|
+
/** Playwright moves a file suite when all declarations come from one other file with a different extension.
|
|
99
|
+
* When that file misses the CLI filter, a matching enclosing describe can still select its descendants. */
|
|
100
|
+
function playwrightLocationFilter(file, root, records, matches) {
|
|
101
|
+
const source = records?.tests[0]?.declaredAt?.relativeFilePath;
|
|
102
|
+
if (!source ||
|
|
103
|
+
path.extname(source) === path.extname(file) ||
|
|
104
|
+
!records.tests.every((test) => test.declaredAt?.relativeFilePath === source) ||
|
|
105
|
+
matches(path.resolve(root, source)))
|
|
106
|
+
return null;
|
|
107
|
+
const collections = new WeakMap();
|
|
108
|
+
return (test, suites) => {
|
|
109
|
+
let byId = collections.get(suites);
|
|
110
|
+
if (!byId) {
|
|
111
|
+
byId = new Map(suites.map((suite) => [suite.id, suite]));
|
|
112
|
+
collections.set(suites, byId);
|
|
113
|
+
}
|
|
114
|
+
for (let id = test.suiteId; id !== null;) {
|
|
115
|
+
const suite = byId.get(id);
|
|
116
|
+
if (matches(path.resolve(root, suite.declaredAt?.relativeFilePath ?? suite.relativeFilePath)))
|
|
117
|
+
return true;
|
|
118
|
+
id = suite.parentId;
|
|
119
|
+
}
|
|
120
|
+
return false;
|
|
121
|
+
};
|
|
122
|
+
}
|
|
97
123
|
/**
|
|
98
124
|
* Whether a rule bringing files back may match something inside a folder, as minimatch's partial match tells
|
|
99
125
|
* Playwright: a rule without a `/` matches at any depth, and one with `**` past the folder's depth too.
|
|
@@ -118,6 +144,9 @@ export class ConfigRuns {
|
|
|
118
144
|
version;
|
|
119
145
|
/** Whether the configs find the test files, as in a scan without patterns, rather than the patterns. */
|
|
120
146
|
findsFiles;
|
|
147
|
+
candidates;
|
|
148
|
+
selection;
|
|
149
|
+
unfiltered = new WeakMap();
|
|
121
150
|
projects = new Map();
|
|
122
151
|
ignoreRules = new Map();
|
|
123
152
|
folderStates = new Map();
|
|
@@ -135,11 +164,25 @@ export class ConfigRuns {
|
|
|
135
164
|
/** The projects of a route, by its config and the folder it runs from. */
|
|
136
165
|
routeProjects = new Map();
|
|
137
166
|
candidateProjects = new Map();
|
|
138
|
-
constructor(configs, framework, version,
|
|
167
|
+
constructor(configs, framework, version, candidates, selection) {
|
|
139
168
|
this.configs = configs;
|
|
140
169
|
this.framework = framework;
|
|
141
170
|
this.version = version;
|
|
142
|
-
this.findsFiles =
|
|
171
|
+
this.findsFiles = candidates !== null;
|
|
172
|
+
this.candidates =
|
|
173
|
+
framework === 'playwright' && candidates
|
|
174
|
+
? candidates
|
|
175
|
+
.map((file) => file.split(path.sep))
|
|
176
|
+
.sort((a, b) => {
|
|
177
|
+
// Playwright sorts directory entries before descending into each directory.
|
|
178
|
+
let i = 0;
|
|
179
|
+
while (a[i] === b[i] && i < a.length - 1)
|
|
180
|
+
i++;
|
|
181
|
+
return a[i].localeCompare(b[i]);
|
|
182
|
+
})
|
|
183
|
+
.map((parts) => parts.join(path.sep))
|
|
184
|
+
: (candidates ?? []);
|
|
185
|
+
this.selection = selection;
|
|
143
186
|
}
|
|
144
187
|
/**
|
|
145
188
|
* The config a file uses, as the runner started at the root would: the outermost config at or above it that runs it,
|
|
@@ -168,6 +211,15 @@ export class ConfigRuns {
|
|
|
168
211
|
return { ...placement, runs: null, projects: null };
|
|
169
212
|
return routed ?? placement;
|
|
170
213
|
}
|
|
214
|
+
*scriptRoutesAbove(file) {
|
|
215
|
+
if (!isInside(this.configs.root, file))
|
|
216
|
+
return;
|
|
217
|
+
for (let folder = path.dirname(file);; folder = path.dirname(folder)) {
|
|
218
|
+
yield* this.routesIn(folder);
|
|
219
|
+
if (folder === this.configs.root)
|
|
220
|
+
break;
|
|
221
|
+
}
|
|
222
|
+
}
|
|
171
223
|
placeByConfigs(file) {
|
|
172
224
|
if (this.framework === 'mocha')
|
|
173
225
|
return this.placeMocha(file);
|
|
@@ -184,7 +236,18 @@ export class ConfigRuns {
|
|
|
184
236
|
// Jest started at the root reads the config there only, and the others through its `projects`.
|
|
185
237
|
const rootConfig = this.framework === 'jest' ? this.configs.inFolder(this.configs.root) : null;
|
|
186
238
|
const around = this.framework !== 'jest' ? this.configs.around(file) : rootConfig ? [rootConfig] : [];
|
|
187
|
-
|
|
239
|
+
// A config selected by filtered package scripts runs with their arguments during discovery.
|
|
240
|
+
const scripted = new Set();
|
|
241
|
+
if (this.findsFiles && around.length) {
|
|
242
|
+
for (const route of this.scriptRoutesAbove(file)) {
|
|
243
|
+
if ('selects' in route && route.config)
|
|
244
|
+
scripted.add(route.config.file);
|
|
245
|
+
if ('launchConfig' in route && route.launchConfig)
|
|
246
|
+
scripted.add(route.launchConfig.file);
|
|
247
|
+
}
|
|
248
|
+
}
|
|
249
|
+
const standalone = around.filter((config) => !scripted.has(config.file));
|
|
250
|
+
for (const config of standalone) {
|
|
188
251
|
const running = this.projectsOf(config).flatMap((project) => {
|
|
189
252
|
const runs = project.runs?.(file);
|
|
190
253
|
return runs ? [{ project, runs }] : [];
|
|
@@ -192,10 +255,13 @@ export class ConfigRuns {
|
|
|
192
255
|
if (running.length > 0) {
|
|
193
256
|
const [{ project, runs }] = running;
|
|
194
257
|
const projects = running.map((item) => item.project.about);
|
|
195
|
-
|
|
258
|
+
const preloaded = this.framework === 'playwright' && this.findsFiles
|
|
259
|
+
? this.unfilteredModules(this.projectsOf(config)).get(file)
|
|
260
|
+
: undefined;
|
|
261
|
+
return { config: project.config, settings: project.settings, runs, projects, preloaded };
|
|
196
262
|
}
|
|
197
263
|
}
|
|
198
|
-
const unknown =
|
|
264
|
+
const unknown = standalone.flatMap((config) => this.projectsOf(config)).find((project) => project.unknown);
|
|
199
265
|
if (unknown?.unknown) {
|
|
200
266
|
return this.unknownPlacement(unknown, file);
|
|
201
267
|
}
|
|
@@ -257,33 +323,74 @@ export class ConfigRuns {
|
|
|
257
323
|
*/
|
|
258
324
|
placeByScripts(file) {
|
|
259
325
|
const unknown = [];
|
|
260
|
-
for (
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
const
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
326
|
+
for (const route of this.scriptRoutesAbove(file)) {
|
|
327
|
+
if ('unknown' in route) {
|
|
328
|
+
unknown.push(route);
|
|
329
|
+
continue;
|
|
330
|
+
}
|
|
331
|
+
const projects = this.projectsOfRoute(route).filter((project) => !this.findsFiles || !route.selects || route.selects(file, project));
|
|
332
|
+
const running = projects.flatMap((project) => {
|
|
333
|
+
const runs = project.runs?.(file);
|
|
334
|
+
return runs ? [{ project, runs }] : [];
|
|
335
|
+
});
|
|
336
|
+
if (running.length > 0) {
|
|
337
|
+
const [{ project, runs }] = running;
|
|
338
|
+
const config = route.config && project.config;
|
|
339
|
+
const testFilters = new Map();
|
|
340
|
+
if (this.findsFiles && route.testFilter) {
|
|
341
|
+
for (const item of running) {
|
|
342
|
+
const first = route.testFilter(file, item.project);
|
|
343
|
+
if (!first)
|
|
344
|
+
continue;
|
|
345
|
+
const alternatives = [first];
|
|
346
|
+
for (const other of this.scriptRoutesAbove(file)) {
|
|
347
|
+
if (other === route || 'unknown' in other || other.config !== route.config)
|
|
348
|
+
continue;
|
|
349
|
+
if (!this.projectsOfRoute(other).includes(item.project) || other.selects?.(file, item.project) === false)
|
|
350
|
+
continue;
|
|
351
|
+
const filter = other.testFilter?.(file, item.project);
|
|
352
|
+
if (!filter) {
|
|
353
|
+
alternatives.length = 0;
|
|
354
|
+
break;
|
|
355
|
+
}
|
|
356
|
+
alternatives.push(filter);
|
|
357
|
+
}
|
|
358
|
+
if (alternatives.length)
|
|
359
|
+
testFilters.set(item.project.about, (test, suites) => alternatives.some((filter) => filter(test, suites)));
|
|
360
|
+
}
|
|
275
361
|
}
|
|
276
|
-
|
|
277
|
-
if (
|
|
278
|
-
|
|
279
|
-
|
|
362
|
+
let preloaded = route.preloaded?.get(file);
|
|
363
|
+
if (preloaded) {
|
|
364
|
+
for (const other of this.scriptRoutesAbove(file)) {
|
|
365
|
+
if (other === route || 'unknown' in other || other.config !== route.config)
|
|
366
|
+
continue;
|
|
367
|
+
if (!running.some(({ project }) => other.selects?.(file, project) !== false))
|
|
368
|
+
continue;
|
|
369
|
+
const skipped = other.preloaded?.get(file);
|
|
370
|
+
if (!skipped) {
|
|
371
|
+
preloaded = undefined;
|
|
372
|
+
break;
|
|
373
|
+
}
|
|
374
|
+
preloaded = new Set([...preloaded].filter((name) => skipped.has(name)));
|
|
280
375
|
}
|
|
281
|
-
this.configs.reportUnknown(unknownProject.unknown.setting, unknownProject.unknown.key, ASSUMED);
|
|
282
|
-
return 'unknown';
|
|
283
376
|
}
|
|
377
|
+
return {
|
|
378
|
+
config,
|
|
379
|
+
preloaded,
|
|
380
|
+
settings: project.settings,
|
|
381
|
+
runs,
|
|
382
|
+
projects: running.map((item) => item.project.about),
|
|
383
|
+
testFilters,
|
|
384
|
+
};
|
|
385
|
+
}
|
|
386
|
+
const unknownProject = projects.find((project) => project.unknown);
|
|
387
|
+
if (unknownProject?.unknown) {
|
|
388
|
+
if (this.findsFiles && CANDIDATE_RUNNERS.has(this.framework)) {
|
|
389
|
+
return this.unknownPlacement(unknownProject, file);
|
|
390
|
+
}
|
|
391
|
+
this.configs.reportUnknown(unknownProject.unknown.setting, unknownProject.unknown.key, ASSUMED);
|
|
392
|
+
return 'unknown';
|
|
284
393
|
}
|
|
285
|
-
if (folder === this.configs.root)
|
|
286
|
-
break;
|
|
287
394
|
}
|
|
288
395
|
for (const route of unknown)
|
|
289
396
|
this.configs.reportFile(this.configs.relative(route.manifest), route.unknown);
|
|
@@ -308,29 +415,36 @@ export class ConfigRuns {
|
|
|
308
415
|
// No package.json, or one the runner can't start from either.
|
|
309
416
|
}
|
|
310
417
|
const seen = new Set();
|
|
418
|
+
const canEnter = (dir) => {
|
|
419
|
+
const cwd = path.resolve(folder, dir);
|
|
420
|
+
if (cwd !== this.configs.root && !isInside(this.configs.root, cwd))
|
|
421
|
+
return null;
|
|
422
|
+
return statSync(cwd, { throwIfNoEntry: false })?.isDirectory() === true;
|
|
423
|
+
};
|
|
311
424
|
for (const [name, script] of Object.entries(scripts)) {
|
|
312
425
|
if (typeof script !== 'string')
|
|
313
426
|
continue;
|
|
314
|
-
for (const command of runnerCommands(script, this.framework)) {
|
|
427
|
+
for (const command of runnerCommands(script, this.framework, canEnter)) {
|
|
315
428
|
const about = `The script ${name} in ${this.configs.relative(manifest)} starts the runner`;
|
|
316
429
|
if (command.unreadable) {
|
|
317
430
|
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
431
|
routes.push({ manifest, unknown });
|
|
319
432
|
continue;
|
|
320
433
|
}
|
|
434
|
+
const cwd = path.resolve(folder, command.cwd ?? '.');
|
|
321
435
|
if (this.framework === 'mocha') {
|
|
322
|
-
const route = this.mochaRoute(
|
|
436
|
+
const route = this.mochaRoute(cwd, command.config, command.args);
|
|
323
437
|
if (route === null)
|
|
324
438
|
continue;
|
|
325
|
-
const key = `${route.config?.file ?? ''}\0${JSON.stringify([...route.args.options, route.args.positional])}`;
|
|
439
|
+
const key = `${cwd}\0${route.config?.file ?? ''}\0${JSON.stringify([...route.args.options, route.args.positional])}`;
|
|
326
440
|
if (seen.has(key))
|
|
327
441
|
continue;
|
|
328
442
|
seen.add(key);
|
|
329
|
-
routes.push({ config: route.config, root:
|
|
443
|
+
routes.push({ config: route.config, root: cwd, mocha: route.args });
|
|
330
444
|
continue;
|
|
331
445
|
}
|
|
332
|
-
const root = command.root === null ?
|
|
333
|
-
const from = this.framework === 'vitest' || this.framework === 'cypress' ? root :
|
|
446
|
+
const root = command.root === null ? cwd : path.resolve(cwd, command.root);
|
|
447
|
+
const from = this.framework === 'vitest' || this.framework === 'cypress' ? root : cwd;
|
|
334
448
|
let config;
|
|
335
449
|
if (command.config === null)
|
|
336
450
|
config = this.defaultConfigIn(root);
|
|
@@ -344,26 +458,154 @@ export class ConfigRuns {
|
|
|
344
458
|
if (config === null)
|
|
345
459
|
continue;
|
|
346
460
|
}
|
|
347
|
-
//
|
|
348
|
-
if (config === null && this.framework !== 'vitest')
|
|
461
|
+
// A plain Playwright test command and Vitest both collect tests without a config.
|
|
462
|
+
if (config === null && this.framework !== 'vitest' && !command.playwrightDefaults && !command.filters)
|
|
349
463
|
continue;
|
|
350
|
-
const key = `${config?.file ?? ''}\0${root}`;
|
|
464
|
+
const key = `${config?.file ?? ''}\0${root}\0${JSON.stringify(command.filters)}`;
|
|
351
465
|
if (seen.has(key))
|
|
352
466
|
continue;
|
|
353
467
|
seen.add(key);
|
|
354
|
-
|
|
468
|
+
const route = { config, root };
|
|
469
|
+
if (command.cwd && command.config === null)
|
|
470
|
+
route.launchConfig = this.defaultConfigIn(folder);
|
|
471
|
+
if (command.filters)
|
|
472
|
+
route.selects = this.matchScriptFiles(command.filters, cwd, route);
|
|
473
|
+
else if (this.framework === 'playwright' && this.findsFiles)
|
|
474
|
+
route.preloaded = this.unfilteredModules(this.projectsOfRoute(route));
|
|
475
|
+
routes.push(route);
|
|
355
476
|
}
|
|
356
477
|
}
|
|
357
478
|
this.scriptRoutes.set(folder, routes);
|
|
358
479
|
return routes;
|
|
359
480
|
}
|
|
481
|
+
/** A process initializes each imported module in the first spec that loads it, in project and directory order. */
|
|
482
|
+
preloadedModules(projects, loads) {
|
|
483
|
+
const visited = new Set();
|
|
484
|
+
const initialized = new Set();
|
|
485
|
+
const preloaded = new Map();
|
|
486
|
+
for (const project of projects) {
|
|
487
|
+
for (const file of this.candidates) {
|
|
488
|
+
if (visited.has(file) || !project.runs?.(file) || !loads(file, project))
|
|
489
|
+
continue;
|
|
490
|
+
visited.add(file);
|
|
491
|
+
const { imports } = this.selection(file);
|
|
492
|
+
const skipped = new Set([...imports].filter((name) => initialized.has(name)));
|
|
493
|
+
if (skipped.size)
|
|
494
|
+
preloaded.set(file, skipped);
|
|
495
|
+
for (const name of imports)
|
|
496
|
+
initialized.add(name);
|
|
497
|
+
}
|
|
498
|
+
}
|
|
499
|
+
return preloaded;
|
|
500
|
+
}
|
|
501
|
+
unfilteredModules(projects) {
|
|
502
|
+
let preloaded = this.unfiltered.get(projects);
|
|
503
|
+
if (!preloaded) {
|
|
504
|
+
preloaded = this.preloadedModules(projects, () => true);
|
|
505
|
+
this.unfiltered.set(projects, preloaded);
|
|
506
|
+
}
|
|
507
|
+
return preloaded;
|
|
508
|
+
}
|
|
509
|
+
matchScriptFiles(filters, folder, route) {
|
|
510
|
+
if (this.framework === 'jest') {
|
|
511
|
+
const paths = new Set(filters.map((filter) => path.resolve(folder, filter)));
|
|
512
|
+
return (file) => paths.has(file);
|
|
513
|
+
}
|
|
514
|
+
if (this.framework === 'playwright') {
|
|
515
|
+
const patterns = [];
|
|
516
|
+
for (const filter of filters) {
|
|
517
|
+
const literal = /^\/(.*)\/([gi]*)$/.exec(filter);
|
|
518
|
+
const pattern = literal ? regExp(literal[1], literal[2]) : new RegExp(filter, 'i');
|
|
519
|
+
if (!pattern)
|
|
520
|
+
return () => false;
|
|
521
|
+
patterns.push(pattern);
|
|
522
|
+
}
|
|
523
|
+
const matchesFile = playwrightMatcher(patterns);
|
|
524
|
+
const projects = this.projectsOfRoute(route);
|
|
525
|
+
const prerequisites = new Set(projects.flatMap((project) => {
|
|
526
|
+
const teardown = settingAt(project.about.settings, ['teardown']);
|
|
527
|
+
return teardown?.kind === 'value' && typeof teardown.value === 'string'
|
|
528
|
+
? [...project.about.dependencies, teardown.value]
|
|
529
|
+
: project.about.dependencies;
|
|
530
|
+
}));
|
|
531
|
+
const preloaded = this.preloadedModules(projects, (file, project) => prerequisites.has(project.about.name) || matchesFile(file));
|
|
532
|
+
route.preloaded = preloaded;
|
|
533
|
+
const recordsByFile = new Map();
|
|
534
|
+
const selectedTests = (file) => {
|
|
535
|
+
if (!recordsByFile.has(file))
|
|
536
|
+
recordsByFile.set(file, this.selection(file, preloaded.get(file)).records());
|
|
537
|
+
return recordsByFile.get(file);
|
|
538
|
+
};
|
|
539
|
+
const locations = new Map();
|
|
540
|
+
const locationFilter = (file) => {
|
|
541
|
+
if (!locations.has(file)) {
|
|
542
|
+
locations.set(file, playwrightLocationFilter(file, this.configs.root, selectedTests(file), matchesFile));
|
|
543
|
+
}
|
|
544
|
+
return locations.get(file);
|
|
545
|
+
};
|
|
546
|
+
const required = new Set();
|
|
547
|
+
const visit = (project) => {
|
|
548
|
+
const teardown = settingAt(project.about.settings, ['teardown']);
|
|
549
|
+
for (const other of projects) {
|
|
550
|
+
if (required.has(other))
|
|
551
|
+
continue;
|
|
552
|
+
const name = other.about.name;
|
|
553
|
+
if (project.about.dependencies.includes(name) || (teardown?.kind === 'value' && teardown.value === name)) {
|
|
554
|
+
required.add(other);
|
|
555
|
+
visit(other);
|
|
556
|
+
}
|
|
557
|
+
}
|
|
558
|
+
};
|
|
559
|
+
for (const project of projects) {
|
|
560
|
+
if (!project.about.dependencies.length && !settingAt(project.about.settings, ['teardown']))
|
|
561
|
+
continue;
|
|
562
|
+
const hasTests = this.candidates.some((file) => {
|
|
563
|
+
if (!matchesFile(file) || !project.runs?.(file))
|
|
564
|
+
return false;
|
|
565
|
+
const records = selectedTests(file);
|
|
566
|
+
if (!records)
|
|
567
|
+
return true;
|
|
568
|
+
const tags = this.configTags(project.config);
|
|
569
|
+
return records.tests.some((test) => locationFilter(file)?.(test, records.suites) !== false &&
|
|
570
|
+
projectsRunning([project.about], test, records.suites, file, tags)?.length !== 0);
|
|
571
|
+
});
|
|
572
|
+
if (hasTests)
|
|
573
|
+
visit(project);
|
|
574
|
+
}
|
|
575
|
+
route.testFilter = (file, project) => (required.has(project) ? null : locationFilter(file));
|
|
576
|
+
return (file, project) => {
|
|
577
|
+
if (required.has(project))
|
|
578
|
+
return true;
|
|
579
|
+
if (!matchesFile(file))
|
|
580
|
+
return false;
|
|
581
|
+
if (!project.runs?.(file))
|
|
582
|
+
return true;
|
|
583
|
+
const filter = locationFilter(file);
|
|
584
|
+
if (!filter)
|
|
585
|
+
return true;
|
|
586
|
+
const records = selectedTests(file);
|
|
587
|
+
return records.tests.some((test) => filter(test, records.suites));
|
|
588
|
+
};
|
|
589
|
+
}
|
|
590
|
+
return (file, project) => {
|
|
591
|
+
const dir = project.about.testDir;
|
|
592
|
+
const test = posix(path.relative(dir, file)).toLocaleLowerCase();
|
|
593
|
+
return filters.some((filter) => {
|
|
594
|
+
if (path.isAbsolute(filter) && posix(file).startsWith(filter))
|
|
595
|
+
return true;
|
|
596
|
+
const relative = posix(path.relative(dir, path.resolve(folder, filter)));
|
|
597
|
+
const resolved = filter.endsWith('/') ? path.posix.join(relative, '/') : relative;
|
|
598
|
+
return test.includes(filter.toLocaleLowerCase()) || test.includes(resolved.toLocaleLowerCase());
|
|
599
|
+
});
|
|
600
|
+
};
|
|
601
|
+
}
|
|
360
602
|
/**
|
|
361
603
|
* The config a runner started in a folder without one named finds: there only, except that Vitest before 5.0 also
|
|
362
604
|
* looks in the folders above it, and Jest takes the folder's package.json when it finds no config; null for Vitest's
|
|
363
605
|
* defaults.
|
|
364
606
|
*/
|
|
365
607
|
defaultConfigIn(folder) {
|
|
366
|
-
const own = this.framework === 'jest' ? this.configs.
|
|
608
|
+
const own = this.framework === 'jest' ? this.configs.projectConfig(folder) : this.configs.inFolder(folder);
|
|
367
609
|
if (own || this.framework !== 'vitest' || atLeast(this.version, 5, 0))
|
|
368
610
|
return own;
|
|
369
611
|
// A config above the project's root is outside what the scan reads.
|
|
@@ -452,6 +694,11 @@ export class ConfigRuns {
|
|
|
452
694
|
/** Mocha runs one set of files, from the config it starts with, or its defaults without one. */
|
|
453
695
|
placeMocha(file) {
|
|
454
696
|
const config = this.configs.mochaConfig();
|
|
697
|
+
// A readable root command runs this config with its CLI options. A separately discovered config still counts.
|
|
698
|
+
if (this.findsFiles &&
|
|
699
|
+
this.routesIn(this.configs.root).some((route) => 'mocha' in route && (!config || route.config?.file === config.file))) {
|
|
700
|
+
return { config, settings: null, runs: false, projects: null };
|
|
701
|
+
}
|
|
455
702
|
const project = config
|
|
456
703
|
? this.projectsOf(config)[0]
|
|
457
704
|
: (this.mochaDefaults ??= this.mochaProject(this.noConfig(), emptySettings()));
|
|
@@ -476,25 +723,46 @@ export class ConfigRuns {
|
|
|
476
723
|
['spec', ['./test']],
|
|
477
724
|
['extension', ['js', 'cjs', 'mjs']],
|
|
478
725
|
['ignore', []],
|
|
726
|
+
['exclude', []],
|
|
479
727
|
['file', []],
|
|
480
728
|
]) {
|
|
481
|
-
const setting = settingAt(settings, [key])
|
|
729
|
+
const setting = settingAt(settings, [key]);
|
|
482
730
|
const found = setting === null || isUnset(setting) ? [...fallback] : patterns(setting, false);
|
|
483
731
|
if (!Array.isArray(found))
|
|
484
732
|
return this.unknownProject(config, found, key);
|
|
485
|
-
|
|
733
|
+
const values = found;
|
|
734
|
+
lists[key] = key === 'extension' || key === 'file' ? values.join(',').split(/ *, */) : values;
|
|
486
735
|
}
|
|
487
736
|
const recursiveSetting = settingAt(settings, ['recursive']);
|
|
488
737
|
if (recursiveSetting?.kind === 'unknown')
|
|
489
738
|
return this.unknownProject(config, recursiveSetting, 'recursive');
|
|
490
739
|
const recursive = recursiveSetting?.kind === 'value' && recursiveSetting.value === true;
|
|
491
|
-
const extensions = lists.extension;
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
740
|
+
const extensions = lists.extension.map((ext) => ext.replace(/^\./, ''));
|
|
741
|
+
const ignores = [...lists.ignore, ...lists.exclude]
|
|
742
|
+
.filter((pattern) => !pattern.startsWith('#'))
|
|
743
|
+
.map((pattern) => {
|
|
744
|
+
const glob = posix(pattern).replace(/^!+/, '');
|
|
745
|
+
const negate = (pattern.length - glob.length) % 2 === 1;
|
|
746
|
+
return (file) => path.posix.matchesGlob(file, glob) !== negate;
|
|
747
|
+
});
|
|
748
|
+
const included = (file) => !ignores.some((match) => match(file));
|
|
749
|
+
const specs = lists.spec.map((spec) => mochaSpec(folder, spec, extensions, recursive, included));
|
|
750
|
+
const loaded = new Set();
|
|
751
|
+
for (const entry of lists.file) {
|
|
752
|
+
const target = path.resolve(folder, entry);
|
|
753
|
+
if (isFileAt(target))
|
|
754
|
+
loaded.add(target);
|
|
755
|
+
else {
|
|
756
|
+
try {
|
|
757
|
+
const resolved = createRequire(import.meta.url).resolve(target);
|
|
758
|
+
// Node resolves symlinks, while discovery preserves the path used to reach the project.
|
|
759
|
+
loaded.add(path.resolve(folder, path.relative(realpathSync(folder), resolved)));
|
|
760
|
+
}
|
|
761
|
+
catch {
|
|
762
|
+
// A missing preload identifies no source file.
|
|
763
|
+
}
|
|
764
|
+
}
|
|
765
|
+
}
|
|
498
766
|
const duration = (key) => {
|
|
499
767
|
const setting = settingAt(settings, [key]);
|
|
500
768
|
const value = setting?.kind === 'value' ? durationOf(setting.value, key) : null;
|
|
@@ -524,9 +792,7 @@ export class ConfigRuns {
|
|
|
524
792
|
return 'test';
|
|
525
793
|
// A project's scripts often give Mocha the spec on its command line, which no config shows, so with globs the
|
|
526
794
|
// scan takes each file they match as run, less `ignore`.
|
|
527
|
-
|
|
528
|
-
return false;
|
|
529
|
-
return ignored.some((isMatch) => isMatch(relative)) ? false : 'test';
|
|
795
|
+
return (this.findsFiles ? specs.some((spec) => spec(file)) : included(relative)) ? 'test' : false;
|
|
530
796
|
},
|
|
531
797
|
};
|
|
532
798
|
}
|
|
@@ -1460,7 +1726,14 @@ export class ConfigRuns {
|
|
|
1460
1726
|
: [];
|
|
1461
1727
|
projects.push(...matches.flatMap((match) => this.vitestPath(config, path.resolve(match), container)));
|
|
1462
1728
|
this.expanding.delete(config);
|
|
1463
|
-
|
|
1729
|
+
if (atLeast(this.version, 5, 0))
|
|
1730
|
+
return projects;
|
|
1731
|
+
// Before Vitest 5 the runner sends the root sequence.concurrent to every project's workers.
|
|
1732
|
+
const parallel = settingAt(config.settings, ['test', 'sequence', 'concurrent']);
|
|
1733
|
+
return projects.map((project) => ({
|
|
1734
|
+
...project,
|
|
1735
|
+
about: { ...project.about, defaults: { ...project.about.defaults, parallel } },
|
|
1736
|
+
}));
|
|
1464
1737
|
}
|
|
1465
1738
|
/**
|
|
1466
1739
|
* The files a config's own file settings select, as candidates for projects the scan can't list, which mostly narrow
|
|
@@ -1643,7 +1916,7 @@ export class ConfigRuns {
|
|
|
1643
1916
|
// Vitest 5 added `repeats` to the config.
|
|
1644
1917
|
repeats: atLeast(this.version, 5, 0) ? settingAt(settings, ['test', 'repeats']) : null,
|
|
1645
1918
|
parallel: settingAt(settings, ['test', 'sequence', 'concurrent']),
|
|
1646
|
-
tags: vitestTags(ownTags ?? settingAt(settings, ['test', 'tags']), settingAt(settings, ['test', 'strictTags']),
|
|
1919
|
+
tags: vitestTags(ownTags ?? settingAt(settings, ['test', 'tags']), settingAt(settings, ['test', 'strictTags']), atLeast(this.version, 5, 0)),
|
|
1647
1920
|
},
|
|
1648
1921
|
};
|
|
1649
1922
|
return {
|
|
@@ -1741,30 +2014,31 @@ function writtenRoot(settings) {
|
|
|
1741
2014
|
}
|
|
1742
2015
|
/** A config's settings without `test.projects`, as an inline project inherits them; both are known objects. */
|
|
1743
2016
|
/**
|
|
1744
|
-
*
|
|
1745
|
-
*
|
|
1746
|
-
* the extensions it takes, without hidden ones, and those of folders below with `recursive`.
|
|
2017
|
+
* Mocha looks for the literal file or folder first, then expands a glob or tries the configured extensions. A
|
|
2018
|
+
* folder selects files with those extensions, skipping hidden filenames and descending only with `recursive`.
|
|
1747
2019
|
*/
|
|
1748
|
-
function mochaSpec(folder, spec, extensions, recursive) {
|
|
2020
|
+
function mochaSpec(folder, spec, extensions, recursive, included) {
|
|
1749
2021
|
const target = path.resolve(folder, spec);
|
|
1750
|
-
|
|
1751
|
-
|
|
1752
|
-
|
|
1753
|
-
const isMatch = picomatch(posix(written).replace(/^\.\//, ''));
|
|
1754
|
-
return (file) => isMatch(posix(path.relative(folder, file)));
|
|
1755
|
-
}
|
|
1756
|
-
const stat = statSync(target, { throwIfNoEntry: false });
|
|
2022
|
+
// Let the host filesystem decide whether a missing component before `..` prevents a literal lookup.
|
|
2023
|
+
const literal = path.isAbsolute(spec) ? spec : folder + path.sep + spec;
|
|
2024
|
+
const stat = statSync(literal, { throwIfNoEntry: false });
|
|
1757
2025
|
if (stat?.isFile())
|
|
1758
|
-
return (file) => file === target;
|
|
1759
|
-
|
|
1760
|
-
|
|
2026
|
+
return (file) => file === target && included(posix(spec));
|
|
2027
|
+
const lookupName = (file) => posix(path.isAbsolute(spec) ? file : path.relative(folder, file));
|
|
2028
|
+
if (!stat?.isDirectory()) {
|
|
2029
|
+
const written = posix(path.isAbsolute(spec) ? path.relative(folder, spec) : spec).replace(/^(?:\.\/)+/, '');
|
|
2030
|
+
// Mocha's glob library expands braces but counts only wildcards and extglobs as magic.
|
|
2031
|
+
const magic = picomatch.scan(written.replace(/\[[^[\]\\]\]|[{}]/g, '_'), { nonegate: true }).isGlob;
|
|
2032
|
+
const pattern = magic ? written : written + '+(' + extensions.map((ext) => '.' + ext).join('|') + ')';
|
|
2033
|
+
return (file) => path.posix.matchesGlob(posix(path.relative(folder, file)), pattern) && included(lookupName(file));
|
|
2034
|
+
}
|
|
1761
2035
|
return (file) => {
|
|
1762
2036
|
if (!isInside(target, file) || path.basename(file).startsWith('.'))
|
|
1763
2037
|
return false;
|
|
1764
2038
|
if (!recursive && path.dirname(file) !== target)
|
|
1765
2039
|
return false;
|
|
1766
2040
|
// An extension may have several parts, as `spec.js`.
|
|
1767
|
-
return extensions.some((extension) => file.endsWith(`.${extension}`));
|
|
2041
|
+
return extensions.some((extension) => file.endsWith(`.${extension}`)) && included(lookupName(file));
|
|
1768
2042
|
};
|
|
1769
2043
|
}
|
|
1770
2044
|
function withoutProjects(settings) {
|
|
@@ -1908,9 +2182,8 @@ function tagIn(setting) {
|
|
|
1908
2182
|
}
|
|
1909
2183
|
/**
|
|
1910
2184
|
* The tags a Vitest config defines, from `test.tags` and `test.strictTags`; null when the scan can't work them out.
|
|
1911
|
-
* Vitest 4.1 passes a `sequence.concurrent` the config sets to every test as an option, where it wins over a tag's.
|
|
1912
2185
|
*/
|
|
1913
|
-
function vitestTags(tags, strictTags,
|
|
2186
|
+
function vitestTags(tags, strictTags, beatsDescribes) {
|
|
1914
2187
|
const items = tags === null || isUnset(tags) ? [] : tags.kind === 'list' ? tags.items : null;
|
|
1915
2188
|
const definitions = items?.map(tagIn) ?? null;
|
|
1916
2189
|
if (definitions === null || definitions.includes(null))
|
|
@@ -1921,7 +2194,6 @@ function vitestTags(tags, strictTags, concurrent, beatsDescribes) {
|
|
|
1921
2194
|
definitions: definitions,
|
|
1922
2195
|
isStrict: Boolean(strictTags?.value ?? true),
|
|
1923
2196
|
beatsDescribes,
|
|
1924
|
-
concurrentBeatsTags: !beatsDescribes && concurrent !== null && !isUnset(concurrent),
|
|
1925
2197
|
};
|
|
1926
2198
|
}
|
|
1927
2199
|
/**
|
|
@@ -1960,7 +2232,11 @@ function configDefaults(projects) {
|
|
|
1960
2232
|
timeoutText: agreedText((defaults) => defaults.timeout),
|
|
1961
2233
|
retryText: agreedText(({ retry }) => (retry?.kind === 'object' ? settingAt(retry, ['count']) : retry)),
|
|
1962
2234
|
repeatsText: agreedText((defaults) => defaults.repeatEach ?? defaults.repeats),
|
|
1963
|
-
parallel:
|
|
2235
|
+
parallel: agreed(({ parallel }) => {
|
|
2236
|
+
if (parallel === null || isUnset(parallel))
|
|
2237
|
+
return undefined;
|
|
2238
|
+
return parallel.kind === 'value' && typeof parallel.value === 'boolean' ? parallel.value : null;
|
|
2239
|
+
}),
|
|
1964
2240
|
};
|
|
1965
2241
|
}
|
|
1966
2242
|
const NO_CONFIG = { projects: null, defaults: null };
|
|
@@ -1972,7 +2248,7 @@ const UNKNOWN_DEFAULTS = {
|
|
|
1972
2248
|
timeoutText: null,
|
|
1973
2249
|
retryText: null,
|
|
1974
2250
|
repeatsText: null,
|
|
1975
|
-
parallel:
|
|
2251
|
+
parallel: null,
|
|
1976
2252
|
};
|
|
1977
2253
|
/**
|
|
1978
2254
|
* What the config a file uses gives it: Playwright's `forbidOnly`, Vitest's per-project `allowOnly`, and for each test,
|
|
@@ -1982,8 +2258,17 @@ export function fileConfig(placement, framework, version, file) {
|
|
|
1982
2258
|
const { config, projects } = placement;
|
|
1983
2259
|
if (config === null) {
|
|
1984
2260
|
// Without a config, Vitest defines no tags and keeps strictTags on.
|
|
1985
|
-
const tags = vitestTags(null, null,
|
|
2261
|
+
const tags = vitestTags(null, null, atLeast(version, 5, 0));
|
|
1986
2262
|
const forbidOnly = onlyRule(framework, null);
|
|
2263
|
+
if (placement.testFilters?.size) {
|
|
2264
|
+
const filters = [...placement.testFilters.values()];
|
|
2265
|
+
return {
|
|
2266
|
+
forbidOnly,
|
|
2267
|
+
tags,
|
|
2268
|
+
configTags: [],
|
|
2269
|
+
forTest: (test, suites) => filters.some((filter) => filter(test, suites)) ? NO_CONFIG : { projects: [], defaults: null },
|
|
2270
|
+
};
|
|
2271
|
+
}
|
|
1987
2272
|
return framework === 'vitest' ? { forbidOnly, forTest: () => NO_CONFIG, tags, configTags: [] } : null;
|
|
1988
2273
|
}
|
|
1989
2274
|
return {
|
|
@@ -1991,7 +2276,10 @@ export function fileConfig(placement, framework, version, file) {
|
|
|
1991
2276
|
forTest(test, suites) {
|
|
1992
2277
|
if (projects === null)
|
|
1993
2278
|
return { projects: null, defaults: UNKNOWN_DEFAULTS };
|
|
1994
|
-
const
|
|
2279
|
+
const eligible = placement.testFilters?.size
|
|
2280
|
+
? projects.filter((project) => placement.testFilters?.get(project)?.(test, suites) !== false)
|
|
2281
|
+
: projects;
|
|
2282
|
+
const running = projectsRunning(eligible, test, suites, file, placement.tags);
|
|
1995
2283
|
// A grep the scan can't match leaves the projects that run the file, which may still agree.
|
|
1996
2284
|
return {
|
|
1997
2285
|
projects: running?.map(({ name }) => name) ?? null,
|
|
@@ -2097,31 +2385,32 @@ function jestGlobs(globs) {
|
|
|
2097
2385
|
};
|
|
2098
2386
|
}
|
|
2099
2387
|
/**
|
|
2100
|
-
*
|
|
2101
|
-
*
|
|
2388
|
+
* Mocha combines repeatable options from its command line and config, including positional specs. The command
|
|
2389
|
+
* line takes precedence for scalar options.
|
|
2102
2390
|
*/
|
|
2103
2391
|
function mochaSettings(settings, args) {
|
|
2104
2392
|
if (settings.kind !== 'object')
|
|
2105
2393
|
return settings;
|
|
2106
|
-
const list = (values) => values.map((value) => ({ kind: 'value', value }));
|
|
2107
2394
|
const keys = new Map(settings.keys);
|
|
2108
2395
|
for (const name of ['spec', 'extension', 'ignore', 'file']) {
|
|
2109
|
-
const values = args.options.get(name);
|
|
2110
|
-
|
|
2111
|
-
|
|
2396
|
+
const values = args.options.get(name) ?? [];
|
|
2397
|
+
const added = name === 'spec' ? [...args.positional, ...values] : values;
|
|
2398
|
+
if (!added.length)
|
|
2399
|
+
continue;
|
|
2400
|
+
const configured = settingAt(settings, [name]);
|
|
2401
|
+
const existing = configured === null || isUnset(configured) ? [] : configured.kind === 'list' ? configured.items : [configured];
|
|
2402
|
+
keys.set(name, {
|
|
2403
|
+
kind: 'list',
|
|
2404
|
+
items: [...added.map((value) => ({ kind: 'value', value })), ...existing],
|
|
2405
|
+
});
|
|
2112
2406
|
}
|
|
2113
2407
|
const ui = args.options.get('ui')?.at(-1);
|
|
2114
2408
|
if (ui !== undefined)
|
|
2115
2409
|
keys.set('ui', { kind: 'value', value: ui });
|
|
2116
|
-
|
|
2117
|
-
|
|
2118
|
-
|
|
2119
|
-
|
|
2120
|
-
return merged;
|
|
2121
|
-
const spec = settingAt(merged, ['spec']);
|
|
2122
|
-
const rest = spec === null || isUnset(spec) ? [] : spec.kind === 'list' ? spec.items : [spec];
|
|
2123
|
-
keys.set('spec', { kind: 'list', items: [...list(args.positional), ...rest] });
|
|
2124
|
-
return merged;
|
|
2410
|
+
const recursive = args.options.get('recursive');
|
|
2411
|
+
if (recursive)
|
|
2412
|
+
keys.set('recursive', { kind: 'value', value: recursive[0] !== 'false' });
|
|
2413
|
+
return { ...settings, keys };
|
|
2125
2414
|
}
|
|
2126
2415
|
/** Whether a Jest setting is given: `null` and `undefined` leave Jest's default, as a `testMatch: null` beside `testRegex`. */
|
|
2127
2416
|
function isJestSet(setting) {
|