test-inventory 0.10.2 → 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 +18 -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/frameworks/node.js +1 -0
- package/dist/frameworks/playwright.js +27 -2
- package/dist/frameworks/test-functions.d.ts +4 -0
- package/dist/frameworks/test-functions.js +60 -1
- package/dist/frameworks/vitest.js +23 -6
- package/dist/node-scripts.d.ts +16 -0
- package/dist/node-scripts.js +119 -0
- package/dist/records.js +1 -1
- package/dist/scan.js +9 -1
- package/dist/values.js +2 -2
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,23 @@
|
|
|
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
|
+
|
|
11
|
+
## 0.10.3
|
|
12
|
+
|
|
13
|
+
### Patch Changes
|
|
14
|
+
|
|
15
|
+
- [#115](https://github.com/Huldoser/test-inventory/pull/115) [`2da89f8`](https://github.com/Huldoser/test-inventory/commit/2da89f84890e2c2ce8a87954263e6ae3f27ce5bc) - Read hooks and suite members on named node:test imports and preserve parameterized declarations chosen between Jest each factories. Avoid false Playwright file-load failures for unknown loop counts, false tests from unresolved destructured wrappers, and async-describe errors caused by awaits inside nested helper declarations. Report Vitest table factories called without their required receiver as file-load failures.
|
|
16
|
+
|
|
17
|
+
- [#115](https://github.com/Huldoser/test-inventory/pull/115) [`2da89f8`](https://github.com/Huldoser/test-inventory/commit/2da89f84890e2c2ce8a87954263e6ae3f27ce5bc) - Keep declarations when a file or imported helper calls a local function named require without arguments. The value reader no longer turns that call into an internal-error that discards the file's tests. Preserve suite, test and hook roles when members are destructured from an already-bound node:test module.
|
|
18
|
+
|
|
19
|
+
- [#115](https://github.com/Huldoser/test-inventory/pull/115) [`2da89f8`](https://github.com/Huldoser/test-inventory/commit/2da89f84890e2c2ce8a87954263e6ae3f27ce5bc) - Recognize defineConfig on Playwright's original package export, including default and CommonJS imports, instead of reporting an invalid-chain error that marks the file's tests notLoaded. Keep extended test functions distinct from the package export.
|
|
20
|
+
|
|
3
21
|
## 0.10.2
|
|
4
22
|
|
|
5
23
|
### 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/frameworks/node.js
CHANGED
|
@@ -54,6 +54,8 @@ function isPlaywrightSource(source) {
|
|
|
54
54
|
/** The names a file binds to Playwright's `test`, its namespace and `mergeTests`. */
|
|
55
55
|
class PlaywrightBindings {
|
|
56
56
|
testNames = new Set();
|
|
57
|
+
/** The package's original test function also carries exports such as defineConfig; extended tests do not. */
|
|
58
|
+
moduleTests = new Set();
|
|
57
59
|
namespaces = new Set();
|
|
58
60
|
mergeTestsNames = new Set();
|
|
59
61
|
/** The import specifiers and declarators that bind those names, to tell them from local names that shadow them. */
|
|
@@ -84,9 +86,11 @@ class PlaywrightBindings {
|
|
|
84
86
|
}
|
|
85
87
|
else if (specifier.type === 'ImportDefaultSpecifier') {
|
|
86
88
|
this.testNames.add(specifier.local.name);
|
|
89
|
+
this.moduleTests.add(specifier.local.name);
|
|
87
90
|
}
|
|
88
91
|
else if (exportName(specifier.imported) === 'test') {
|
|
89
92
|
this.testNames.add(specifier.local.name);
|
|
93
|
+
this.moduleTests.add(specifier.local.name);
|
|
90
94
|
}
|
|
91
95
|
else if (exportName(specifier.imported) === 'mergeTests') {
|
|
92
96
|
this.mergeTestsNames.add(specifier.local.name);
|
|
@@ -187,6 +191,9 @@ class PlaywrightBindings {
|
|
|
187
191
|
}
|
|
188
192
|
if (this.isTestObject(init, false)) {
|
|
189
193
|
this.testNames.add(id.name);
|
|
194
|
+
const node = unwrap(init);
|
|
195
|
+
if (node.type === 'Identifier' && this.moduleTests.has(node.name))
|
|
196
|
+
this.moduleTests.add(id.name);
|
|
190
197
|
return true;
|
|
191
198
|
}
|
|
192
199
|
return false;
|
|
@@ -197,8 +204,10 @@ class PlaywrightBindings {
|
|
|
197
204
|
if (property.type === 'RestElement' || property.value.type !== 'Identifier')
|
|
198
205
|
continue;
|
|
199
206
|
const key = propertyKey(property);
|
|
200
|
-
if (key === 'test')
|
|
207
|
+
if (key === 'test') {
|
|
201
208
|
this.testNames.add(property.value.name);
|
|
209
|
+
this.moduleTests.add(property.value.name);
|
|
210
|
+
}
|
|
202
211
|
if (key === 'mergeTests')
|
|
203
212
|
this.mergeTestsNames.add(property.value.name);
|
|
204
213
|
}
|
|
@@ -248,6 +257,12 @@ export class PlaywrightAdapter {
|
|
|
248
257
|
return null;
|
|
249
258
|
const names = links.map((link) => link.name);
|
|
250
259
|
const key = names.join('.');
|
|
260
|
+
if (key === 'defineConfig' &&
|
|
261
|
+
chain &&
|
|
262
|
+
(this.bindings.isModule(chain.base) ||
|
|
263
|
+
(chain.base.type === 'Identifier' && this.bindings.moduleTests.has(chain.base.name)))) {
|
|
264
|
+
return { kind: 'other' };
|
|
265
|
+
}
|
|
251
266
|
const addedIn = ADDED_IN.get(key);
|
|
252
267
|
if (addedIn && !atLeast(this.file.version, ...addedIn)) {
|
|
253
268
|
return this.invalid(call, names, `needs Playwright ${addedIn.join('.')} or newer`, context);
|
|
@@ -367,6 +382,8 @@ export class PlaywrightAdapter {
|
|
|
367
382
|
assumeLocal(declaration, name, links, args) {
|
|
368
383
|
if (declaration.type !== 'VariableDeclarator' || !mayHoldTestObject(declaration) || !isTestName(name))
|
|
369
384
|
return false;
|
|
385
|
+
if (declaration.id.type !== 'Identifier')
|
|
386
|
+
return false;
|
|
370
387
|
if (!this.looksLikeTest(links, args))
|
|
371
388
|
return false;
|
|
372
389
|
if (!this.assumed.has(declaration)) {
|
|
@@ -396,6 +413,14 @@ export class PlaywrightAdapter {
|
|
|
396
413
|
const destructured = boundMembers(declarator.id, name);
|
|
397
414
|
if (!destructured)
|
|
398
415
|
return null;
|
|
416
|
+
const init = declarator.init ? unwrap(declarator.init) : null;
|
|
417
|
+
if (destructured.length > 0 && TEST_MEMBERS.has(destructured[0]) && init?.type === 'Identifier') {
|
|
418
|
+
const imported = this.imports.get(init.name);
|
|
419
|
+
if (imported?.node === this.file.values.declarationOf(init.name, lookup.scopes) &&
|
|
420
|
+
!this.follow(init.name, !lookup.inBody)) {
|
|
421
|
+
return null;
|
|
422
|
+
}
|
|
423
|
+
}
|
|
399
424
|
let members = this.aliases.get(declarator);
|
|
400
425
|
if (members === undefined) {
|
|
401
426
|
// Set first, so a variable defined through itself ends the lookup.
|
|
@@ -817,7 +842,7 @@ function containsAwait(fn) {
|
|
|
817
842
|
const visit = (node) => {
|
|
818
843
|
if (node.type === 'AwaitExpression' || (node.type === 'ForOfStatement' && node.await))
|
|
819
844
|
return true;
|
|
820
|
-
if (node !== fn && isFunctionNode(node))
|
|
845
|
+
if (node !== fn && (node.type === 'FunctionDeclaration' || isFunctionNode(node)))
|
|
821
846
|
return false;
|
|
822
847
|
return childNodes(node).some(visit);
|
|
823
848
|
};
|
|
@@ -45,6 +45,8 @@ export interface Dialect {
|
|
|
45
45
|
aliases?: ReadonlySet<string>;
|
|
46
46
|
/** What the module is when called, as `node:test`'s default export and `require()` are its `test`. */
|
|
47
47
|
callable?: Start;
|
|
48
|
+
/** Named exports that are the callable module itself, as node:test's `test` and `it`. */
|
|
49
|
+
moduleMembers?: ReadonlySet<string>;
|
|
48
50
|
/** The module's other members, which a chain on the callable module may start with and is then no test. */
|
|
49
51
|
others?: ReadonlySet<string>;
|
|
50
52
|
/** Whether the functions must be imported, as the runner sets no globals; `starts` are then exports only. */
|
|
@@ -161,6 +163,8 @@ export declare abstract class SuiteAdapter implements Adapter {
|
|
|
161
163
|
* `each` and `skipIf`, return a test function only when called, so their calls are never read through a variable.
|
|
162
164
|
*/
|
|
163
165
|
private alias;
|
|
166
|
+
/** Members taken from a bound module retain its exported kinds, rather than becoming test modifiers. */
|
|
167
|
+
private moduleAlias;
|
|
164
168
|
private aliasOf;
|
|
165
169
|
/**
|
|
166
170
|
* The test functions a value may hold, and whether it may also hold something else, as `process.env.CI` may. A test
|
|
@@ -11,7 +11,20 @@ export function shared(a, b) {
|
|
|
11
11
|
return other?.name === link.name && !link.args && !link.template && !other.args && !other.template;
|
|
12
12
|
};
|
|
13
13
|
const differs = a.links.findIndex((link, index) => !same(link, index));
|
|
14
|
-
|
|
14
|
+
const common = differs === -1 ? a.links : a.links.slice(0, differs);
|
|
15
|
+
const table = a.links.at(-1);
|
|
16
|
+
const otherTable = b.links.at(-1);
|
|
17
|
+
if (table &&
|
|
18
|
+
(table.name === 'each' || table.name === 'for') &&
|
|
19
|
+
otherTable?.name === table.name &&
|
|
20
|
+
!table.args &&
|
|
21
|
+
!table.template &&
|
|
22
|
+
!otherTable.args &&
|
|
23
|
+
!otherTable.template &&
|
|
24
|
+
!common.includes(table)) {
|
|
25
|
+
return { kind: a.kind, links: [...common, table] };
|
|
26
|
+
}
|
|
27
|
+
return { kind: a.kind, links: common };
|
|
15
28
|
}
|
|
16
29
|
function links(names) {
|
|
17
30
|
return names.map((name) => ({ name, args: null, template: null }));
|
|
@@ -189,6 +202,10 @@ export class SuiteBindings {
|
|
|
189
202
|
return (node.type === 'Identifier' && this.namespaces.has(node.name)) || this.dialect.isModule(node);
|
|
190
203
|
}
|
|
191
204
|
bindMember(imported, local) {
|
|
205
|
+
if (this.dialect.moduleMembers?.has(imported)) {
|
|
206
|
+
this.bindModule(local);
|
|
207
|
+
return;
|
|
208
|
+
}
|
|
192
209
|
const start = this.dialect.starts.get(imported);
|
|
193
210
|
const hook = this.dialect.hooks.get(imported);
|
|
194
211
|
if (start)
|
|
@@ -303,6 +320,18 @@ export class SuiteAdapter {
|
|
|
303
320
|
if (base.type === 'CallExpression' && this.dialect.isModule(base))
|
|
304
321
|
return this.member(chainLinks);
|
|
305
322
|
if (base.type === 'CallExpression') {
|
|
323
|
+
const callee = unwrap(base.callee);
|
|
324
|
+
if (callee.type === 'ConditionalExpression' || callee.type === 'LogicalExpression') {
|
|
325
|
+
const chosen = this.aliasOf(callee, lookup);
|
|
326
|
+
const last = chosen?.links.at(-1);
|
|
327
|
+
if (!chosen || !last || last.args || last.template)
|
|
328
|
+
return null;
|
|
329
|
+
return {
|
|
330
|
+
kind: chosen.kind,
|
|
331
|
+
index: 0,
|
|
332
|
+
modifiers: [...chosen.links.slice(0, -1), { ...last, args: base.arguments }],
|
|
333
|
+
};
|
|
334
|
+
}
|
|
306
335
|
const returned = this.returned(base, chainLinks, args, lookup);
|
|
307
336
|
return returned && { kind: returned.kind, index: 0, modifiers: returned.links };
|
|
308
337
|
}
|
|
@@ -326,6 +355,13 @@ export class SuiteAdapter {
|
|
|
326
355
|
// A parameter's declaration is its function: `describe('market orders', (test) => { test(...) })`.
|
|
327
356
|
if (this.suiteParameters.get(declaration) === base.name)
|
|
328
357
|
return { kind: 'test', index: 0 };
|
|
358
|
+
const moduleAlias = declaration.type === 'VariableDeclarator' ? this.moduleAlias(declaration, base.name, lookup) : null;
|
|
359
|
+
if (moduleAlias) {
|
|
360
|
+
const member = this.member([...links(moduleAlias), ...chainLinks]);
|
|
361
|
+
return member && member.index >= moduleAlias.length
|
|
362
|
+
? { ...member, index: member.index - moduleAlias.length }
|
|
363
|
+
: null;
|
|
364
|
+
}
|
|
329
365
|
const followed = this.imports.get(base.name)?.node === declaration &&
|
|
330
366
|
this.worthFollowing(base.name, chainLinks, args) &&
|
|
331
367
|
this.follow(base.name, !inBody && mayDeclareTests(base.name, chainLinks));
|
|
@@ -389,6 +425,23 @@ export class SuiteAdapter {
|
|
|
389
425
|
}
|
|
390
426
|
return alias && { kind: alias.kind, links: [...alias.links, ...links(destructured)] };
|
|
391
427
|
}
|
|
428
|
+
/** Members taken from a bound module retain its exported kinds, rather than becoming test modifiers. */
|
|
429
|
+
moduleAlias(declarator, name, lookup) {
|
|
430
|
+
if (!declarator.init)
|
|
431
|
+
return null;
|
|
432
|
+
const init = unwrap(declarator.init);
|
|
433
|
+
if (!this.bindings.isNamespace(init))
|
|
434
|
+
return null;
|
|
435
|
+
if (init.type === 'Identifier') {
|
|
436
|
+
const declaration = this.file.values.declarationOf(init.name, lookup.scopes);
|
|
437
|
+
if (declaration === null || !this.bindings.declarations.has(declaration))
|
|
438
|
+
return null;
|
|
439
|
+
}
|
|
440
|
+
let members = boundMembers(declarator.id, name);
|
|
441
|
+
while (members && this.dialect.moduleMembers?.has(members[0]))
|
|
442
|
+
members = members.slice(1);
|
|
443
|
+
return members;
|
|
444
|
+
}
|
|
392
445
|
aliasOf(expression, lookup) {
|
|
393
446
|
const functions = this.choices(expression, lookup)?.functions ?? [];
|
|
394
447
|
if (functions.length === 0)
|
|
@@ -512,6 +565,12 @@ export class SuiteAdapter {
|
|
|
512
565
|
if (callee.type !== 'Identifier')
|
|
513
566
|
return null;
|
|
514
567
|
const declaration = this.file.values.declarationOf(callee.name, context.scopes);
|
|
568
|
+
const members = declaration?.type === 'VariableDeclarator' ? this.moduleAlias(declaration, callee.name, context) : null;
|
|
569
|
+
if (members?.length === 1) {
|
|
570
|
+
const hook = this.dialect.hooks.get(members[0]);
|
|
571
|
+
if (hook)
|
|
572
|
+
return this.hook(call, hook, context);
|
|
573
|
+
}
|
|
515
574
|
const hook = declaration === null
|
|
516
575
|
? this.dialect.hooks.get(callee.name)
|
|
517
576
|
: this.bindings.declarations.has(declaration) && this.bindings.hooks.get(callee.name);
|
|
@@ -179,14 +179,31 @@ export class VitestAdapter extends SuiteAdapter {
|
|
|
179
179
|
*/
|
|
180
180
|
unboundCall(call, context) {
|
|
181
181
|
const callee = unwrap(call.callee);
|
|
182
|
-
if (callee.type
|
|
182
|
+
if (callee.type === 'CallExpression')
|
|
183
|
+
return this.unboundCall(callee, context);
|
|
184
|
+
if (callee.type === 'Identifier') {
|
|
185
|
+
const found = this.destructuredMember(callee.name, context);
|
|
186
|
+
if (found && readsItsFunction(found.kind, found.member, this.file.version)) {
|
|
187
|
+
const from = snippet(text(this.file, found.from));
|
|
188
|
+
const message = `${callee.name} is destructured from ${from}, so it loses the test object it reads, and Vitest fails the file.`;
|
|
189
|
+
return { kind: 'invalid', problem: problem('invalid-chain', call, message, callee.name) };
|
|
190
|
+
}
|
|
191
|
+
}
|
|
192
|
+
if (callee.type !== 'Identifier' &&
|
|
193
|
+
callee.type !== 'ConditionalExpression' &&
|
|
194
|
+
callee.type !== 'LogicalExpression' &&
|
|
195
|
+
callee.type !== 'SequenceExpression') {
|
|
196
|
+
return null;
|
|
197
|
+
}
|
|
198
|
+
const chosen = this.testFunction(callee, context.scopes, (name, scopes) => context.returnsOf(name, scopes));
|
|
199
|
+
const member = chosen?.links.at(-1);
|
|
200
|
+
if (!chosen || !member || member.args || member.template)
|
|
183
201
|
return null;
|
|
184
|
-
|
|
185
|
-
if (!found || !readsItsFunction(found.kind, found.member, this.file.version))
|
|
202
|
+
if (!readsItsFunction(chosen.kind, member.name, this.file.version))
|
|
186
203
|
return null;
|
|
187
|
-
const
|
|
188
|
-
const message = `${
|
|
189
|
-
return { kind: 'invalid', problem: problem('invalid-chain', call, message,
|
|
204
|
+
const source = snippet(text(this.file, callee));
|
|
205
|
+
const message = `${source} is called without the test or describe function it reads as this, so Vitest fails the file.`;
|
|
206
|
+
return { kind: 'invalid', problem: problem('invalid-chain', call, message, source) };
|
|
190
207
|
}
|
|
191
208
|
chainCall(call, context) {
|
|
192
209
|
const chain = readChain(call.callee);
|
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/records.js
CHANGED
|
@@ -650,7 +650,7 @@ class RecordBuilder {
|
|
|
650
650
|
const titles = describes.flatMap((scope) => suiteOf(scope).declaration.title?.text ?? []).reverse();
|
|
651
651
|
// In a loop, a title path that never changes is registered again on each pass.
|
|
652
652
|
const repeated = playwright &&
|
|
653
|
-
test.passes.some((passes) => passes
|
|
653
|
+
test.passes.some((passes) => passes !== null && passes > 1) &&
|
|
654
654
|
describes.every((scope) => !suiteOf(scope).declaration.title?.isDynamic);
|
|
655
655
|
if (repeated) {
|
|
656
656
|
const message = 'The test is declared in a loop with the same title on each pass, so Playwright fails to load the file and runs no tests at all.';
|
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/dist/values.js
CHANGED
|
@@ -897,7 +897,7 @@ function localRequire(expression) {
|
|
|
897
897
|
const node = unwrap(expression);
|
|
898
898
|
if (node.type !== 'CallExpression' || node.callee.type !== 'Identifier' || node.callee.name !== 'require')
|
|
899
899
|
return null;
|
|
900
|
-
const
|
|
901
|
-
const isLocal = argument
|
|
900
|
+
const argument = node.arguments.at(0);
|
|
901
|
+
const isLocal = argument?.type === 'Literal' && typeof argument.value === 'string' && /^\.\.?\//.test(argument.value);
|
|
902
902
|
return isLocal ? argument.value : null;
|
|
903
903
|
}
|
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",
|