test-inventory 0.10.3 → 0.10.4
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 +8 -0
- package/dist/config-runs.d.ts +28 -0
- package/dist/config-runs.js +152 -9
- package/dist/config.d.ts +7 -0
- package/dist/config.js +13 -2
- package/dist/node-scripts.d.ts +16 -0
- package/dist/node-scripts.js +119 -0
- package/dist/scan.js +9 -1
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,13 @@
|
|
|
1
1
|
# test-inventory
|
|
2
2
|
|
|
3
|
+
## 0.10.4
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- [#117](https://github.com/Huldoser/test-inventory/pull/117) [`ac4d95f`](https://github.com/Huldoser/test-inventory/commit/ac4d95f52e2e17571a23cba4467525718a5a7bbf) - Count a config a package.json script starts Vitest, Jest, Playwright, Cypress or WebdriverIO with, as `vitest run --config vitest.config.integration.mts`, when deciding whether a file runs, so its files no longer get `file-not-run`. Vitest and Cypress read its globs from the folder the script runs in, the others from the config's folder. A config the scan can't read, such as a variable, gives a `config-value-unknown` warning on the package.json in place of `file-not-run`.
|
|
8
|
+
|
|
9
|
+
- [#117](https://github.com/Huldoser/test-inventory/pull/117) [`ac4d95f`](https://github.com/Huldoser/test-inventory/commit/ac4d95f52e2e17571a23cba4467525718a5a7bbf) - Don't report `file-not-run` for a file that a collected test file imports, such as a shared suite, as its tests run in that file.
|
|
10
|
+
|
|
3
11
|
## 0.10.3
|
|
4
12
|
|
|
5
13
|
### Patch Changes
|
package/dist/config-runs.d.ts
CHANGED
|
@@ -68,6 +68,10 @@ export declare class ConfigRuns {
|
|
|
68
68
|
private bunFiles;
|
|
69
69
|
/** The Vitest configs whose projects are being found, with their names, to stop at one whose projects name itself. */
|
|
70
70
|
private readonly expanding;
|
|
71
|
+
/** The routes the scripts of a folder's package.json give the runner, by the folder. */
|
|
72
|
+
private readonly scriptRoutes;
|
|
73
|
+
/** The projects of a route, by its config and the folder it runs from. */
|
|
74
|
+
private readonly routeProjects;
|
|
71
75
|
constructor(configs: Configs, framework: Framework, version: [number, number] | null, findsFiles: boolean);
|
|
72
76
|
/**
|
|
73
77
|
* The config a file uses, as the runner started at the root would: the outermost config at or above it that runs it,
|
|
@@ -75,7 +79,31 @@ export declare class ConfigRuns {
|
|
|
75
79
|
* nearest config.
|
|
76
80
|
*/
|
|
77
81
|
placementOf(file: string): Placement;
|
|
82
|
+
/**
|
|
83
|
+
* A file the configs the runner finds by name leave out may still run through a config a package.json script names,
|
|
84
|
+
* as `vitest --config vitest.integration.config.ts`; when a script's config can't be read, the scan can't tell.
|
|
85
|
+
*/
|
|
78
86
|
private place;
|
|
87
|
+
private placeByConfigs;
|
|
88
|
+
/**
|
|
89
|
+
* The placement the first route that runs a file gives it, from the package.json scripts in its folder and those above
|
|
90
|
+
* it, nearest first; `unknown`, reported, when none runs it and one can't be read; null when none runs it.
|
|
91
|
+
*/
|
|
92
|
+
private placeByScripts;
|
|
93
|
+
/**
|
|
94
|
+
* The routes the scripts of the package.json in a folder give the runner: the config each command that starts it
|
|
95
|
+
* names, else the one the runner finds in the folder it starts in. Vitest and Cypress start in the folder the command
|
|
96
|
+
* names as their root, else the script's, and read a config path from there; the others read it from the script's.
|
|
97
|
+
*/
|
|
98
|
+
private routesIn;
|
|
99
|
+
/**
|
|
100
|
+
* The config a runner started in a folder without one named finds: there only, except that Vitest before 5.0 also
|
|
101
|
+
* looks in the folders above it, and Jest takes the folder's package.json when it finds no config; null for Vitest's
|
|
102
|
+
* defaults.
|
|
103
|
+
*/
|
|
104
|
+
private defaultConfigIn;
|
|
105
|
+
/** A route's projects, as the runner started in its folder finds them; Vitest's defaults there without a config. */
|
|
106
|
+
private projectsOfRoute;
|
|
79
107
|
/**
|
|
80
108
|
* Playwright's config `tag`, from 1.57, which it gives every test before its own tags; null when the scan can't work
|
|
81
109
|
* it out. That is reported where the config writes `tag`; a config whose settings come from code the scan can't
|
package/dist/config-runs.js
CHANGED
|
@@ -5,7 +5,7 @@ import picomatch from 'picomatch';
|
|
|
5
5
|
import { globSync } from 'tinyglobby';
|
|
6
6
|
import { mergeDeep, settingAt, unknownText, } from "./config.js";
|
|
7
7
|
import { atLeast } from "./frameworks/common.js";
|
|
8
|
-
import { nodeTestCommands, scriptsRunBy } from "./node-scripts.js";
|
|
8
|
+
import { nodeTestCommands, runnerCommands, scriptsRunBy } from "./node-scripts.js";
|
|
9
9
|
import { durationOf } from "./frameworks/mocha.js";
|
|
10
10
|
import { VITEST_BENCHMARK_INCLUDE, VITEST_INCLUDE, VITEST_TYPECHECK_INCLUDE, vitestExclude, } from "./vitest-defaults.js";
|
|
11
11
|
const PLAYWRIGHT_TEST_MATCH = '**/*.@(spec|test).?(c|m)[jt]s?(x)';
|
|
@@ -33,6 +33,8 @@ const NO_DEFAULTS = {
|
|
|
33
33
|
tags: null,
|
|
34
34
|
};
|
|
35
35
|
const ASSUMED = 'the scan takes its files to be run';
|
|
36
|
+
/** The runners whose config a package.json script may name, which the scan then reads as one more that runs files. */
|
|
37
|
+
const SCRIPT_RUNNERS = new Set(['vitest', 'jest', 'playwright', 'cypress', 'webdriverio']);
|
|
36
38
|
const NOT_FOUND = "the scan can't tell which files it runs; give patterns to scan them";
|
|
37
39
|
function emptySettings() {
|
|
38
40
|
return { kind: 'object', keys: new Map(), rest: null };
|
|
@@ -122,6 +124,10 @@ export class ConfigRuns {
|
|
|
122
124
|
bunFiles = null;
|
|
123
125
|
/** The Vitest configs whose projects are being found, with their names, to stop at one whose projects name itself. */
|
|
124
126
|
expanding = new Map();
|
|
127
|
+
/** The routes the scripts of a folder's package.json give the runner, by the folder. */
|
|
128
|
+
scriptRoutes = new Map();
|
|
129
|
+
/** The projects of a route, by its config and the folder it runs from. */
|
|
130
|
+
routeProjects = new Map();
|
|
125
131
|
constructor(configs, framework, version, findsFiles) {
|
|
126
132
|
this.configs = configs;
|
|
127
133
|
this.framework = framework;
|
|
@@ -137,7 +143,20 @@ export class ConfigRuns {
|
|
|
137
143
|
const placement = this.place(file);
|
|
138
144
|
return { ...placement, tags: this.configTags(placement.config) };
|
|
139
145
|
}
|
|
146
|
+
/**
|
|
147
|
+
* A file the configs the runner finds by name leave out may still run through a config a package.json script names,
|
|
148
|
+
* as `vitest --config vitest.integration.config.ts`; when a script's config can't be read, the scan can't tell.
|
|
149
|
+
*/
|
|
140
150
|
place(file) {
|
|
151
|
+
const placement = this.placeByConfigs(file);
|
|
152
|
+
if (placement.runs !== false || !SCRIPT_RUNNERS.has(this.framework))
|
|
153
|
+
return placement;
|
|
154
|
+
const routed = this.placeByScripts(file);
|
|
155
|
+
if (routed === 'unknown')
|
|
156
|
+
return { ...placement, runs: null, projects: null };
|
|
157
|
+
return routed ?? placement;
|
|
158
|
+
}
|
|
159
|
+
placeByConfigs(file) {
|
|
141
160
|
if (this.framework === 'mocha')
|
|
142
161
|
return this.placeMocha(file);
|
|
143
162
|
if (this.framework === 'jasmine')
|
|
@@ -183,6 +202,132 @@ export class ConfigRuns {
|
|
|
183
202
|
projects: nearest ? [] : null,
|
|
184
203
|
};
|
|
185
204
|
}
|
|
205
|
+
/**
|
|
206
|
+
* The placement the first route that runs a file gives it, from the package.json scripts in its folder and those above
|
|
207
|
+
* it, nearest first; `unknown`, reported, when none runs it and one can't be read; null when none runs it.
|
|
208
|
+
*/
|
|
209
|
+
placeByScripts(file) {
|
|
210
|
+
const unknown = [];
|
|
211
|
+
for (let folder = path.dirname(file);; folder = path.dirname(folder)) {
|
|
212
|
+
for (const route of this.routesIn(folder)) {
|
|
213
|
+
if ('unknown' in route) {
|
|
214
|
+
unknown.push(route);
|
|
215
|
+
continue;
|
|
216
|
+
}
|
|
217
|
+
const projects = this.projectsOfRoute(route);
|
|
218
|
+
const running = projects.flatMap((project) => {
|
|
219
|
+
const runs = project.runs?.(file);
|
|
220
|
+
return runs ? [{ project, runs }] : [];
|
|
221
|
+
});
|
|
222
|
+
if (running.length > 0) {
|
|
223
|
+
const [{ project, runs }] = running;
|
|
224
|
+
const config = route.config && project.config;
|
|
225
|
+
return { config, settings: project.settings, runs, projects: running.map((item) => item.project.about) };
|
|
226
|
+
}
|
|
227
|
+
const unknownProject = projects.find((project) => project.unknown);
|
|
228
|
+
if (unknownProject?.unknown) {
|
|
229
|
+
this.configs.reportUnknown(unknownProject.unknown.setting, unknownProject.unknown.key, ASSUMED);
|
|
230
|
+
return 'unknown';
|
|
231
|
+
}
|
|
232
|
+
}
|
|
233
|
+
if (folder === this.configs.root)
|
|
234
|
+
break;
|
|
235
|
+
}
|
|
236
|
+
for (const route of unknown)
|
|
237
|
+
this.configs.reportFile(this.configs.relative(route.manifest), route.unknown);
|
|
238
|
+
return unknown.length > 0 ? 'unknown' : null;
|
|
239
|
+
}
|
|
240
|
+
/**
|
|
241
|
+
* The routes the scripts of the package.json in a folder give the runner: the config each command that starts it
|
|
242
|
+
* names, else the one the runner finds in the folder it starts in. Vitest and Cypress start in the folder the command
|
|
243
|
+
* names as their root, else the script's, and read a config path from there; the others read it from the script's.
|
|
244
|
+
*/
|
|
245
|
+
routesIn(folder) {
|
|
246
|
+
let routes = this.scriptRoutes.get(folder);
|
|
247
|
+
if (routes)
|
|
248
|
+
return routes;
|
|
249
|
+
routes = [];
|
|
250
|
+
const manifest = path.join(folder, 'package.json');
|
|
251
|
+
let scripts = {};
|
|
252
|
+
try {
|
|
253
|
+
scripts = JSON.parse(readFileSync(manifest, 'utf8')).scripts ?? {};
|
|
254
|
+
}
|
|
255
|
+
catch {
|
|
256
|
+
// No package.json, or one the runner can't start from either.
|
|
257
|
+
}
|
|
258
|
+
const seen = new Set();
|
|
259
|
+
for (const [name, script] of Object.entries(scripts)) {
|
|
260
|
+
if (typeof script !== 'string')
|
|
261
|
+
continue;
|
|
262
|
+
for (const command of runnerCommands(script, this.framework)) {
|
|
263
|
+
const about = `The script ${name} in ${this.configs.relative(manifest)} starts the runner`;
|
|
264
|
+
if (command.unreadable) {
|
|
265
|
+
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.`;
|
|
266
|
+
routes.push({ manifest, unknown });
|
|
267
|
+
continue;
|
|
268
|
+
}
|
|
269
|
+
const root = command.root === null ? folder : path.resolve(folder, command.root);
|
|
270
|
+
const from = this.framework === 'vitest' || this.framework === 'cypress' ? root : folder;
|
|
271
|
+
let config;
|
|
272
|
+
if (command.config === null)
|
|
273
|
+
config = this.defaultConfigIn(root);
|
|
274
|
+
else {
|
|
275
|
+
const target = path.resolve(from, command.config);
|
|
276
|
+
const stat = statSync(target, { throwIfNoEntry: false });
|
|
277
|
+
// The runner refuses a config that doesn't exist, so the command runs no file.
|
|
278
|
+
if (!stat)
|
|
279
|
+
continue;
|
|
280
|
+
config = stat.isDirectory() ? this.configs.inFolder(target) : this.configs.at(target);
|
|
281
|
+
if (config === null)
|
|
282
|
+
continue;
|
|
283
|
+
}
|
|
284
|
+
// Vitest runs with its defaults without a config; the others refuse to start, or always find one.
|
|
285
|
+
if (config === null && this.framework !== 'vitest')
|
|
286
|
+
continue;
|
|
287
|
+
const key = `${config?.file ?? ''}\0${root}`;
|
|
288
|
+
if (seen.has(key))
|
|
289
|
+
continue;
|
|
290
|
+
seen.add(key);
|
|
291
|
+
routes.push({ config, root });
|
|
292
|
+
}
|
|
293
|
+
}
|
|
294
|
+
this.scriptRoutes.set(folder, routes);
|
|
295
|
+
return routes;
|
|
296
|
+
}
|
|
297
|
+
/**
|
|
298
|
+
* The config a runner started in a folder without one named finds: there only, except that Vitest before 5.0 also
|
|
299
|
+
* looks in the folders above it, and Jest takes the folder's package.json when it finds no config; null for Vitest's
|
|
300
|
+
* defaults.
|
|
301
|
+
*/
|
|
302
|
+
defaultConfigIn(folder) {
|
|
303
|
+
const own = this.framework === 'jest' ? this.configs.jestConfigFrom(folder) : this.configs.inFolder(folder);
|
|
304
|
+
if (own || this.framework !== 'vitest' || atLeast(this.version, 5, 0))
|
|
305
|
+
return own;
|
|
306
|
+
// A config above the project's root is outside what the scan reads.
|
|
307
|
+
const { root } = this.configs;
|
|
308
|
+
for (let above = path.dirname(folder); above === root || isInside(root, above); above = path.dirname(above)) {
|
|
309
|
+
const config = this.configs.inFolder(above);
|
|
310
|
+
if (config)
|
|
311
|
+
return config;
|
|
312
|
+
}
|
|
313
|
+
return null;
|
|
314
|
+
}
|
|
315
|
+
/** A route's projects, as the runner started in its folder finds them; Vitest's defaults there without a config. */
|
|
316
|
+
projectsOfRoute(route) {
|
|
317
|
+
const key = `${route.config?.file ?? ''}\0${route.root}`;
|
|
318
|
+
let projects = this.routeProjects.get(key);
|
|
319
|
+
if (!projects) {
|
|
320
|
+
const config = route.config ?? this.noConfig(route.root);
|
|
321
|
+
if (this.framework === 'vitest')
|
|
322
|
+
projects = this.vitestProjects(config, null, route.root);
|
|
323
|
+
else if (this.framework === 'cypress')
|
|
324
|
+
projects = this.cypressProjects(config, route.root);
|
|
325
|
+
else
|
|
326
|
+
projects = this.projectsOf(config);
|
|
327
|
+
this.routeProjects.set(key, projects);
|
|
328
|
+
}
|
|
329
|
+
return projects;
|
|
330
|
+
}
|
|
186
331
|
/**
|
|
187
332
|
* Playwright's config `tag`, from 1.57, which it gives every test before its own tags; null when the scan can't work
|
|
188
333
|
* it out. That is reported where the config writes `tag`; a config whose settings come from code the scan can't
|
|
@@ -400,8 +545,7 @@ export class ConfigRuns {
|
|
|
400
545
|
* dot files included, and those in `node_modules` unless a `specPattern` names it; component testing also leaves out
|
|
401
546
|
* the files e2e's `specPattern` matches. `cypress run` matches each pattern against the whole path, as globby does.
|
|
402
547
|
*/
|
|
403
|
-
cypressProjects(config) {
|
|
404
|
-
const folder = path.dirname(config.file);
|
|
548
|
+
cypressProjects(config, folder = path.dirname(config.file)) {
|
|
405
549
|
const types = [
|
|
406
550
|
['e2e', ['cypress/e2e/**/*.cy.{js,jsx,ts,tsx}'], ['*.hot-update.js']],
|
|
407
551
|
];
|
|
@@ -971,9 +1115,9 @@ export class ConfigRuns {
|
|
|
971
1115
|
return rules;
|
|
972
1116
|
}
|
|
973
1117
|
/** A config for the defaults of a runner started where no config is found. */
|
|
974
|
-
noConfig() {
|
|
975
|
-
const file = path.join(
|
|
976
|
-
return { file, record: { relativeFilePath:
|
|
1118
|
+
noConfig(folder = this.configs.root) {
|
|
1119
|
+
const file = path.join(folder, 'package.json');
|
|
1120
|
+
return { file, record: { relativeFilePath: this.configs.relative(file), extends: [] }, settings: emptySettings() };
|
|
977
1121
|
}
|
|
978
1122
|
/**
|
|
979
1123
|
* Jest's projects: the config itself, or the entries of its `projects`. A path or glob there names a folder, whose
|
|
@@ -1162,14 +1306,13 @@ export class ConfigRuns {
|
|
|
1162
1306
|
return { settings, refusal: null };
|
|
1163
1307
|
return { settings: { ...settings, keys: new Map([...base.keys, ...settings.keys]) }, refusal: null };
|
|
1164
1308
|
}
|
|
1165
|
-
vitestProjects(config, container = null) {
|
|
1166
|
-
const folder = path.dirname(config.file);
|
|
1309
|
+
vitestProjects(config, container = null, folder = path.dirname(config.file)) {
|
|
1167
1310
|
const list = settingAt(config.settings, ['test', 'projects']);
|
|
1168
1311
|
const isVitest3 = this.version !== null && this.version[0] < 4;
|
|
1169
1312
|
const workspace = isVitest3 ? settingAt(config.settings, ['test', 'workspace']) : null;
|
|
1170
1313
|
if (workspace)
|
|
1171
1314
|
return [this.unknownProject(config, unknownAt(workspace), 'test.workspace')];
|
|
1172
|
-
if (isVitest3 && VITEST_WORKSPACES.some((name) => existsSync(path.join(
|
|
1315
|
+
if (isVitest3 && VITEST_WORKSPACES.some((name) => existsSync(path.join(path.dirname(config.file), name)))) {
|
|
1173
1316
|
// Vitest 3 takes its projects from a workspace file, which the scan doesn't read.
|
|
1174
1317
|
return [this.unknownProject(config, { kind: 'unknown', where: null }, 'test.projects')];
|
|
1175
1318
|
}
|
package/dist/config.d.ts
CHANGED
|
@@ -95,6 +95,8 @@ export declare class Configs {
|
|
|
95
95
|
private reportAt;
|
|
96
96
|
/** Reports, once, a config the runner reads in a way the scan doesn't follow, or refuses. */
|
|
97
97
|
reportConfig(config: ConfigFile, message: string): void;
|
|
98
|
+
/** Reports, once, a file the scan reads runner settings from, such as a package.json script, and can't follow. */
|
|
99
|
+
reportFile(relativeFilePath: string, message: string): void;
|
|
98
100
|
/**
|
|
99
101
|
* The config Mocha runs with, started in the root: the first `.mocharc` file from the root up, joined with the `mocha`
|
|
100
102
|
* key of the nearest package.json. Null without either.
|
|
@@ -114,6 +116,11 @@ export declare class Configs {
|
|
|
114
116
|
inFolder(folder: string): ConfigFile | null;
|
|
115
117
|
/** Config file names, in the order the runner looks for them; Jest reads `.cts` from 30.0 and `.mts` from 30.4. */
|
|
116
118
|
private names;
|
|
119
|
+
/**
|
|
120
|
+
* The config Jest started in a folder with a package.json reads: as `jestConfigIn`, with the package.json itself,
|
|
121
|
+
* and so Jest's defaults from that folder, when it has no `jest` key.
|
|
122
|
+
*/
|
|
123
|
+
jestConfigFrom(folder: string): ConfigFile | null;
|
|
117
124
|
/**
|
|
118
125
|
* The config Jest takes in a folder: a `jest.config` file, else the `package.json` with a `jest` key, which from 30.0
|
|
119
126
|
* may be the path to the config. A `package.json` without one is a config only in the root, as Jest started there
|
package/dist/config.js
CHANGED
|
@@ -797,11 +797,15 @@ export class Configs {
|
|
|
797
797
|
}
|
|
798
798
|
/** Reports, once, a config the runner reads in a way the scan doesn't follow, or refuses. */
|
|
799
799
|
reportConfig(config, message) {
|
|
800
|
-
|
|
800
|
+
this.reportFile(config.record.relativeFilePath, message);
|
|
801
|
+
}
|
|
802
|
+
/** Reports, once, a file the scan reads runner settings from, such as a package.json script, and can't follow. */
|
|
803
|
+
reportFile(relativeFilePath, message) {
|
|
804
|
+
const id = `${relativeFilePath}\0${message}`;
|
|
801
805
|
if (this.reported.has(id))
|
|
802
806
|
return;
|
|
803
807
|
this.reported.add(id);
|
|
804
|
-
this.diagnostics.push(fileDiagnostic('config-value-unknown',
|
|
808
|
+
this.diagnostics.push(fileDiagnostic('config-value-unknown', relativeFilePath, message));
|
|
805
809
|
}
|
|
806
810
|
/**
|
|
807
811
|
* The config Mocha runs with, started in the root: the first `.mocharc` file from the root up, joined with the `mocha`
|
|
@@ -865,6 +869,13 @@ export class Configs {
|
|
|
865
869
|
return CONFIG_FILES.jest.filter((name) => (!name.endsWith('.cts') || atLeast(this.version, 30, 0)) &&
|
|
866
870
|
(!name.endsWith('.mts') || atLeast(this.version, 30, 4)));
|
|
867
871
|
}
|
|
872
|
+
/**
|
|
873
|
+
* The config Jest started in a folder with a package.json reads: as `jestConfigIn`, with the package.json itself,
|
|
874
|
+
* and so Jest's defaults from that folder, when it has no `jest` key.
|
|
875
|
+
*/
|
|
876
|
+
jestConfigFrom(folder) {
|
|
877
|
+
return this.jestConfigIn(folder, true);
|
|
878
|
+
}
|
|
868
879
|
/**
|
|
869
880
|
* The config Jest takes in a folder: a `jest.config` file, else the `package.json` with a `jest` key, which from 30.0
|
|
870
881
|
* may be the path to the config. A `package.json` without one is a config only in the root, as Jest started there
|
package/dist/node-scripts.d.ts
CHANGED
|
@@ -9,3 +9,19 @@ export declare function nodeTestCommands(script: string, setups?: boolean): stri
|
|
|
9
9
|
* `bun run`, or `npm-run-all`, `run-s` and `run-p`, whose names may be globs where `*` stops at a `:`.
|
|
10
10
|
*/
|
|
11
11
|
export declare function scriptsRunBy(scripts: Record<string, unknown>, name: string): string[];
|
|
12
|
+
/** The runners a script can start with a config of its own, which the scan then takes as one more that runs files. */
|
|
13
|
+
export type ScriptRunner = 'vitest' | 'jest' | 'playwright' | 'cypress' | 'webdriverio';
|
|
14
|
+
/** A command of a script that starts a test runner. */
|
|
15
|
+
export interface RunnerCommand {
|
|
16
|
+
/** The config it names, as written; null when it names none. */
|
|
17
|
+
config: string | null;
|
|
18
|
+
/** The folder it takes as the project's root, as written: Vitest's `--root`, Cypress's `--project`; else null. */
|
|
19
|
+
root: string | null;
|
|
20
|
+
/** Whether it names its config or root in a way the scan can't read: a variable, or Jest's inline JSON. */
|
|
21
|
+
unreadable: boolean;
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* The commands of a package.json script that start a runner, with the config and root each names. Only a command whose
|
|
25
|
+
* program is the runner counts, so `eslint --plugin jest -c .eslintrc.json` and `npm run jest` start none.
|
|
26
|
+
*/
|
|
27
|
+
export declare function runnerCommands(script: string, runner: ScriptRunner): RunnerCommand[];
|
package/dist/node-scripts.js
CHANGED
|
@@ -143,3 +143,122 @@ function calledScripts(words, names) {
|
|
|
143
143
|
return first === 'run' ? [second] : [first];
|
|
144
144
|
return [];
|
|
145
145
|
}
|
|
146
|
+
/** Each runner's program, the subcommands that run tests, and the options that name its config and its root. */
|
|
147
|
+
const RUNNERS = {
|
|
148
|
+
vitest: { program: 'vitest', subcommands: null, config: ['--config', '-c'], root: ['--root', '-r'] },
|
|
149
|
+
jest: { program: 'jest', subcommands: null, config: ['--config', '-c'], root: [] },
|
|
150
|
+
playwright: { program: 'playwright', subcommands: ['test'], config: ['--config', '-c'], root: [] },
|
|
151
|
+
cypress: {
|
|
152
|
+
program: 'cypress',
|
|
153
|
+
subcommands: ['run', 'open'],
|
|
154
|
+
config: ['--config-file', '-C'],
|
|
155
|
+
root: ['--project', '-P'],
|
|
156
|
+
},
|
|
157
|
+
// `wdio run <config>` and `wdio <config>` take the config as the first argument.
|
|
158
|
+
webdriverio: { program: 'wdio', subcommands: null, config: [], root: [] },
|
|
159
|
+
};
|
|
160
|
+
/** The program each package's files start when `node` runs them. */
|
|
161
|
+
const RUNNER_PACKAGES = {
|
|
162
|
+
vitest: 'vitest',
|
|
163
|
+
jest: 'jest',
|
|
164
|
+
'jest-cli': 'jest',
|
|
165
|
+
'@playwright/test': 'playwright',
|
|
166
|
+
playwright: 'playwright',
|
|
167
|
+
cypress: 'cypress',
|
|
168
|
+
'@wdio/cli': 'wdio',
|
|
169
|
+
};
|
|
170
|
+
/**
|
|
171
|
+
* The commands of a package.json script that start a runner, with the config and root each names. Only a command whose
|
|
172
|
+
* program is the runner counts, so `eslint --plugin jest -c .eslintrc.json` and `npm run jest` start none.
|
|
173
|
+
*/
|
|
174
|
+
export function runnerCommands(script, runner) {
|
|
175
|
+
const { program, subcommands, config, root } = RUNNERS[runner];
|
|
176
|
+
const found = [];
|
|
177
|
+
for (const words of commandsOf(script)) {
|
|
178
|
+
const started = programOf(words);
|
|
179
|
+
if (started?.program !== program)
|
|
180
|
+
continue;
|
|
181
|
+
let args = started.args;
|
|
182
|
+
if (subcommands) {
|
|
183
|
+
if (!subcommands.includes(args[0]))
|
|
184
|
+
continue;
|
|
185
|
+
args = args.slice(1);
|
|
186
|
+
}
|
|
187
|
+
const command = { config: null, root: null, unreadable: false };
|
|
188
|
+
if (runner === 'webdriverio') {
|
|
189
|
+
const first = args.at(0) === 'run' ? args.at(1) : args.at(0);
|
|
190
|
+
if (first !== undefined && !first.startsWith('-'))
|
|
191
|
+
command.config = first;
|
|
192
|
+
}
|
|
193
|
+
for (let index = 0; index < args.length; index++) {
|
|
194
|
+
const parts = args[index].split(/=(.*)/s);
|
|
195
|
+
const key = config.includes(parts[0]) ? 'config' : root.includes(parts[0]) ? 'root' : null;
|
|
196
|
+
if (key === null)
|
|
197
|
+
continue;
|
|
198
|
+
const value = parts.at(1) ?? args.at(++index);
|
|
199
|
+
if (value === undefined)
|
|
200
|
+
command.unreadable = true;
|
|
201
|
+
else
|
|
202
|
+
command[key] = value;
|
|
203
|
+
}
|
|
204
|
+
// The shell expands a variable, and Jest reads a config that starts with `{` as the config itself.
|
|
205
|
+
const values = [command.config, command.root].filter((value) => value !== null);
|
|
206
|
+
if (values.some((value) => /[$%]/.test(value) || value.startsWith('{')))
|
|
207
|
+
command.unreadable = true;
|
|
208
|
+
found.push(command);
|
|
209
|
+
}
|
|
210
|
+
return found;
|
|
211
|
+
}
|
|
212
|
+
/**
|
|
213
|
+
* The program a command starts, with its arguments: past variables set before it, `cross-env`, `dotenv --`, and `npx`,
|
|
214
|
+
* `bunx`, `pnpm exec`, `yarn exec`, `npm exec` or a package manager given a binary's name; for `node`, the runner whose
|
|
215
|
+
* package holds the file it runs. Null when there is none.
|
|
216
|
+
*/
|
|
217
|
+
function programOf(words) {
|
|
218
|
+
let index = 0;
|
|
219
|
+
const skip = (test) => {
|
|
220
|
+
while (index < words.length && test(words[index]))
|
|
221
|
+
index++;
|
|
222
|
+
};
|
|
223
|
+
const isAssignment = (word) => /^\w+=/.test(word);
|
|
224
|
+
skip(isAssignment);
|
|
225
|
+
for (;;) {
|
|
226
|
+
const [word, next] = [words.at(index), words.at(index + 1)];
|
|
227
|
+
if (word === 'cross-env' || word === 'env') {
|
|
228
|
+
index++;
|
|
229
|
+
skip(isAssignment);
|
|
230
|
+
}
|
|
231
|
+
else if (word === 'dotenv' || (word === 'npm' && next === 'exec')) {
|
|
232
|
+
const end = words.indexOf('--', index);
|
|
233
|
+
index = end === -1 ? index + 2 : end + 1;
|
|
234
|
+
}
|
|
235
|
+
else if (word === 'npx' || word === 'bunx') {
|
|
236
|
+
index++;
|
|
237
|
+
skip((item) => item.startsWith('-'));
|
|
238
|
+
}
|
|
239
|
+
else if ((word === 'pnpm' && (next === 'exec' || next === 'dlx')) ||
|
|
240
|
+
(word === 'yarn' && next === 'exec') ||
|
|
241
|
+
(word === 'bun' && next === 'x')) {
|
|
242
|
+
index += 2;
|
|
243
|
+
}
|
|
244
|
+
else if ((word === 'pnpm' || word === 'yarn') && next !== 'run') {
|
|
245
|
+
// `pnpm vitest` starts the binary when no script has its name, which the scan takes to be so.
|
|
246
|
+
index++;
|
|
247
|
+
}
|
|
248
|
+
else
|
|
249
|
+
break;
|
|
250
|
+
}
|
|
251
|
+
const word = words.at(index);
|
|
252
|
+
if (word === undefined)
|
|
253
|
+
return null;
|
|
254
|
+
if (/(^|[/\\])node(\.exe)?$/.test(word)) {
|
|
255
|
+
index++;
|
|
256
|
+
while (index < words.length && words[index].startsWith('-'))
|
|
257
|
+
index += VALUE_OPTIONS.has(words[index]) ? 2 : 1;
|
|
258
|
+
const file = /node_modules[/\\](?:\.bin[/\\]([^/\\]+)|(@[^/\\]+[/\\][^/\\]+|[^/\\]+)[/\\])/.exec(words.at(index) ?? '');
|
|
259
|
+
const program = file?.at(1) ?? RUNNER_PACKAGES[file?.at(2)?.replaceAll('\\', '/') ?? ''];
|
|
260
|
+
return program ? { program, args: words.slice(index + 1) } : null;
|
|
261
|
+
}
|
|
262
|
+
const name = word.split(/[/\\]/).at(-1);
|
|
263
|
+
return { program: name.replace(/\.(cmd|exe|[cm]?js)$/, ''), args: words.slice(index + 1) };
|
|
264
|
+
}
|
package/dist/scan.js
CHANGED
|
@@ -207,6 +207,8 @@ export async function scan(options) {
|
|
|
207
207
|
};
|
|
208
208
|
const snapshotFiles = { framework, list, read: (file) => bytesOf(root, file) };
|
|
209
209
|
const notRun = [];
|
|
210
|
+
// A file a collected test file imports runs in that file: its tests register when it loads.
|
|
211
|
+
const imported = new Set();
|
|
210
212
|
const results = [];
|
|
211
213
|
const globalsFiles = [];
|
|
212
214
|
for (const { absolutePath, relativeFilePath } of files) {
|
|
@@ -255,6 +257,11 @@ export async function scan(options) {
|
|
|
255
257
|
if (result.usesGlobals)
|
|
256
258
|
globalsFiles.push({ absolutePath, relativeFilePath });
|
|
257
259
|
// A file without tests that no config runs, such as a source file a broad pattern matches, misses nothing.
|
|
260
|
+
if (placement.runs) {
|
|
261
|
+
for (const test of result.tests)
|
|
262
|
+
for (const file of test.dependencies)
|
|
263
|
+
imported.add(file);
|
|
264
|
+
}
|
|
258
265
|
if (placement.runs === false && result.tests.length > 0) {
|
|
259
266
|
const message = `The file has tests, but no config in its folder or above runs it, so the runner doesn't collect them; the nearest config is ${config}.`;
|
|
260
267
|
notRun.push(fileDiagnostic('file-not-run', relativeFilePath, message));
|
|
@@ -275,7 +282,8 @@ export async function scan(options) {
|
|
|
275
282
|
globals = fileDiagnostic('globals-not-enabled', relativeFilePath, message);
|
|
276
283
|
break;
|
|
277
284
|
}
|
|
278
|
-
|
|
285
|
+
const neverRun = notRun.filter((diagnostic) => !imported.has(diagnostic.relativeFilePath));
|
|
286
|
+
projectDiagnostics.push(...configs.diagnostics, ...neverRun, ...(globals ? [globals] : []));
|
|
279
287
|
// After the config warnings, which may say why no file was found.
|
|
280
288
|
if (files.length === 0) {
|
|
281
289
|
projectDiagnostics.push(fileDiagnostic('no-files-matched', '.', noFiles(root, patterns, framework, placements)));
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "test-inventory",
|
|
3
|
-
"version": "0.10.
|
|
3
|
+
"version": "0.10.4",
|
|
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",
|