test-inventory 0.11.1 → 0.12.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 +20 -0
- package/README.md +2 -1
- package/dist/config-runs.js +9 -6
- package/dist/dependency-hash.d.ts +9 -0
- package/dist/dependency-hash.js +43 -5
- package/dist/diff.js +4 -3
- package/dist/filter.d.ts +1 -1
- package/dist/filter.js +16 -1
- package/dist/frameworks/test-functions.js +3 -1
- package/dist/inventory-input.d.ts +1 -1
- package/dist/inventory-input.js +8 -0
- package/dist/module-globs.d.ts +7 -0
- package/dist/module-globs.js +80 -0
- package/dist/node-scripts.d.ts +2 -0
- package/dist/node-scripts.js +2 -0
- package/dist/records.js +1 -0
- package/dist/scan.js +1 -1
- package/dist/types.d.ts +2 -0
- package/package.json +6 -6
- package/schema/diff-v1.json +14 -0
- package/schema/v1.json +11 -0
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,25 @@
|
|
|
1
1
|
# test-inventory
|
|
2
2
|
|
|
3
|
+
## 0.12.1
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- [#157](https://github.com/Huldoser/test-inventory/pull/157) [`dafab8b`](https://github.com/Huldoser/test-inventory/commit/dafab8b7108fa9ee58b107e016be13a0837db5af) - Discover Playwright specs when a package script runs `playwright test` without a config file. Default file matching and ignore rules apply from the package folder.
|
|
8
|
+
|
|
9
|
+
- [#157](https://github.com/Huldoser/test-inventory/pull/157) [`dafab8b`](https://github.com/Huldoser/test-inventory/commit/dafab8b7108fa9ee58b107e016be13a0837db5af) - Update oxc-parser to 0.160.0 for TypeScript parsing fixes, including comparisons after `as` and `satisfies`.
|
|
10
|
+
|
|
11
|
+
- [#157](https://github.com/Huldoser/test-inventory/pull/157) [`dafab8b`](https://github.com/Huldoser/test-inventory/commit/dafab8b7108fa9ee58b107e016be13a0837db5af) - Recognize a re-exported Vitest test called with a title, options, a body and an extra argument.
|
|
12
|
+
|
|
13
|
+
## 0.12.0
|
|
14
|
+
|
|
15
|
+
### Minor Changes
|
|
16
|
+
|
|
17
|
+
- [#152](https://github.com/Huldoser/test-inventory/pull/152) [`271bb7d`](https://github.com/Huldoser/test-inventory/commit/271bb7d8e2eca630c5eeac4dbb567ba565e38855) - Track files selected by relative literal Vite module globs in Vitest scans. Test records store the pattern groups in `dependencyGlobs`, so filtering a saved inventory can select tests for newly added or deleted matching files. Node ESM imports with a fixed relative filename and a dynamic query now track the source file.
|
|
18
|
+
|
|
19
|
+
### Patch Changes
|
|
20
|
+
|
|
21
|
+
- [#151](https://github.com/Huldoser/test-inventory/pull/151) [`4d404b9`](https://github.com/Huldoser/test-inventory/commit/4d404b93f83f9a11540a74cf571b32a933008e8b) - Resolve Vitest project paths and globs from the configured root. Report unknown project membership when the root cannot be read, so the scan no longer says those files will be skipped.
|
|
22
|
+
|
|
3
23
|
## 0.11.1
|
|
4
24
|
|
|
5
25
|
### Patch Changes
|
package/README.md
CHANGED
|
@@ -38,7 +38,8 @@ npx test-inventory "tests/**/*.spec.ts" --framework playwright --output inventor
|
|
|
38
38
|
```
|
|
39
39
|
|
|
40
40
|
Without the glob, the test files are those the project's Playwright, Vitest, Jest, Mocha, Jasmine, Cypress or
|
|
41
|
-
WebdriverIO configs run, or for node:test and Bun the files `node --test` and `bun test` run.
|
|
41
|
+
WebdriverIO configs run, or for node:test and Bun the files `node --test` and `bun test` run. A package script running
|
|
42
|
+
plain `playwright test` also discovers Playwright specs without a config. Without `--framework`, the
|
|
42
43
|
scan takes the runner the project uses, and asks for `--framework` when it uses several.
|
|
43
44
|
|
|
44
45
|
For this spec from a trading app's UI tests, `tests/alerts.spec.ts`:
|
package/dist/config-runs.js
CHANGED
|
@@ -344,8 +344,8 @@ export class ConfigRuns {
|
|
|
344
344
|
if (config === null)
|
|
345
345
|
continue;
|
|
346
346
|
}
|
|
347
|
-
//
|
|
348
|
-
if (config === null && this.framework !== 'vitest')
|
|
347
|
+
// A plain Playwright test command and Vitest both collect tests without a config.
|
|
348
|
+
if (config === null && this.framework !== 'vitest' && !command.playwrightDefaults)
|
|
349
349
|
continue;
|
|
350
350
|
const key = `${config?.file ?? ''}\0${root}`;
|
|
351
351
|
if (seen.has(key))
|
|
@@ -1428,26 +1428,29 @@ export class ConfigRuns {
|
|
|
1428
1428
|
if (list.kind !== 'list') {
|
|
1429
1429
|
return [this.unknownProject(config, unknownAt(list), 'test.projects', this.vitestCandidates(config, folder))];
|
|
1430
1430
|
}
|
|
1431
|
+
const written = writtenRoot(config.settings);
|
|
1432
|
+
const root = typeof written === 'string' ? path.resolve(folder, written) : folder;
|
|
1431
1433
|
this.expanding.set(config, name);
|
|
1432
1434
|
const globs = [];
|
|
1433
1435
|
// Vitest names an inline project without a name after its place among the entries that aren't paths.
|
|
1434
1436
|
let index = 0;
|
|
1435
1437
|
const projects = list.items.flatMap((item) => {
|
|
1436
1438
|
if (item.kind === 'value' && typeof item.value === 'string') {
|
|
1437
|
-
|
|
1438
|
-
|
|
1439
|
+
if (written && typeof written !== 'string')
|
|
1440
|
+
return [this.unknownProject(config, written.setting, written.key)];
|
|
1441
|
+
const pattern = item.value.replace('<rootDir>', () => posix(root));
|
|
1439
1442
|
// Vitest globs every pattern and negation together, and reads a plain path as it is.
|
|
1440
1443
|
if (pattern.startsWith('!') || picomatch.scan(pattern).isGlob)
|
|
1441
1444
|
globs.push(pattern);
|
|
1442
1445
|
else
|
|
1443
|
-
return this.vitestPath(config, path.resolve(
|
|
1446
|
+
return this.vitestPath(config, path.resolve(root, pattern), container);
|
|
1444
1447
|
return [];
|
|
1445
1448
|
}
|
|
1446
1449
|
return this.vitestEntry(config, item, folder, String(index++), container);
|
|
1447
1450
|
});
|
|
1448
1451
|
const matches = globs.length
|
|
1449
1452
|
? globSync(globs, {
|
|
1450
|
-
cwd:
|
|
1453
|
+
cwd: root,
|
|
1451
1454
|
absolute: true,
|
|
1452
1455
|
dot: true,
|
|
1453
1456
|
onlyFiles: false,
|
|
@@ -58,6 +58,10 @@ interface Unit {
|
|
|
58
58
|
asks: string[] | null;
|
|
59
59
|
/** The snapshot matchers its code calls, which compare against files beside the test file. */
|
|
60
60
|
snapshots: SnapshotUse[];
|
|
61
|
+
globs?: {
|
|
62
|
+
patterns: string[];
|
|
63
|
+
files: string[];
|
|
64
|
+
}[];
|
|
61
65
|
hash: string | null | undefined;
|
|
62
66
|
}
|
|
63
67
|
/** A snapshot matcher a test's code calls, and the name or path it gives; null when it gives none the scan can read. */
|
|
@@ -95,6 +99,7 @@ interface Reach {
|
|
|
95
99
|
/** The fixtures the units' code asks for; null when some of it asks for all. */
|
|
96
100
|
asks: string[] | null;
|
|
97
101
|
snapshots: SnapshotUse[];
|
|
102
|
+
globs: string[][];
|
|
98
103
|
}
|
|
99
104
|
/** What several reaches cover together, by file. */
|
|
100
105
|
interface Merged {
|
|
@@ -128,12 +133,16 @@ export interface Dependencies {
|
|
|
128
133
|
files: string[];
|
|
129
134
|
/** The file and line of each place the test reaches that can't be followed, sorted. */
|
|
130
135
|
unfollowed: string[];
|
|
136
|
+
globs: string[][];
|
|
131
137
|
}
|
|
132
138
|
/**
|
|
133
139
|
* Follows what each test runs, across the files of one scan: its call, the code around it, and every declaration
|
|
134
140
|
* that code uses, in its own file and through imports. Each piece is read once per scan, however many tests reach it.
|
|
135
141
|
*/
|
|
136
142
|
export declare class DependencyGraph {
|
|
143
|
+
private readonly root;
|
|
144
|
+
private readonly framework;
|
|
145
|
+
constructor(root?: string | null, framework?: Framework | null);
|
|
137
146
|
private readonly modules;
|
|
138
147
|
private readonly units;
|
|
139
148
|
private readonly imports;
|
package/dist/dependency-hash.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import path from 'node:path';
|
|
2
|
+
import { moduleMatches, modulePatterns } from "./module-globs.js";
|
|
2
3
|
import { visitorKeys, } from 'oxc-parser';
|
|
3
4
|
import { childNodes, isFunctionNode, propertyKey, unwrap } from "./ast.js";
|
|
4
5
|
import { exportName, parseModule } from "./frameworks/bindings.js";
|
|
@@ -314,6 +315,12 @@ function isLoadCode(statement) {
|
|
|
314
315
|
* that code uses, in its own file and through imports. Each piece is read once per scan, however many tests reach it.
|
|
315
316
|
*/
|
|
316
317
|
export class DependencyGraph {
|
|
318
|
+
root;
|
|
319
|
+
framework;
|
|
320
|
+
constructor(root = null, framework = null) {
|
|
321
|
+
this.root = root;
|
|
322
|
+
this.framework = framework;
|
|
323
|
+
}
|
|
317
324
|
modules = new WeakMap();
|
|
318
325
|
units = [new WeakMap(), new WeakMap()];
|
|
319
326
|
imports = new WeakMap();
|
|
@@ -391,8 +398,16 @@ export class DependencyGraph {
|
|
|
391
398
|
const fixtures = [];
|
|
392
399
|
let asks = [];
|
|
393
400
|
const snapshots = [];
|
|
401
|
+
const globs = [];
|
|
394
402
|
for (const unit of units) {
|
|
395
403
|
snapshots.push(...unit.snapshots);
|
|
404
|
+
for (const glob of unit.globs ?? []) {
|
|
405
|
+
globs.push(glob.patterns);
|
|
406
|
+
// Vite exposes the file name as a key even when the module has no code to hash.
|
|
407
|
+
for (const file of glob.files)
|
|
408
|
+
if (!byFile.has(file))
|
|
409
|
+
byFile.set(file, []);
|
|
410
|
+
}
|
|
396
411
|
if (unit.place)
|
|
397
412
|
places.push(unit.place);
|
|
398
413
|
if (unit.fixtures)
|
|
@@ -413,7 +428,7 @@ export class DependencyGraph {
|
|
|
413
428
|
// Sorted by hash, so that moving code around in a file doesn't change it; each part keeps its own order.
|
|
414
429
|
for (const hashes of byFile.values())
|
|
415
430
|
hashes.sort();
|
|
416
|
-
return { units, byFile, places, fixtures, asks, snapshots };
|
|
431
|
+
return { units, byFile, places, fixtures, asks, snapshots, globs };
|
|
417
432
|
}
|
|
418
433
|
/**
|
|
419
434
|
* Everything a test's roots reach on top of `bases`, such as the code its file runs when loaded, which all its tests
|
|
@@ -514,7 +529,9 @@ export class DependencyGraph {
|
|
|
514
529
|
});
|
|
515
530
|
// Places on one line, as two imports a statement makes, are one entry.
|
|
516
531
|
const unfollowed = places.map((place) => `${place.relativeFilePath}:${place.source.position(start(place)).line}`);
|
|
517
|
-
|
|
532
|
+
const groups = new Map(reached.flatMap((r) => r.globs).map((group) => [JSON.stringify(group), group]));
|
|
533
|
+
const globs = [...groups.keys()].sort().map((key) => groups.get(key));
|
|
534
|
+
return { globs, hash: shortHash(`[${parts.join(',')}]`), files, unfollowed: [...new Set(unfollowed)] };
|
|
518
535
|
}
|
|
519
536
|
newModule(relativeFilePath, parsed, text, values, readModule) {
|
|
520
537
|
return {
|
|
@@ -1314,9 +1331,18 @@ export class DependencyGraph {
|
|
|
1314
1331
|
}
|
|
1315
1332
|
break;
|
|
1316
1333
|
}
|
|
1317
|
-
case 'ImportExpression':
|
|
1318
|
-
|
|
1334
|
+
case 'ImportExpression': {
|
|
1335
|
+
// In Node ESM the query distinguishes module instances while the pathname identifies their source.
|
|
1336
|
+
const prefix = this.framework === 'node' && node.source.type === 'TemplateLiteral'
|
|
1337
|
+
? node.source.quasis[0].value.cooked
|
|
1338
|
+
: null;
|
|
1339
|
+
const file = prefix?.match(/^(\.\.?\/[\w./-]+\.(?:mjs|js|cjs|json))\?/)?.[1];
|
|
1340
|
+
if (file)
|
|
1341
|
+
add(this.imported(module, file, '*', types, node));
|
|
1342
|
+
else
|
|
1343
|
+
loadsByPath(node.source, scopes, node);
|
|
1319
1344
|
break;
|
|
1345
|
+
}
|
|
1320
1346
|
case 'CallExpression': {
|
|
1321
1347
|
const { callee } = node;
|
|
1322
1348
|
asks(node, scopes);
|
|
@@ -1342,7 +1368,19 @@ export class DependencyGraph {
|
|
|
1342
1368
|
loadsByPath(node.arguments.at(0), scopes, node);
|
|
1343
1369
|
}
|
|
1344
1370
|
if (object.type === 'MetaProperty' && property.name.startsWith('glob')) {
|
|
1345
|
-
|
|
1371
|
+
const patterns = this.framework === 'vitest' && object.meta.name === 'import' && property.name === 'glob'
|
|
1372
|
+
? modulePatterns(node, module.relativeFilePath)
|
|
1373
|
+
: null;
|
|
1374
|
+
const files = patterns && this.root ? moduleMatches(this.root, patterns) : null;
|
|
1375
|
+
if (patterns && files) {
|
|
1376
|
+
(unit.globs ??= []).push({ patterns, files });
|
|
1377
|
+
for (const file of files) {
|
|
1378
|
+
const relative = path.posix.relative(path.posix.dirname(module.relativeFilePath), file);
|
|
1379
|
+
add(this.imported(module, relative.startsWith('../') ? relative : './' + relative, '*', types, node));
|
|
1380
|
+
}
|
|
1381
|
+
}
|
|
1382
|
+
else
|
|
1383
|
+
edges.add(this.placeUnit(module, node, "The modules this loads match a pattern, so dependencyHash doesn't cover them."));
|
|
1346
1384
|
}
|
|
1347
1385
|
}
|
|
1348
1386
|
break;
|
package/dist/diff.js
CHANGED
|
@@ -36,6 +36,7 @@ const CLASSIFIED = new Set([
|
|
|
36
36
|
'suitePath',
|
|
37
37
|
'bodyHash',
|
|
38
38
|
'dependencyHash',
|
|
39
|
+
'dependencyGlobs',
|
|
39
40
|
'state',
|
|
40
41
|
'tags',
|
|
41
42
|
'isActive',
|
|
@@ -94,7 +95,7 @@ function kindsOf(before, after, fields) {
|
|
|
94
95
|
kinds.push('renamed');
|
|
95
96
|
if (fields.includes('bodyHash'))
|
|
96
97
|
kinds.push('bodyChanged');
|
|
97
|
-
if (fields.includes('dependencyHash'))
|
|
98
|
+
if (fields.includes('dependencyHash') || fields.includes('dependencyGlobs'))
|
|
98
99
|
kinds.push('dependenciesChanged');
|
|
99
100
|
const disabled = (test) => ['skip', 'fixme', 'todo'].includes(test.state);
|
|
100
101
|
const runnable = (test) => ['active', 'expectedToFail'].includes(test.state);
|
|
@@ -119,8 +120,8 @@ function kindsOf(before, after, fields) {
|
|
|
119
120
|
* different tool versions are not compared; scan both revisions with one version for rename and body detection.
|
|
120
121
|
*/
|
|
121
122
|
export function diffInventories(before, after) {
|
|
122
|
-
checkInventory(before, 'before');
|
|
123
|
-
checkInventory(after, 'after');
|
|
123
|
+
before = checkInventory(before, 'before');
|
|
124
|
+
after = checkInventory(after, 'after');
|
|
124
125
|
if (before.framework !== after.framework)
|
|
125
126
|
throw new OptionsError('before and after must use the same framework. Scan both revisions with the same --framework.');
|
|
126
127
|
const hashesComparable = before.tool.version === after.tool.version;
|
package/dist/filter.d.ts
CHANGED
|
@@ -13,7 +13,7 @@ export interface InventoryFilter {
|
|
|
13
13
|
withoutReason?: boolean;
|
|
14
14
|
/**
|
|
15
15
|
* Keeps the tests a change to one of these files can affect: those whose `dependencies` include it, and those that
|
|
16
|
-
* reach code the scan can't follow (`hasUnfollowedDependencies`). Paths are from the project root, as
|
|
16
|
+
* reach a matching module glob or code the scan can't follow (`hasUnfollowedDependencies`). Paths are from the project root, as
|
|
17
17
|
* `dependencies` writes them. An empty list keeps only the tests the scan can't follow.
|
|
18
18
|
*/
|
|
19
19
|
related?: string[];
|
package/dist/filter.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import path from 'node:path';
|
|
2
|
+
import { globRelated } from "./module-globs.js";
|
|
2
3
|
import { checkObject, OptionsError } from "./options.js";
|
|
3
4
|
import { summarize } from "./summary.js";
|
|
4
5
|
const STATES = ['active', 'skip', 'fixme', 'todo', 'expectedToFail', 'notLoaded'];
|
|
@@ -16,6 +17,7 @@ const TEST_KEYS = Object.keys({
|
|
|
16
17
|
bodyHash: true,
|
|
17
18
|
dependencyHash: true,
|
|
18
19
|
dependencies: true,
|
|
20
|
+
dependencyGlobs: true,
|
|
19
21
|
hasUnfollowedDependencies: true,
|
|
20
22
|
unfollowedDependencies: true,
|
|
21
23
|
suiteId: true,
|
|
@@ -129,12 +131,25 @@ export function matcher(filter) {
|
|
|
129
131
|
const related = checked.related === undefined
|
|
130
132
|
? null
|
|
131
133
|
: new Set(list(checked.related, 'filter.related', null).map((file) => path.posix.normalize(file.replaceAll('\\', '/'))));
|
|
134
|
+
const groups = new Map();
|
|
135
|
+
const relatedGroup = (patterns) => {
|
|
136
|
+
const key = JSON.stringify(patterns);
|
|
137
|
+
let matches = groups.get(key);
|
|
138
|
+
if (matches === undefined) {
|
|
139
|
+
matches = globRelated(patterns, related);
|
|
140
|
+
groups.set(key, matches);
|
|
141
|
+
}
|
|
142
|
+
return matches;
|
|
143
|
+
};
|
|
132
144
|
return (test) => (states.length === 0 || states.includes(test.state)) &&
|
|
133
145
|
(tags.length === 0 || test.tags.some((tag) => tags.includes(tag))) &&
|
|
134
146
|
(grep === null || grep.test(test.fullName)) &&
|
|
135
147
|
(!only || test.isOnly) &&
|
|
136
148
|
(!withoutReason || (!test.isActive && !test.isNotLoaded && test.reason === null)) &&
|
|
137
|
-
(related === null ||
|
|
149
|
+
(related === null ||
|
|
150
|
+
test.hasUnfollowedDependencies ||
|
|
151
|
+
test.dependencies.some((file) => related.has(file)) ||
|
|
152
|
+
(test.dependencyGlobs ?? []).some(relatedGroup));
|
|
138
153
|
}
|
|
139
154
|
/**
|
|
140
155
|
* Keeps the tests that pass every condition of the filter; a list keeps a test that has any of its values. The
|
|
@@ -535,9 +535,11 @@ export class SuiteAdapter {
|
|
|
535
535
|
* so it doesn't depend on which call comes first.
|
|
536
536
|
*/
|
|
537
537
|
worthFollowing(name, chainLinks, args, held) {
|
|
538
|
+
// Vitest reads the title, options and body even when JavaScript supplies a fourth argument.
|
|
539
|
+
const declarationArgs = this.dialect.name === 'Vitest' && args.length > 3 ? args.slice(0, 3) : args;
|
|
538
540
|
return ((held && isTestName(name)) ||
|
|
539
541
|
this.looksLikeTest(chainLinks, args) ||
|
|
540
|
-
((chainLinks.length === 0 || isTestName(name)) && hasDeclarationArguments(
|
|
542
|
+
((chainLinks.length === 0 || isTestName(name)) && hasDeclarationArguments(declarationArgs)));
|
|
541
543
|
}
|
|
542
544
|
/** The framework as followed modules are read. */
|
|
543
545
|
framework() {
|
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
import type { Inventory } from './types.ts';
|
|
2
2
|
/** Validates a saved scan before a diff reads its records; projected records and JSON Lines are not full scans. */
|
|
3
|
-
export declare function checkInventory(value: unknown, name: string):
|
|
3
|
+
export declare function checkInventory(value: unknown, name: string): Inventory;
|
package/dist/inventory-input.js
CHANGED
|
@@ -45,6 +45,13 @@ function matches(value, rule) {
|
|
|
45
45
|
}
|
|
46
46
|
/** Validates a saved scan before a diff reads its records; projected records and JSON Lines are not full scans. */
|
|
47
47
|
export function checkInventory(value, name) {
|
|
48
|
+
// Older complete v1 records predate dependencyGlobs. A saved scan can be shared with another caller.
|
|
49
|
+
if (value && typeof value === 'object' && 'tests' in value && Array.isArray(value.tests)) {
|
|
50
|
+
value = {
|
|
51
|
+
...value,
|
|
52
|
+
tests: value.tests.map((test) => test && typeof test === 'object' && !('dependencyGlobs' in test) ? { ...test, dependencyGlobs: [] } : test),
|
|
53
|
+
};
|
|
54
|
+
}
|
|
48
55
|
let valid = false;
|
|
49
56
|
try {
|
|
50
57
|
JSON.stringify(value);
|
|
@@ -59,4 +66,5 @@ export function checkInventory(value, name) {
|
|
|
59
66
|
const ids = new Set(inventory.tests.map((test) => test.id));
|
|
60
67
|
if (ids.size !== inventory.tests.length)
|
|
61
68
|
throw new OptionsError(`${name} contains duplicate test ids. Scan it again without combining inventories.`);
|
|
69
|
+
return inventory;
|
|
62
70
|
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { CallExpression } from 'oxc-parser';
|
|
2
|
+
/** One Vite glob call, with root-relative positive and negative patterns kept together. */
|
|
3
|
+
export declare function modulePatterns(call: CallExpression, from: string): string[] | null;
|
|
4
|
+
/** Keep symlinked and unreadable trees unknown. Vite can include files beyond what the scan may read. */
|
|
5
|
+
export declare function moduleMatches(root: string, patterns: string[]): string[] | null;
|
|
6
|
+
/** Whether a changed path belongs to this saved call, including one added after the scan. */
|
|
7
|
+
export declare function globRelated(patterns: string[], files: Set<string>): boolean;
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
import { readdirSync, realpathSync } from 'node:fs';
|
|
2
|
+
import path from 'node:path';
|
|
3
|
+
import picomatch from 'picomatch';
|
|
4
|
+
import { globSync } from 'tinyglobby';
|
|
5
|
+
/** One Vite glob call, with root-relative positive and negative patterns kept together. */
|
|
6
|
+
export function modulePatterns(call, from) {
|
|
7
|
+
const first = call.arguments.at(0);
|
|
8
|
+
const options = call.arguments.at(1);
|
|
9
|
+
if (options &&
|
|
10
|
+
(call.arguments.length !== 2 ||
|
|
11
|
+
options.type !== 'ObjectExpression' ||
|
|
12
|
+
!options.properties.every((p) => p.type === 'Property' &&
|
|
13
|
+
!p.computed &&
|
|
14
|
+
p.key.type === 'Identifier' &&
|
|
15
|
+
p.key.name === 'eager' &&
|
|
16
|
+
p.value.type === 'Literal' &&
|
|
17
|
+
typeof p.value.value === 'boolean')))
|
|
18
|
+
return null;
|
|
19
|
+
const items = first?.type === 'ArrayExpression' ? first.elements : [first];
|
|
20
|
+
const patterns = [];
|
|
21
|
+
for (const item of items) {
|
|
22
|
+
if (item?.type !== 'Literal' || typeof item.value !== 'string')
|
|
23
|
+
return null;
|
|
24
|
+
const negative = item.value.startsWith('!');
|
|
25
|
+
const literal = negative ? item.value.slice(1) : item.value;
|
|
26
|
+
if (!/^\.\.?\//.test(literal) ||
|
|
27
|
+
!/^[\w./*-]+$/.test(literal) ||
|
|
28
|
+
literal
|
|
29
|
+
.replace(/^(?:\.\.?\/)+/, '')
|
|
30
|
+
.split('/')
|
|
31
|
+
.includes('..'))
|
|
32
|
+
return null;
|
|
33
|
+
const target = path.posix.join(path.posix.dirname(from), literal);
|
|
34
|
+
if (target.split('/').some((segment) => segment.startsWith('.') || segment === 'node_modules') ||
|
|
35
|
+
!/^[\w./*-]+$/.test(target))
|
|
36
|
+
return null;
|
|
37
|
+
patterns.push((negative ? '!' : '') + target);
|
|
38
|
+
}
|
|
39
|
+
if (!patterns.some((p) => !p.startsWith('!')) || !/^[\w./-]+$/.test(from))
|
|
40
|
+
return null;
|
|
41
|
+
return [...new Set([...patterns, '!' + from])].sort();
|
|
42
|
+
}
|
|
43
|
+
/** Keep symlinked and unreadable trees unknown. Vite can include files beyond what the scan may read. */
|
|
44
|
+
export function moduleMatches(root, patterns) {
|
|
45
|
+
const unreadable = new Set();
|
|
46
|
+
const files = globSync(patterns, {
|
|
47
|
+
cwd: root,
|
|
48
|
+
expandDirectories: false,
|
|
49
|
+
extglob: false,
|
|
50
|
+
followSymbolicLinks: false,
|
|
51
|
+
ignore: ['**/node_modules/**'],
|
|
52
|
+
fs: {
|
|
53
|
+
readdirSync: ((folder) => {
|
|
54
|
+
try {
|
|
55
|
+
if (path.relative(realpathSync(root), realpathSync(folder)) !== path.relative(root, folder)) {
|
|
56
|
+
unreadable.add(folder);
|
|
57
|
+
return [];
|
|
58
|
+
}
|
|
59
|
+
const entries = readdirSync(folder, { withFileTypes: true });
|
|
60
|
+
if (entries.some((e) => e.isSymbolicLink()))
|
|
61
|
+
unreadable.add(folder);
|
|
62
|
+
return entries;
|
|
63
|
+
}
|
|
64
|
+
catch {
|
|
65
|
+
unreadable.add(folder);
|
|
66
|
+
return [];
|
|
67
|
+
}
|
|
68
|
+
}),
|
|
69
|
+
},
|
|
70
|
+
});
|
|
71
|
+
return unreadable.size > 0 || files.some((f) => /[?#\\]/.test(f)) ? null : files.sort();
|
|
72
|
+
}
|
|
73
|
+
/** Whether a changed path belongs to this saved call, including one added after the scan. */
|
|
74
|
+
export function globRelated(patterns, files) {
|
|
75
|
+
const include = picomatch(patterns.filter((p) => !p.startsWith('!')), {
|
|
76
|
+
noext: true,
|
|
77
|
+
ignore: [...patterns.filter((p) => p.startsWith('!')).map((p) => p.slice(1)), '**/node_modules/**'],
|
|
78
|
+
});
|
|
79
|
+
return [...files].some((file) => include(file));
|
|
80
|
+
}
|
package/dist/node-scripts.d.ts
CHANGED
|
@@ -19,6 +19,8 @@ export interface RunnerCommand {
|
|
|
19
19
|
root: string | null;
|
|
20
20
|
/** Whether it names its config or root in a way the scan can't read: a variable, or Jest's inline JSON. */
|
|
21
21
|
unreadable: boolean;
|
|
22
|
+
/** A plain playwright test command collects its default files even without a config. */
|
|
23
|
+
playwrightDefaults?: true;
|
|
22
24
|
/** For Mocha, which takes its files and settings from them, the words after the program. */
|
|
23
25
|
args?: string[];
|
|
24
26
|
}
|
package/dist/node-scripts.js
CHANGED
|
@@ -216,6 +216,8 @@ export function runnerCommands(script, runner) {
|
|
|
216
216
|
args = args.slice(1);
|
|
217
217
|
}
|
|
218
218
|
const command = { config: null, root: null, unreadable: false };
|
|
219
|
+
if (started.program === 'playwright' && args.length === 0)
|
|
220
|
+
command.playwrightDefaults = true;
|
|
219
221
|
if (runner === 'mocha')
|
|
220
222
|
command.args = args;
|
|
221
223
|
if (runner === 'webdriverio') {
|
package/dist/records.js
CHANGED
|
@@ -560,6 +560,7 @@ class RecordBuilder {
|
|
|
560
560
|
dependencyHash: dependencies.hash,
|
|
561
561
|
dependencies: dependencies.files,
|
|
562
562
|
hasUnfollowedDependencies: dependencies.unfollowed.length > 0,
|
|
563
|
+
dependencyGlobs: dependencies.globs,
|
|
563
564
|
unfollowedDependencies: dependencies.unfollowed,
|
|
564
565
|
suiteId: describes.length > 0 ? this.suiteIds.get(describes[describes.length - 1]) : null,
|
|
565
566
|
parentTestId: null,
|
package/dist/scan.js
CHANGED
|
@@ -179,7 +179,7 @@ export async function scan(options) {
|
|
|
179
179
|
const projectDiagnostics = versionDiagnostics(framework, frameworkVersion, source, range);
|
|
180
180
|
projectDiagnostics.push(...found.diagnostics);
|
|
181
181
|
const readerFor = moduleResolver(root);
|
|
182
|
-
const graph = new DependencyGraph();
|
|
182
|
+
const graph = new DependencyGraph(root, framework);
|
|
183
183
|
const exports = new ExportedValues();
|
|
184
184
|
const configs = new Configs(root, framework, readerFor, rules);
|
|
185
185
|
const runs = new ConfigRuns(configs, framework, rules, patterns === null);
|
package/dist/types.d.ts
CHANGED
|
@@ -276,6 +276,8 @@ export interface TestRecord {
|
|
|
276
276
|
dependencies: string[];
|
|
277
277
|
/** Something the test reaches couldn't be followed, so a change there doesn't change `dependencyHash`. */
|
|
278
278
|
hasUnfollowedDependencies: boolean;
|
|
279
|
+
/** Root-relative Vite module patterns, grouped by call. Within each group a leading ! excludes matching paths. */
|
|
280
|
+
dependencyGlobs: string[][];
|
|
279
281
|
/**
|
|
280
282
|
* Where the test reaches what couldn't be followed: the file and line of each place, as `support/venues.ts:2`, sorted;
|
|
281
283
|
* empty when `hasUnfollowedDependencies` is false. A `dependency-not-followed` warning at the place says what it is.
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "test-inventory",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.12.1",
|
|
4
4
|
"description": "Lists every Playwright, Vitest, Jest, Mocha, Jasmine, Cypress, WebdriverIO, node:test and Bun test from the source code, without running it: its state and why, tags, an id that survives a move, a hash of everything it runs, and the tests a change can affect.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"testing",
|
|
@@ -80,14 +80,14 @@
|
|
|
80
80
|
"lint:fix": "eslint . --fix",
|
|
81
81
|
"format": "prettier --write . --ignore-path .gitignore --ignore-path .prettierignore --ignore-path .git/info/exclude",
|
|
82
82
|
"format:check": "node scripts/format-check.ts",
|
|
83
|
-
"docs:api": "typedoc",
|
|
83
|
+
"docs:api": "cd scripts/typedoc && typedoc --options ../../typedoc.json",
|
|
84
84
|
"docs:dev": "npm run docs:api && vitepress dev docs",
|
|
85
85
|
"docs:build": "npm run docs:api && vitepress build docs",
|
|
86
86
|
"docs:preview": "vitepress preview docs",
|
|
87
87
|
"changeset": "changeset"
|
|
88
88
|
},
|
|
89
89
|
"dependencies": {
|
|
90
|
-
"oxc-parser": "0.
|
|
90
|
+
"oxc-parser": "0.160.0",
|
|
91
91
|
"picomatch": "^4.0.7",
|
|
92
92
|
"tinyglobby": "^0.2.17"
|
|
93
93
|
},
|
|
@@ -102,7 +102,7 @@
|
|
|
102
102
|
"eslint": "~10.15.0",
|
|
103
103
|
"prettier": "3.10.1",
|
|
104
104
|
"publint": "^0.3.25",
|
|
105
|
-
"ts-json-schema-generator": "2.
|
|
105
|
+
"ts-json-schema-generator": "2.10.0",
|
|
106
106
|
"typedoc": "^0.28.20",
|
|
107
107
|
"typedoc-plugin-markdown": "^4.14.1",
|
|
108
108
|
"typedoc-vitepress-theme": "^1.1.4",
|
|
@@ -113,8 +113,8 @@
|
|
|
113
113
|
"vitest": "5.1.1"
|
|
114
114
|
},
|
|
115
115
|
"overrides": {
|
|
116
|
-
"
|
|
117
|
-
"
|
|
116
|
+
"typedoc": {
|
|
117
|
+
"minimatch": "^11.0.9"
|
|
118
118
|
},
|
|
119
119
|
"vitepress-plugin-llms": {
|
|
120
120
|
"minimatch": "^11.0.9"
|
package/schema/diff-v1.json
CHANGED
|
@@ -201,6 +201,7 @@
|
|
|
201
201
|
"dependencyHash",
|
|
202
202
|
"dependencies",
|
|
203
203
|
"hasUnfollowedDependencies",
|
|
204
|
+
"dependencyGlobs",
|
|
204
205
|
"unfollowedDependencies",
|
|
205
206
|
"suiteId",
|
|
206
207
|
"parentTestId",
|
|
@@ -307,6 +308,7 @@
|
|
|
307
308
|
"dependencyHash",
|
|
308
309
|
"dependencies",
|
|
309
310
|
"hasUnfollowedDependencies",
|
|
311
|
+
"dependencyGlobs",
|
|
310
312
|
"unfollowedDependencies",
|
|
311
313
|
"suiteId",
|
|
312
314
|
"parentTestId",
|
|
@@ -413,6 +415,7 @@
|
|
|
413
415
|
"dependencyHash",
|
|
414
416
|
"dependencies",
|
|
415
417
|
"hasUnfollowedDependencies",
|
|
418
|
+
"dependencyGlobs",
|
|
416
419
|
"unfollowedDependencies",
|
|
417
420
|
"suiteId",
|
|
418
421
|
"parentTestId",
|
|
@@ -548,6 +551,16 @@
|
|
|
548
551
|
"type": "boolean",
|
|
549
552
|
"description": "Something the test reaches couldn't be followed, so a change there doesn't change `dependencyHash`."
|
|
550
553
|
},
|
|
554
|
+
"dependencyGlobs": {
|
|
555
|
+
"type": "array",
|
|
556
|
+
"items": {
|
|
557
|
+
"type": "array",
|
|
558
|
+
"items": {
|
|
559
|
+
"type": "string"
|
|
560
|
+
}
|
|
561
|
+
},
|
|
562
|
+
"description": "Root-relative Vite module patterns, grouped by call. Within each group a leading ! excludes matching paths."
|
|
563
|
+
},
|
|
551
564
|
"unfollowedDependencies": {
|
|
552
565
|
"type": "array",
|
|
553
566
|
"items": {
|
|
@@ -989,6 +1002,7 @@
|
|
|
989
1002
|
"dependencyHash",
|
|
990
1003
|
"dependencies",
|
|
991
1004
|
"hasUnfollowedDependencies",
|
|
1005
|
+
"dependencyGlobs",
|
|
992
1006
|
"unfollowedDependencies",
|
|
993
1007
|
"suiteId",
|
|
994
1008
|
"parentTestId",
|
package/schema/v1.json
CHANGED
|
@@ -790,6 +790,16 @@
|
|
|
790
790
|
"type": "boolean",
|
|
791
791
|
"description": "Something the test reaches couldn't be followed, so a change there doesn't change `dependencyHash`."
|
|
792
792
|
},
|
|
793
|
+
"dependencyGlobs": {
|
|
794
|
+
"type": "array",
|
|
795
|
+
"items": {
|
|
796
|
+
"type": "array",
|
|
797
|
+
"items": {
|
|
798
|
+
"type": "string"
|
|
799
|
+
}
|
|
800
|
+
},
|
|
801
|
+
"description": "Root-relative Vite module patterns, grouped by call. Within each group a leading ! excludes matching paths."
|
|
802
|
+
},
|
|
793
803
|
"unfollowedDependencies": {
|
|
794
804
|
"type": "array",
|
|
795
805
|
"items": {
|
|
@@ -1231,6 +1241,7 @@
|
|
|
1231
1241
|
"dependencyHash",
|
|
1232
1242
|
"dependencies",
|
|
1233
1243
|
"hasUnfollowedDependencies",
|
|
1244
|
+
"dependencyGlobs",
|
|
1234
1245
|
"unfollowedDependencies",
|
|
1235
1246
|
"suiteId",
|
|
1236
1247
|
"parentTestId",
|