test-inventory 0.10.4 → 0.11.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +106 -0
- package/README.md +6 -4
- package/dist/cli.d.ts +1 -1
- 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 +2 -0
- 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/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 +21 -3
- package/dist/values.js +112 -13
- package/package.json +1 -1
- package/schema/diff-v1.json +12 -1
- package/schema/v1.json +9 -1
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
/** An argument as a POSIX shell reads it back: quoted when it holds anything but plain path characters. */
|
|
2
|
+
function quote(argument) {
|
|
3
|
+
return /^[\w./@:+=,-]+$/.test(argument) ? argument : `'${argument.replaceAll("'", "'\\''")}'`;
|
|
4
|
+
}
|
|
5
|
+
/** The arguments of the command for one runner, and its caveat. */
|
|
6
|
+
function commandFor(framework, config, projects, files) {
|
|
7
|
+
const withConfig = (flag) => (config === null ? [] : [flag, config]);
|
|
8
|
+
switch (framework) {
|
|
9
|
+
case 'vitest':
|
|
10
|
+
return {
|
|
11
|
+
args: [
|
|
12
|
+
'npx',
|
|
13
|
+
'vitest',
|
|
14
|
+
'run',
|
|
15
|
+
...files,
|
|
16
|
+
...withConfig('--config'),
|
|
17
|
+
...projects.flatMap((p) => ['--project', p]),
|
|
18
|
+
],
|
|
19
|
+
caveat: null,
|
|
20
|
+
};
|
|
21
|
+
case 'jest': {
|
|
22
|
+
const selected = projects.length > 0 ? ['--selectProjects', ...projects] : [];
|
|
23
|
+
return {
|
|
24
|
+
args: ['npx', 'jest', ...withConfig('--config'), ...selected, '--runTestsByPath', ...files],
|
|
25
|
+
caveat: null,
|
|
26
|
+
};
|
|
27
|
+
}
|
|
28
|
+
case 'playwright': {
|
|
29
|
+
// `--project` takes every name after it, so the files come first.
|
|
30
|
+
const selected = projects.length > 0 ? ['--project', ...projects] : [];
|
|
31
|
+
return { args: ['npx', 'playwright', 'test', ...files, ...withConfig('--config'), ...selected], caveat: null };
|
|
32
|
+
}
|
|
33
|
+
case 'mocha':
|
|
34
|
+
return {
|
|
35
|
+
args: ['npx', 'mocha', ...withConfig(config?.endsWith('package.json') ? '--package' : '--config'), ...files],
|
|
36
|
+
caveat: config === null
|
|
37
|
+
? null
|
|
38
|
+
: 'Mocha adds the files to the spec of the config, so every spec the config lists runs too.',
|
|
39
|
+
};
|
|
40
|
+
case 'jasmine':
|
|
41
|
+
return { args: ['npx', 'jasmine', ...(config === null ? [] : [`--config=${config}`]), ...files], caveat: null };
|
|
42
|
+
case 'cypress':
|
|
43
|
+
return {
|
|
44
|
+
args: [
|
|
45
|
+
'npx',
|
|
46
|
+
'cypress',
|
|
47
|
+
'run',
|
|
48
|
+
...withConfig('--config-file'),
|
|
49
|
+
...(projects.includes('component') ? ['--component'] : []),
|
|
50
|
+
'--spec',
|
|
51
|
+
files.join(','),
|
|
52
|
+
],
|
|
53
|
+
caveat: null,
|
|
54
|
+
};
|
|
55
|
+
case 'webdriverio':
|
|
56
|
+
return {
|
|
57
|
+
args: [
|
|
58
|
+
'npx',
|
|
59
|
+
'wdio',
|
|
60
|
+
'run',
|
|
61
|
+
...(config === null ? [] : [config]),
|
|
62
|
+
...files.flatMap((file) => ['--spec', file]),
|
|
63
|
+
],
|
|
64
|
+
caveat: config === null
|
|
65
|
+
? "No WebdriverIO config was found, and 'wdio run' needs one, as in 'npx wdio run wdio.conf.ts'."
|
|
66
|
+
: null,
|
|
67
|
+
};
|
|
68
|
+
case 'node':
|
|
69
|
+
// node --test reads each argument as a glob; a character in brackets stands for itself.
|
|
70
|
+
return { args: ['node', '--test', ...files.map((file) => file.replace(/[[\]*?{}]/g, '[$&]'))], caveat: null };
|
|
71
|
+
case 'bun':
|
|
72
|
+
// Without `./`, Bun takes an argument as part of a name to look for.
|
|
73
|
+
return { args: ['bun', 'test', ...files.map((file) => `./${file}`)], caveat: null };
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
/**
|
|
77
|
+
* The commands that run the tests an inventory keeps, as after `filterInventory()` with `related`: one for each config,
|
|
78
|
+
* and for Cypress one for each testing type, with the projects that run the tests, sorted by config. A test whose
|
|
79
|
+
* projects are unknown runs in every project of its config.
|
|
80
|
+
*/
|
|
81
|
+
export function runCommands(inventory) {
|
|
82
|
+
const configs = new Map(inventory.files.map((file) => [file.relativeFilePath, file.config]));
|
|
83
|
+
const groups = new Map();
|
|
84
|
+
for (const test of inventory.tests) {
|
|
85
|
+
const config = configs.get(test.relativeFilePath) ?? null;
|
|
86
|
+
// Cypress runs one testing type at a time.
|
|
87
|
+
const type = inventory.framework === 'cypress' ? (test.projects?.join(',') ?? '') : '';
|
|
88
|
+
const key = `${config ?? ''}\0${type}`;
|
|
89
|
+
const group = groups.get(key) ?? { config, files: new Set(), projects: new Set(), all: false };
|
|
90
|
+
groups.set(key, group);
|
|
91
|
+
group.files.add(test.relativeFilePath);
|
|
92
|
+
if (test.projects === null)
|
|
93
|
+
group.all = true;
|
|
94
|
+
// A config without projects has one with an empty name, which no flag selects.
|
|
95
|
+
for (const name of test.projects ?? [])
|
|
96
|
+
if (name !== '')
|
|
97
|
+
group.projects.add(name);
|
|
98
|
+
}
|
|
99
|
+
return [...groups.entries()]
|
|
100
|
+
.sort(([a], [b]) => (a < b ? -1 : 1))
|
|
101
|
+
.map(([, group]) => {
|
|
102
|
+
const projects = group.all ? [] : [...group.projects].sort();
|
|
103
|
+
const files = [...group.files].sort();
|
|
104
|
+
const { args, caveat } = commandFor(inventory.framework, group.config, projects, files);
|
|
105
|
+
return { config: group.config, projects, files, command: args.map(quote).join(' '), caveat };
|
|
106
|
+
});
|
|
107
|
+
}
|
package/dist/scan.js
CHANGED
|
@@ -10,7 +10,7 @@ import { DependencyGraph } from "./dependency-hash.js";
|
|
|
10
10
|
import { ExportedValues } from "./imported-values.js";
|
|
11
11
|
import { fileDiagnostic } from "./diagnostics.js";
|
|
12
12
|
import { findFiles, normalizePattern, readFailure } from "./files.js";
|
|
13
|
-
import { detectFramework, detectFrameworkVersion, FRAMEWORK_NAMES, OLDEST } from "./framework-version.js";
|
|
13
|
+
import { configFolderBelow, detectFramework, detectFrameworkVersion, FRAMEWORK_NAMES, OLDEST, } from "./framework-version.js";
|
|
14
14
|
import { createInventory } from "./inventory.js";
|
|
15
15
|
import { checkComments, checkFlag, checkFramework, checkObject, checkSignal, checkStrings, checkVersion, invalid, majorMinor, toPosixPath, } from "./options.js";
|
|
16
16
|
import { moduleResolver } from "./resolve.js";
|
|
@@ -121,7 +121,7 @@ function bytesOf(root, file) {
|
|
|
121
121
|
}
|
|
122
122
|
}
|
|
123
123
|
/** Why a scan found no test files: what the patterns matched, or whether there is a config to find them from. */
|
|
124
|
-
function noFiles(root, patterns, framework, placements) {
|
|
124
|
+
function noFiles(root, patterns, framework, placements, ignore) {
|
|
125
125
|
if (patterns) {
|
|
126
126
|
const list = patterns.map((pattern) => `"${pattern}"`).join(', ');
|
|
127
127
|
return `No test files match ${list} in the root.${folderHint(root, patterns, framework)}`;
|
|
@@ -133,7 +133,12 @@ function noFiles(root, patterns, framework, placements) {
|
|
|
133
133
|
return "No patterns were given, and no file in the root matches what node --test runs: Node.js's default patterns, or the files a package.json script gives it.";
|
|
134
134
|
}
|
|
135
135
|
const name = FRAMEWORK_NAMES[framework];
|
|
136
|
-
|
|
136
|
+
const below = configFolderBelow(root, framework, ignore);
|
|
137
|
+
if (below === undefined) {
|
|
138
|
+
return `No patterns were given, and no ${name} config is in the root or a folder below it, so there are no test files to find.`;
|
|
139
|
+
}
|
|
140
|
+
const none = `No patterns were given, and no ${name} config is in the root, the only place the scan reads it from, so there are no test files to find.`;
|
|
141
|
+
return below === null ? none : `${none} There is one in ${below}: scan that folder, or give patterns.`;
|
|
137
142
|
}
|
|
138
143
|
/**
|
|
139
144
|
* Scans the test files that match `patterns` under `root`, or without patterns those the configs run, one file at a
|
|
@@ -179,7 +184,12 @@ export async function scan(options) {
|
|
|
179
184
|
const configs = new Configs(root, framework, readerFor, rules);
|
|
180
185
|
const runs = new ConfigRuns(configs, framework, rules, patterns === null);
|
|
181
186
|
const placements = new Map(found.files.map((file) => [file.absolutePath, runs.placementOf(file.absolutePath)]));
|
|
182
|
-
const files = patterns
|
|
187
|
+
const files = patterns
|
|
188
|
+
? found.files
|
|
189
|
+
: found.files.filter((file) => {
|
|
190
|
+
const placement = placements.get(file.absolutePath);
|
|
191
|
+
return Boolean(placement.runs) || placement.candidate === true;
|
|
192
|
+
});
|
|
183
193
|
// A setup project's files may be outside the patterns, or ignored for the scan, so they are looked for in its testDir.
|
|
184
194
|
const setupDirs = new Set();
|
|
185
195
|
for (const { config, projects } of placements.values()) {
|
|
@@ -286,7 +296,7 @@ export async function scan(options) {
|
|
|
286
296
|
projectDiagnostics.push(...configs.diagnostics, ...neverRun, ...(globals ? [globals] : []));
|
|
287
297
|
// After the config warnings, which may say why no file was found.
|
|
288
298
|
if (files.length === 0) {
|
|
289
|
-
projectDiagnostics.push(fileDiagnostic('no-files-matched', '.', noFiles(root, patterns, framework, placements)));
|
|
299
|
+
projectDiagnostics.push(fileDiagnostic('no-files-matched', '.', noFiles(root, patterns, framework, placements, ignore)));
|
|
290
300
|
}
|
|
291
301
|
const fileCount = files.length;
|
|
292
302
|
const records = configs.records((config) => runs.projectsIn(config));
|
package/dist/types.d.ts
CHANGED
|
@@ -261,7 +261,10 @@ export interface SuiteRecord {
|
|
|
261
261
|
export interface TestRecord {
|
|
262
262
|
/** Derived from the file path, the describe titles, the title and its position among tests with the same title. */
|
|
263
263
|
id: Hash;
|
|
264
|
-
/**
|
|
264
|
+
/**
|
|
265
|
+
* Hash of the test body, ignoring whitespace and comments: the test function, one passed by name, or the one a wrapper
|
|
266
|
+
* call receives; null when the test has none of these.
|
|
267
|
+
*/
|
|
265
268
|
bodyHash: Hash | null;
|
|
266
269
|
/**
|
|
267
270
|
* Hash of everything the test runs in the project: its call, the hooks, options and code of the file and of every
|
|
@@ -273,6 +276,11 @@ export interface TestRecord {
|
|
|
273
276
|
dependencies: string[];
|
|
274
277
|
/** Something the test reaches couldn't be followed, so a change there doesn't change `dependencyHash`. */
|
|
275
278
|
hasUnfollowedDependencies: boolean;
|
|
279
|
+
/**
|
|
280
|
+
* Where the test reaches what couldn't be followed: the file and line of each place, as `support/venues.ts:2`, sorted;
|
|
281
|
+
* empty when `hasUnfollowedDependencies` is false. A `dependency-not-followed` warning at the place says what it is.
|
|
282
|
+
*/
|
|
283
|
+
unfollowedDependencies: string[];
|
|
276
284
|
/** The nearest describe; null outside any describe. */
|
|
277
285
|
suiteId: Hash | null;
|
|
278
286
|
/**
|
package/dist/values.d.ts
CHANGED
|
@@ -32,10 +32,11 @@ export declare class Values {
|
|
|
32
32
|
/**
|
|
33
33
|
* Runs `read` with a function's parameters bound to the arguments of one call, worked out where the call is, so that
|
|
34
34
|
* titles and values built from them resolve, as in `test(\`${side} rejects a zero quantity\`)` inside
|
|
35
|
-
* `validatesQuantity('buy')`. `args` stop at a spread argument, after which no position is known
|
|
36
|
-
* takes the parameter's default value, worked out in `scopes`, the scopes around the
|
|
35
|
+
* `validatesQuantity('buy')`. `args` stop at a spread argument, after which no position is known, and `complete` is
|
|
36
|
+
* false then. A missing argument takes the parameter's default value, worked out in `scopes`, the scopes around the
|
|
37
|
+
* function. A rest parameter, as `...cycles`, holds the arguments left.
|
|
37
38
|
*/
|
|
38
|
-
withArguments<T>(fn: FunctionNode, args: readonly Resolved[], scopes: readonly Node[], read: () => T): T;
|
|
39
|
+
withArguments<T>(fn: FunctionNode, args: readonly Resolved[], scopes: readonly Node[], read: () => T, complete?: boolean): T;
|
|
39
40
|
/**
|
|
40
41
|
* Runs `read` with the names a loop declares bound to one of the values it goes over, as in
|
|
41
42
|
* `for (const [tier, bps] of Object.entries(FEES))`. `declarator` is the loop's variable declarator.
|
|
@@ -60,6 +61,11 @@ export declare class Values {
|
|
|
60
61
|
* A parameter is not its function, though the function declares it.
|
|
61
62
|
*/
|
|
62
63
|
functionOf(name: string, scopes: readonly Node[]): FunctionNode | null;
|
|
64
|
+
/** `functionOf()`, with the scopes around the function's declaration, in which its body is read. */
|
|
65
|
+
functionWithScopes(name: string, scopes: readonly Node[]): {
|
|
66
|
+
fn: FunctionNode;
|
|
67
|
+
scopes: readonly Node[];
|
|
68
|
+
} | null;
|
|
63
69
|
/** The value a `const` name is declared with, and the scopes around that declaration; null for any other name. */
|
|
64
70
|
constantOf(name: string, scopes: readonly Node[]): {
|
|
65
71
|
init: Expression;
|
|
@@ -87,6 +93,12 @@ export declare class Values {
|
|
|
87
93
|
private isGlobal;
|
|
88
94
|
/** `data.name` where `data` is `import * as data`: what the module exports as `name`; null for any other member. */
|
|
89
95
|
private namespaceMember;
|
|
96
|
+
/**
|
|
97
|
+
* A property of an object written out in a constant the module keeps, worked out alone, as `TITLES.fill` in
|
|
98
|
+
* `const TITLES = { fill: 'fills a limit order', format: (venue) => venue }`, whatever its other values are. Null when
|
|
99
|
+
* a spread, a key the scan can't work out, or a getter or method of that name may hold it.
|
|
100
|
+
*/
|
|
101
|
+
private ownProperty;
|
|
90
102
|
private imported;
|
|
91
103
|
/**
|
|
92
104
|
* How many items a list has when not all its values are known, as `[NaN, Infinity]`: a list written out, its spreads
|
|
@@ -104,6 +116,12 @@ export declare class Values {
|
|
|
104
116
|
private changedAtLoad;
|
|
105
117
|
private resolveConstant;
|
|
106
118
|
private enumMembers;
|
|
119
|
+
/** A name's binding, and the scopes from the outermost to the one that declares it. */
|
|
107
120
|
private lookup;
|
|
108
121
|
private bindings;
|
|
109
122
|
}
|
|
123
|
+
/**
|
|
124
|
+
* Names assigned to or changed anywhere in `body`, its functions included: `x = ...`, `x++`, `[x] = ...`,
|
|
125
|
+
* `for (x of ...)`, `x.push(...)`.
|
|
126
|
+
*/
|
|
127
|
+
export declare function assignedNames(body: Node): Set<string>;
|
package/dist/values.js
CHANGED
|
@@ -20,6 +20,7 @@ export function isScopeNode(node) {
|
|
|
20
20
|
case 'ForInStatement':
|
|
21
21
|
case 'ForOfStatement':
|
|
22
22
|
case 'CatchClause':
|
|
23
|
+
case 'SwitchStatement':
|
|
23
24
|
return true;
|
|
24
25
|
default:
|
|
25
26
|
return false;
|
|
@@ -68,13 +69,22 @@ export class Values {
|
|
|
68
69
|
/**
|
|
69
70
|
* Runs `read` with a function's parameters bound to the arguments of one call, worked out where the call is, so that
|
|
70
71
|
* titles and values built from them resolve, as in `test(\`${side} rejects a zero quantity\`)` inside
|
|
71
|
-
* `validatesQuantity('buy')`. `args` stop at a spread argument, after which no position is known
|
|
72
|
-
* takes the parameter's default value, worked out in `scopes`, the scopes around the
|
|
72
|
+
* `validatesQuantity('buy')`. `args` stop at a spread argument, after which no position is known, and `complete` is
|
|
73
|
+
* false then. A missing argument takes the parameter's default value, worked out in `scopes`, the scopes around the
|
|
74
|
+
* function. A rest parameter, as `...cycles`, holds the arguments left.
|
|
73
75
|
*/
|
|
74
|
-
withArguments(fn, args, scopes, read) {
|
|
76
|
+
withArguments(fn, args, scopes, read, complete = true) {
|
|
75
77
|
const parameters = new Map();
|
|
76
78
|
for (const [index, parameter] of fn.params.entries()) {
|
|
77
|
-
|
|
79
|
+
if (parameter.type === 'RestElement') {
|
|
80
|
+
const rest = args.slice(index);
|
|
81
|
+
const unknown = complete ? rest.find((item) => !item.ok) : UNRESOLVED;
|
|
82
|
+
const value = unknown ?? { ok: true, value: rest.map((item) => item.value) };
|
|
83
|
+
this.bind(parameter.argument, value, parameters, [...scopes, fn]);
|
|
84
|
+
}
|
|
85
|
+
else {
|
|
86
|
+
this.bind(parameter, args.at(index), parameters, [...scopes, fn]);
|
|
87
|
+
}
|
|
78
88
|
}
|
|
79
89
|
// A parameter the function assigns to may hold another value by the time it is read.
|
|
80
90
|
for (const name of this.assignedIn(fn.body))
|
|
@@ -280,6 +290,9 @@ export class Values {
|
|
|
280
290
|
const namespace = this.namespaceMember(expression, scopes);
|
|
281
291
|
if (namespace)
|
|
282
292
|
return namespace;
|
|
293
|
+
const own = this.ownProperty(expression, scopes);
|
|
294
|
+
if (own)
|
|
295
|
+
return own;
|
|
283
296
|
const object = this.resolve(expression.object, scopes);
|
|
284
297
|
if (!object.ok)
|
|
285
298
|
return object;
|
|
@@ -314,13 +327,17 @@ export class Values {
|
|
|
314
327
|
* A parameter is not its function, though the function declares it.
|
|
315
328
|
*/
|
|
316
329
|
functionOf(name, scopes) {
|
|
317
|
-
|
|
318
|
-
|
|
330
|
+
return this.functionWithScopes(name, scopes)?.fn ?? null;
|
|
331
|
+
}
|
|
332
|
+
/** `functionOf()`, with the scopes around the function's declaration, in which its body is read. */
|
|
333
|
+
functionWithScopes(name, scopes) {
|
|
334
|
+
const found = this.lookup(name, scopes);
|
|
335
|
+
const declaration = found?.binding.declaration;
|
|
319
336
|
// A class is bound like a function, but has no body to walk.
|
|
320
|
-
|
|
321
|
-
return declaration;
|
|
337
|
+
const declared = found?.binding.kind === 'function' && declaration?.type === 'FunctionDeclaration';
|
|
322
338
|
const init = declaration?.type === 'VariableDeclarator' && declaration.init ? unwrap(declaration.init) : null;
|
|
323
|
-
|
|
339
|
+
const fn = declared ? declaration : isFunctionNode(init) ? init : null;
|
|
340
|
+
return fn && found ? { fn, scopes: found.scopes } : null;
|
|
324
341
|
}
|
|
325
342
|
/** The value a `const` name is declared with, and the scopes around that declaration; null for any other name. */
|
|
326
343
|
constantOf(name, scopes) {
|
|
@@ -426,8 +443,14 @@ export class Values {
|
|
|
426
443
|
if (object.type !== 'Identifier')
|
|
427
444
|
return null;
|
|
428
445
|
const binding = this.lookup(object.name, scopes)?.binding;
|
|
429
|
-
if (binding?.kind !== 'import'
|
|
446
|
+
if (binding?.kind !== 'import')
|
|
447
|
+
return null;
|
|
448
|
+
// `const fees = require('./fees')` holds the module's exports, as `import * as fees` does.
|
|
449
|
+
const required = binding.imported === 'default' && binding.declaration.type === 'VariableDeclarator';
|
|
450
|
+
if (binding.imported !== null && !required)
|
|
430
451
|
return null;
|
|
452
|
+
if (required && this.changedAtLoad(scopes[0]).has(object.name))
|
|
453
|
+
return { ok: false, importedFrom: binding.source };
|
|
431
454
|
const key = expression.computed
|
|
432
455
|
? this.resolve(expression.property, scopes)
|
|
433
456
|
: { ok: true, value: propertyName(expression) };
|
|
@@ -435,6 +458,41 @@ export class Values {
|
|
|
435
458
|
return { ok: false, importedFrom: binding.source };
|
|
436
459
|
return this.imported(binding.source, String(key.value));
|
|
437
460
|
}
|
|
461
|
+
/**
|
|
462
|
+
* A property of an object written out in a constant the module keeps, worked out alone, as `TITLES.fill` in
|
|
463
|
+
* `const TITLES = { fill: 'fills a limit order', format: (venue) => venue }`, whatever its other values are. Null when
|
|
464
|
+
* a spread, a key the scan can't work out, or a getter or method of that name may hold it.
|
|
465
|
+
*/
|
|
466
|
+
ownProperty(expression, scopes) {
|
|
467
|
+
const object = unwrap(expression.object);
|
|
468
|
+
if (object.type !== 'Identifier')
|
|
469
|
+
return null;
|
|
470
|
+
const binding = this.lookup(object.name, scopes)?.binding;
|
|
471
|
+
if (binding?.kind !== 'const' || this.changedAtLoad(binding.scopes[0]).has(object.name))
|
|
472
|
+
return null;
|
|
473
|
+
const init = unwrap(binding.init);
|
|
474
|
+
if (init.type !== 'ObjectExpression')
|
|
475
|
+
return null;
|
|
476
|
+
const key = expression.computed
|
|
477
|
+
? this.resolve(expression.property, scopes)
|
|
478
|
+
: { ok: true, value: propertyName(expression) };
|
|
479
|
+
if (!key.ok || !isKey(key.value))
|
|
480
|
+
return null;
|
|
481
|
+
let found = null;
|
|
482
|
+
for (const property of init.properties) {
|
|
483
|
+
if (property.type === 'SpreadElement')
|
|
484
|
+
return null;
|
|
485
|
+
const name = this.propertyKey(property.key, property.computed, binding.scopes);
|
|
486
|
+
if (!name.ok || !isKey(name.value))
|
|
487
|
+
return null;
|
|
488
|
+
if (String(name.value) !== String(key.value))
|
|
489
|
+
continue;
|
|
490
|
+
if (property.kind !== 'init' || property.method)
|
|
491
|
+
return null;
|
|
492
|
+
found = property.value;
|
|
493
|
+
}
|
|
494
|
+
return found && this.resolve(found, binding.scopes);
|
|
495
|
+
}
|
|
438
496
|
imported(source, name) {
|
|
439
497
|
const resolved = name !== null && this.imports ? this.imports(source, name) : UNRESOLVED;
|
|
440
498
|
return resolved.ok ? resolved : { ok: false, importedFrom: source };
|
|
@@ -565,11 +623,13 @@ export class Values {
|
|
|
565
623
|
}
|
|
566
624
|
return members;
|
|
567
625
|
}
|
|
626
|
+
/** A name's binding, and the scopes from the outermost to the one that declares it. */
|
|
568
627
|
lookup(name, scopes) {
|
|
569
628
|
for (let index = scopes.length - 1; index >= 0; index--) {
|
|
570
|
-
const
|
|
629
|
+
const declaredIn = scopes.slice(0, index + 1);
|
|
630
|
+
const binding = this.bindings(scopes[index], declaredIn).get(name);
|
|
571
631
|
if (binding)
|
|
572
|
-
return { binding };
|
|
632
|
+
return { binding, scopes: declaredIn };
|
|
573
633
|
}
|
|
574
634
|
return null;
|
|
575
635
|
}
|
|
@@ -643,7 +703,7 @@ function rootName(node) {
|
|
|
643
703
|
* Names assigned to or changed anywhere in `body`, its functions included: `x = ...`, `x++`, `[x] = ...`,
|
|
644
704
|
* `for (x of ...)`, `x.push(...)`.
|
|
645
705
|
*/
|
|
646
|
-
function assignedNames(body) {
|
|
706
|
+
export function assignedNames(body) {
|
|
647
707
|
const names = new Set();
|
|
648
708
|
const targets = (target) => {
|
|
649
709
|
switch (target?.type) {
|
|
@@ -855,19 +915,38 @@ function collectBindings(scope, scopes) {
|
|
|
855
915
|
break;
|
|
856
916
|
}
|
|
857
917
|
};
|
|
918
|
+
// A `var` in a nested block belongs to the whole function or module, as in `case 'x': var context = ...`.
|
|
919
|
+
const hoist = (body) => {
|
|
920
|
+
for (const declarator of nestedVars(body)) {
|
|
921
|
+
for (const name of bindingNames(declarator.id))
|
|
922
|
+
if (!bindings.has(name))
|
|
923
|
+
bindings.set(name, { kind: 'other', declaration: declarator });
|
|
924
|
+
}
|
|
925
|
+
};
|
|
858
926
|
switch (scope.type) {
|
|
859
927
|
case 'Program':
|
|
928
|
+
for (const statement of scope.body)
|
|
929
|
+
declare(statement);
|
|
930
|
+
hoist(scope);
|
|
931
|
+
break;
|
|
860
932
|
case 'BlockStatement':
|
|
861
933
|
case 'StaticBlock':
|
|
862
934
|
case 'TSModuleBlock':
|
|
863
935
|
for (const statement of scope.body)
|
|
864
936
|
declare(statement);
|
|
865
937
|
break;
|
|
938
|
+
case 'SwitchStatement':
|
|
939
|
+
for (const item of scope.cases)
|
|
940
|
+
for (const statement of item.consequent)
|
|
941
|
+
declare(statement);
|
|
942
|
+
break;
|
|
866
943
|
case 'FunctionDeclaration':
|
|
867
944
|
case 'FunctionExpression':
|
|
868
945
|
case 'ArrowFunctionExpression':
|
|
869
946
|
for (const parameter of scope.params)
|
|
870
947
|
other(bindingNames(parameter), scope);
|
|
948
|
+
// Only a TypeScript overload has no body, and no walk goes into one.
|
|
949
|
+
hoist(scope.body);
|
|
871
950
|
break;
|
|
872
951
|
case 'ForStatement':
|
|
873
952
|
declare(scope.init);
|
|
@@ -882,6 +961,26 @@ function collectBindings(scope, scopes) {
|
|
|
882
961
|
}
|
|
883
962
|
return bindings;
|
|
884
963
|
}
|
|
964
|
+
/** The `var` declarators in the blocks below a scope, outside the functions, classes and namespaces in it. */
|
|
965
|
+
function nestedVars(scope) {
|
|
966
|
+
const found = [];
|
|
967
|
+
// Only statements hold declarations, so expressions, however deep, are not walked.
|
|
968
|
+
const visit = (node) => {
|
|
969
|
+
if (node.type === 'VariableDeclaration') {
|
|
970
|
+
if (node.kind === 'var')
|
|
971
|
+
found.push(...node.declarations);
|
|
972
|
+
return;
|
|
973
|
+
}
|
|
974
|
+
if (!/Statement$|^(SwitchCase|CatchClause|ExportNamedDeclaration)$/.test(node.type))
|
|
975
|
+
return;
|
|
976
|
+
for (const child of childNodes(node))
|
|
977
|
+
visit(child);
|
|
978
|
+
};
|
|
979
|
+
for (const child of childNodes(scope))
|
|
980
|
+
if (child.type !== 'VariableDeclaration')
|
|
981
|
+
visit(child);
|
|
982
|
+
return found;
|
|
983
|
+
}
|
|
885
984
|
/** `Object.keys(x)`, `Object.values(x)` or `Object.entries(x)`, which list as many items as `x` has keys. */
|
|
886
985
|
function isObjectListing(call) {
|
|
887
986
|
const callee = unwrap(call.callee);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "test-inventory",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.11.0",
|
|
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",
|
package/schema/diff-v1.json
CHANGED
|
@@ -201,6 +201,7 @@
|
|
|
201
201
|
"dependencyHash",
|
|
202
202
|
"dependencies",
|
|
203
203
|
"hasUnfollowedDependencies",
|
|
204
|
+
"unfollowedDependencies",
|
|
204
205
|
"suiteId",
|
|
205
206
|
"parentTestId",
|
|
206
207
|
"suitePath",
|
|
@@ -306,6 +307,7 @@
|
|
|
306
307
|
"dependencyHash",
|
|
307
308
|
"dependencies",
|
|
308
309
|
"hasUnfollowedDependencies",
|
|
310
|
+
"unfollowedDependencies",
|
|
309
311
|
"suiteId",
|
|
310
312
|
"parentTestId",
|
|
311
313
|
"suitePath",
|
|
@@ -411,6 +413,7 @@
|
|
|
411
413
|
"dependencyHash",
|
|
412
414
|
"dependencies",
|
|
413
415
|
"hasUnfollowedDependencies",
|
|
416
|
+
"unfollowedDependencies",
|
|
414
417
|
"suiteId",
|
|
415
418
|
"parentTestId",
|
|
416
419
|
"suitePath",
|
|
@@ -527,7 +530,7 @@
|
|
|
527
530
|
"type": "null"
|
|
528
531
|
}
|
|
529
532
|
],
|
|
530
|
-
"description": "Hash of the test body, ignoring whitespace and comments; null when the test has
|
|
533
|
+
"description": "Hash of the test body, ignoring whitespace and comments: the test function, one passed by name, or the one a wrapper call receives; null when the test has none of these."
|
|
531
534
|
},
|
|
532
535
|
"dependencyHash": {
|
|
533
536
|
"type": "string",
|
|
@@ -545,6 +548,13 @@
|
|
|
545
548
|
"type": "boolean",
|
|
546
549
|
"description": "Something the test reaches couldn't be followed, so a change there doesn't change `dependencyHash`."
|
|
547
550
|
},
|
|
551
|
+
"unfollowedDependencies": {
|
|
552
|
+
"type": "array",
|
|
553
|
+
"items": {
|
|
554
|
+
"type": "string"
|
|
555
|
+
},
|
|
556
|
+
"description": "Where the test reaches what couldn't be followed: the file and line of each place, as `support/venues.ts:2`, sorted; empty when `hasUnfollowedDependencies` is false. A `dependency-not-followed` warning at the place says what it is."
|
|
557
|
+
},
|
|
548
558
|
"suiteId": {
|
|
549
559
|
"anyOf": [
|
|
550
560
|
{
|
|
@@ -979,6 +989,7 @@
|
|
|
979
989
|
"dependencyHash",
|
|
980
990
|
"dependencies",
|
|
981
991
|
"hasUnfollowedDependencies",
|
|
992
|
+
"unfollowedDependencies",
|
|
982
993
|
"suiteId",
|
|
983
994
|
"parentTestId",
|
|
984
995
|
"suitePath",
|
package/schema/v1.json
CHANGED
|
@@ -772,7 +772,7 @@
|
|
|
772
772
|
"type": "null"
|
|
773
773
|
}
|
|
774
774
|
],
|
|
775
|
-
"description": "Hash of the test body, ignoring whitespace and comments; null when the test has
|
|
775
|
+
"description": "Hash of the test body, ignoring whitespace and comments: the test function, one passed by name, or the one a wrapper call receives; null when the test has none of these."
|
|
776
776
|
},
|
|
777
777
|
"dependencyHash": {
|
|
778
778
|
"type": "string",
|
|
@@ -790,6 +790,13 @@
|
|
|
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
|
+
"unfollowedDependencies": {
|
|
794
|
+
"type": "array",
|
|
795
|
+
"items": {
|
|
796
|
+
"type": "string"
|
|
797
|
+
},
|
|
798
|
+
"description": "Where the test reaches what couldn't be followed: the file and line of each place, as `support/venues.ts:2`, sorted; empty when `hasUnfollowedDependencies` is false. A `dependency-not-followed` warning at the place says what it is."
|
|
799
|
+
},
|
|
793
800
|
"suiteId": {
|
|
794
801
|
"anyOf": [
|
|
795
802
|
{
|
|
@@ -1224,6 +1231,7 @@
|
|
|
1224
1231
|
"dependencyHash",
|
|
1225
1232
|
"dependencies",
|
|
1226
1233
|
"hasUnfollowedDependencies",
|
|
1234
|
+
"unfollowedDependencies",
|
|
1227
1235
|
"suiteId",
|
|
1228
1236
|
"parentTestId",
|
|
1229
1237
|
"suitePath",
|