test-inventory 0.4.1 → 0.6.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 +96 -0
- package/README.md +4 -1
- package/dist/ast.d.ts +3 -3
- package/dist/ast.js +4 -4
- package/dist/bin.js +1 -0
- package/dist/cli.d.ts +4 -2
- package/dist/cli.js +27 -7
- package/dist/config-dependencies.d.ts +62 -0
- package/dist/config-dependencies.js +231 -0
- package/dist/config-runs.d.ts +113 -0
- package/dist/config-runs.js +807 -0
- package/dist/config.d.ts +90 -0
- package/dist/config.js +652 -0
- package/dist/dependency-hash.d.ts +242 -0
- package/dist/dependency-hash.js +1458 -0
- package/dist/diagnostics.js +6 -1
- package/dist/extract.d.ts +20 -0
- package/dist/extract.js +20 -4
- package/dist/filter.d.ts +6 -0
- package/dist/filter.js +18 -1
- package/dist/frameworks/bindings.d.ts +22 -0
- package/dist/frameworks/bindings.js +19 -9
- package/dist/frameworks/common.d.ts +5 -0
- package/dist/frameworks/common.js +11 -0
- package/dist/frameworks/playwright.d.ts +2 -1
- package/dist/frameworks/playwright.js +11 -2
- package/dist/frameworks/vitest.d.ts +2 -1
- package/dist/frameworks/vitest.js +9 -3
- package/dist/hash.d.ts +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/inventory.d.ts +2 -2
- package/dist/inventory.js +2 -1
- package/dist/json.js +2 -0
- package/dist/model.d.ts +9 -1
- package/dist/options.d.ts +2 -2
- package/dist/records.d.ts +58 -2
- package/dist/records.js +196 -28
- package/dist/scan-file.d.ts +13 -1
- package/dist/scan-file.js +16 -4
- package/dist/scan-source.js +1 -1
- package/dist/scan.d.ts +2 -1
- package/dist/scan.js +131 -18
- package/dist/types.d.ts +83 -7
- package/dist/values.d.ts +5 -0
- package/dist/values.js +5 -0
- package/dist/vitest-config.d.ts +6 -4
- package/dist/vitest-config.js +32 -28
- package/dist/vitest-defaults.d.ts +6 -0
- package/dist/vitest-defaults.js +16 -0
- package/package.json +10 -8
- package/schema/v1.json +200 -6
|
@@ -0,0 +1,242 @@
|
|
|
1
|
+
import { type Node } from 'oxc-parser';
|
|
2
|
+
import type { ConfigGap, RunsWith } from './config-dependencies.ts';
|
|
3
|
+
import type { Extraction, Frame, PendingTest } from './extract.ts';
|
|
4
|
+
import type { ModuleReader, ModuleSource, Problem, Span } from './model.ts';
|
|
5
|
+
import type { ParsedFile } from './parse.ts';
|
|
6
|
+
import { type SourceText } from './source.ts';
|
|
7
|
+
import type { Framework } from './types.ts';
|
|
8
|
+
import { Values } from './values.ts';
|
|
9
|
+
/** A file whose code a test can run: the scanned file, a module it imports, or a data file such as JSON. */
|
|
10
|
+
interface Module {
|
|
11
|
+
relativeFilePath: string;
|
|
12
|
+
/** Null for a file that isn't JavaScript or TypeScript, which is taken by its text. */
|
|
13
|
+
parsed: ParsedFile | null;
|
|
14
|
+
/** The file's text with line endings read as `\n`, for a file that isn't code. */
|
|
15
|
+
text: string | null;
|
|
16
|
+
values: Values;
|
|
17
|
+
readModule: ModuleReader | null;
|
|
18
|
+
/** Its top-level code that runs when it is imported, and the modules it imports, which run then too. */
|
|
19
|
+
load: [Unit | null, Unit | null];
|
|
20
|
+
/** All of it, for a module used in ways the scan can't narrow down to declarations. */
|
|
21
|
+
whole: [Unit | null, Unit | null];
|
|
22
|
+
/** What each import in the module stands for, as it is asked for once per test file that reaches it. */
|
|
23
|
+
imports: Map<string, Unit[]>;
|
|
24
|
+
/** The module each specifier names, as a barrel's `export *` is searched once for every name imported through it. */
|
|
25
|
+
reads: Map<string, ReturnType<ModuleReader>>;
|
|
26
|
+
}
|
|
27
|
+
/** Code to hash, with the scopes around each node, so that the names it uses can be followed to their declarations. */
|
|
28
|
+
interface Root {
|
|
29
|
+
node: Node;
|
|
30
|
+
scopes: readonly Node[];
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* A piece of code a test may run, and the pieces it uses in turn. A unit with a `place` and no code stands for
|
|
34
|
+
* something the scan can't follow.
|
|
35
|
+
*/
|
|
36
|
+
interface Unit {
|
|
37
|
+
module: Module;
|
|
38
|
+
roots: Root[];
|
|
39
|
+
/** Nodes left out, given as end by start: the tests and describes in a file's or a describe's own code. */
|
|
40
|
+
cut: ReadonlyMap<number, number>;
|
|
41
|
+
/** Whether names in types are followed too, for type tests. */
|
|
42
|
+
types: boolean;
|
|
43
|
+
/** Extra units it always brings in, such as the code its module runs when it is imported. */
|
|
44
|
+
with: Unit[];
|
|
45
|
+
edges: Set<Unit> | null;
|
|
46
|
+
place: Place | null;
|
|
47
|
+
/** For a test object built with `extend()`, the fixtures left out of its code. */
|
|
48
|
+
fixtures: Fixtures | null;
|
|
49
|
+
/** Fills in `roots` and `with` when the walk first reaches the unit. */
|
|
50
|
+
prepare: (() => void) | null;
|
|
51
|
+
/**
|
|
52
|
+
* Fixtures the functions in its code ask for when passed to a hook, a condition such as `test.skip()`, `test.use()`
|
|
53
|
+
* or a test, as a helper that registers a hook does; null when one takes them whole or can't be told.
|
|
54
|
+
*/
|
|
55
|
+
asks: string[] | null;
|
|
56
|
+
/** The snapshot matchers its code calls, which compare against files beside the test file. */
|
|
57
|
+
snapshots: SnapshotUse[];
|
|
58
|
+
hash: string | null | undefined;
|
|
59
|
+
}
|
|
60
|
+
/** A snapshot matcher a test's code calls, and the name or path it gives; null when it gives none the scan can read. */
|
|
61
|
+
export interface SnapshotUse {
|
|
62
|
+
matcher: string;
|
|
63
|
+
name: string | null;
|
|
64
|
+
/** Given as path parts, as `['portfolio', 'allocation.png']`, which Playwright doesn't sanitize. */
|
|
65
|
+
isParts: boolean;
|
|
66
|
+
}
|
|
67
|
+
/** Reads the snapshot files of a scan from disk, and says whether the config moves them. */
|
|
68
|
+
export interface SnapshotFiles {
|
|
69
|
+
framework: Framework;
|
|
70
|
+
/** The files in a folder of the project and the folders in it, as paths in the folder with `/`; none for no folder. */
|
|
71
|
+
list(folder: string): string[] | 'unreadable';
|
|
72
|
+
/** A file's bytes, from the project root; null when there is none, as before a snapshot is first written. */
|
|
73
|
+
read(file: string): Uint8Array | null | 'unreadable';
|
|
74
|
+
/** Where the config puts snapshots elsewhere, which the scan doesn't follow; null when it doesn't. */
|
|
75
|
+
moved: ConfigGap | null;
|
|
76
|
+
}
|
|
77
|
+
/** Something a test reaches that the scan can't follow. */
|
|
78
|
+
export interface Place {
|
|
79
|
+
relativeFilePath: string;
|
|
80
|
+
source: SourceText;
|
|
81
|
+
problem: Problem;
|
|
82
|
+
/** Not reported, as when one file's code is scanned and no import is read: the test record says enough. */
|
|
83
|
+
isQuiet: boolean;
|
|
84
|
+
}
|
|
85
|
+
/** The units some roots reach, the hashes of their code by file, each list sorted, and the places among them. */
|
|
86
|
+
interface Reach {
|
|
87
|
+
units: Set<Unit>;
|
|
88
|
+
byFile: Map<string, string[]>;
|
|
89
|
+
places: Place[];
|
|
90
|
+
/** The fixtures of the test objects among the units, which each test takes as it needs them. */
|
|
91
|
+
fixtures: Fixtures[];
|
|
92
|
+
/** The fixtures the units' code asks for; null when some of it asks for all. */
|
|
93
|
+
asks: string[] | null;
|
|
94
|
+
snapshots: SnapshotUse[];
|
|
95
|
+
}
|
|
96
|
+
/** A fixture one `extend()` call defines, and the fixtures it asks for; null when it takes them whole. */
|
|
97
|
+
interface Fixture {
|
|
98
|
+
unit: Unit;
|
|
99
|
+
uses: string[] | null;
|
|
100
|
+
}
|
|
101
|
+
/** The fixtures a test object's own `extend()` calls define, left out of the object's unit and taken per test. */
|
|
102
|
+
interface Fixtures {
|
|
103
|
+
byName: Map<string, Fixture[]>;
|
|
104
|
+
/** Fixtures with `auto: true`, which run for every test that uses the object. */
|
|
105
|
+
auto: string[];
|
|
106
|
+
framework: Framework;
|
|
107
|
+
}
|
|
108
|
+
/** The fixtures a test asks for: its own, and those of the hooks around it. */
|
|
109
|
+
export interface FixtureNeeds {
|
|
110
|
+
names: string[];
|
|
111
|
+
/** The test or a hook takes its fixtures whole, so it may use any. */
|
|
112
|
+
all: boolean;
|
|
113
|
+
}
|
|
114
|
+
/** What a test runs, as the test record gives it. */
|
|
115
|
+
export interface Dependencies {
|
|
116
|
+
hash: string;
|
|
117
|
+
files: string[];
|
|
118
|
+
isComplete: boolean;
|
|
119
|
+
}
|
|
120
|
+
/**
|
|
121
|
+
* Follows what each test runs, across the files of one scan: its call, the code around it, and every declaration
|
|
122
|
+
* that code uses, in its own file and through imports. Each piece is read once per scan, however many tests reach it.
|
|
123
|
+
*/
|
|
124
|
+
export declare class DependencyGraph {
|
|
125
|
+
private readonly modules;
|
|
126
|
+
private readonly units;
|
|
127
|
+
private readonly imports;
|
|
128
|
+
private readonly snapshotFiles;
|
|
129
|
+
private readonly calledTests;
|
|
130
|
+
private readonly testObjects;
|
|
131
|
+
/** Places already reported, so that one the scan reaches from many files is reported once. */
|
|
132
|
+
private readonly reported;
|
|
133
|
+
/** The module of a file the scan reads code from, given as its parsed file. */
|
|
134
|
+
module(parsed: ParsedFile, relativeFilePath: string, values: Values, readModule: ModuleReader | null): Module;
|
|
135
|
+
/**
|
|
136
|
+
* Code a test or a describe runs, written in `module`. `cut` lists the nodes left out, such as the tests in a
|
|
137
|
+
* describe.
|
|
138
|
+
*/
|
|
139
|
+
unit(module: Module, nodes: Node[], cut: Span[], types: boolean): Unit;
|
|
140
|
+
/** The code a file runs when it is loaded, leaving out the tests and describes at `cut`. */
|
|
141
|
+
loadUnit(module: Module, types: boolean, cut?: Span[], allImports?: boolean): Unit;
|
|
142
|
+
/** The units a set of roots reaches, leaving out those `skip` reached, with their hashes by file. */
|
|
143
|
+
reach(roots: Unit[], skip?: Reach[]): Reach;
|
|
144
|
+
/**
|
|
145
|
+
* Everything a test's roots reach on top of `base`, the code its file runs when loaded, which all its tests share,
|
|
146
|
+
* with the fixtures it needs of each test object reached: the hash, the files, and whether all of it could be
|
|
147
|
+
* followed.
|
|
148
|
+
*/
|
|
149
|
+
dependencies(roots: Unit[], bases: Reach[], needs: FixtureNeeds, snapshots: (uses: SnapshotUse[]) => Unit[], report: (place: Place) => void): Dependencies;
|
|
150
|
+
private newModule;
|
|
151
|
+
private newUnit;
|
|
152
|
+
private hashOf;
|
|
153
|
+
/** The module a file imports, read and parsed once per scan. */
|
|
154
|
+
private moduleOf;
|
|
155
|
+
private textUnit;
|
|
156
|
+
private wholeUnit;
|
|
157
|
+
/** The unit of a declaration: a declarator, function, class, enum, namespace or `import x = require()`. */
|
|
158
|
+
private declarationUnit;
|
|
159
|
+
/** Whether a name is bound to a test object, once per declaration, as a file may call a helper thousands of times. */
|
|
160
|
+
private isTestObject;
|
|
161
|
+
/**
|
|
162
|
+
* A file a test compares against, by its bytes: a snapshot or a screenshot, read once per scan however many tests
|
|
163
|
+
* compare against it; null when there is none yet.
|
|
164
|
+
*/
|
|
165
|
+
snapshotUnit(relativeFilePath: string, read: () => Uint8Array | null | 'unreadable'): Unit | null | 'unreadable';
|
|
166
|
+
/** A place in a scanned file that marks its tests without a warning, as for what one file's code can't show. */
|
|
167
|
+
quietUnit(module: Module, message: string): Unit;
|
|
168
|
+
/** An import of a name a test uses: the module it names and how, as `import { round } from 'lodash'`. */
|
|
169
|
+
private importUnit;
|
|
170
|
+
/** A place in a module the scan can't follow, as a unit that marks the tests that reach it. */
|
|
171
|
+
private placeUnit;
|
|
172
|
+
/**
|
|
173
|
+
* A module the config runs each test with, taken whole: the config itself, a setup file, or a file of a setup
|
|
174
|
+
* project.
|
|
175
|
+
*/
|
|
176
|
+
runUnit(source: ModuleSource, isConfig: boolean): Unit;
|
|
177
|
+
/** Something in a config the scan can't follow, as a unit that marks the tests whose config it is. */
|
|
178
|
+
gapUnit(gap: ConfigGap): Unit;
|
|
179
|
+
/**
|
|
180
|
+
* What a module's import of `name` from `specifier` stands for, `at` being the statement in `from` that imports it:
|
|
181
|
+
* the declaration it exports, `*` for all of it, or `''` for the code it runs when loaded. Installed packages give
|
|
182
|
+
* nothing; a local module that can't be read gives a place.
|
|
183
|
+
*/
|
|
184
|
+
private imported;
|
|
185
|
+
/** The module a specifier names, from where `from` is; null when no module is read, as for one file's code. */
|
|
186
|
+
private read;
|
|
187
|
+
private readImport;
|
|
188
|
+
/**
|
|
189
|
+
* The units of what a module exports under a name: its own export first, then one an `export *` passes on, as the
|
|
190
|
+
* module system picks them. `*` is the whole module. A name the scan can't find, as with CommonJS exports, also
|
|
191
|
+
* takes the whole module, so that nothing it may run is left out.
|
|
192
|
+
*/
|
|
193
|
+
private exported;
|
|
194
|
+
/** What `export * from source` gives for a name; null when the module behind it doesn't export it. */
|
|
195
|
+
private reexported;
|
|
196
|
+
/**
|
|
197
|
+
* The units a name stands for where it is declared: the declaration, the export of the module it's imported from, or
|
|
198
|
+
* for a parameter only the parameters, as the call that passes their values is followed on its own.
|
|
199
|
+
*/
|
|
200
|
+
private toDeclaration;
|
|
201
|
+
/**
|
|
202
|
+
* A test object built with `extend()` on the framework's own: its code without the fixtures its `extend()` calls
|
|
203
|
+
* define, which each test takes as it needs them. Null for any other value.
|
|
204
|
+
*/
|
|
205
|
+
private testObjectUnit;
|
|
206
|
+
private readTestObject;
|
|
207
|
+
/**
|
|
208
|
+
* The framework of a test object: its own `test`, `mergeTests()` of test objects, or one built on them with
|
|
209
|
+
* `extend()`, followed through imports; null for an expression that isn't one.
|
|
210
|
+
*/
|
|
211
|
+
private frameworkOf;
|
|
212
|
+
/**
|
|
213
|
+
* Takes what the values given to `test.use()`, `override()` or `scoped()` ask for: functions and `[fn, options]`
|
|
214
|
+
* pairs, as `extend()` takes them. Playwright's options and a spread of its `devices` are values, not fixtures.
|
|
215
|
+
*/
|
|
216
|
+
private useValues;
|
|
217
|
+
/**
|
|
218
|
+
* Whether a call is on a test object, so that its functions run with fixtures: the framework's own, a global one,
|
|
219
|
+
* one built with `extend()`, or a parameter, as a helper that takes the test object has.
|
|
220
|
+
*/
|
|
221
|
+
private isTestReference;
|
|
222
|
+
/**
|
|
223
|
+
* The fixtures a fixture's or hook's function asks for. A value such as a constant asks for none; null when the
|
|
224
|
+
* function takes them whole, or the value can't be told, as a factory's result or a fixture from a package.
|
|
225
|
+
*/
|
|
226
|
+
private fixtureUses;
|
|
227
|
+
/**
|
|
228
|
+
* What an expression holds, followed through constants and imports to the function or value they are bound to; the
|
|
229
|
+
* expression itself when it is something else, with the module and scopes to read it in.
|
|
230
|
+
*/
|
|
231
|
+
private valueOf;
|
|
232
|
+
private importOf;
|
|
233
|
+
/** The units a unit uses directly: the declarations its names refer to, and the modules it loads. */
|
|
234
|
+
private edgesOf;
|
|
235
|
+
}
|
|
236
|
+
/**
|
|
237
|
+
* What each test of a scanned file runs: its own call, the helper call that registers it, every describe around it
|
|
238
|
+
* with its hooks and options, the file's own top-level code, and what all of these reach. `report` gets each place the
|
|
239
|
+
* scan can't follow, once per scan.
|
|
240
|
+
*/
|
|
241
|
+
export declare function fileDependencies(graph: DependencyGraph, main: Frame, extraction: Extraction, types: boolean, report: (place: Place) => void, runsWith?: RunsWith, snapshotFiles?: SnapshotFiles | null): (test: PendingTest) => Dependencies;
|
|
242
|
+
export {};
|