@provino/orchestrator 0.0.0-stage → 0.1.0-rc.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/LICENSE +21 -0
- package/README.md +8 -2
- package/dist/coverage-store.js +72 -0
- package/dist/coverage.js +112 -0
- package/dist/discover-rules.js +290 -0
- package/dist/errors.js +16 -0
- package/dist/index.d.ts +1690 -0
- package/dist/index.js +4974 -0
- package/dist/start.js +2223 -0
- package/dist/stdio.js +18 -0
- package/dist/worker/bootstrap.d.ts +1 -0
- package/dist/worker/bootstrap.js +25 -0
- package/dist/worker/index.d.ts +301 -0
- package/dist/worker/index.js +3 -0
- package/dist/worker/main.d.ts +8 -0
- package/dist/worker/main.js +24 -0
- package/package.json +66 -3
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Pixel Perfect Software
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,3 +1,9 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @provino/orchestrator
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
The coordinator and the worker runtime: file discovery, ordering and sharding, the worker pool (forks, threads or inline), the connection to each worker, global setup and teardown, the run lifecycle (bail, signals, exit codes) and the code that runs inside each worker.
|
|
4
|
+
|
|
5
|
+
This package is a building block of [Provino](https://github.com/pixel-perfect-software/provino), a test runner that is pre-alpha and not on npm yet. The `provino` package ships every `@provino/*` package inlined in one bundle, so you install `provino`, not this package.
|
|
6
|
+
|
|
7
|
+
**Versioning:** this package is `@beta` as a whole. There is no semver promise for it before 1.0, and its API can change in any release.
|
|
8
|
+
|
|
9
|
+
[MIT](https://github.com/pixel-perfect-software/provino/blob/main/LICENSE)
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
import { t as OrchestratorError } from "./errors.js";
|
|
2
|
+
import { expandIstanbulData } from "@provino/coverage/node";
|
|
3
|
+
|
|
4
|
+
// src/coverage-store.ts
|
|
5
|
+
function badEvent(why, cause) {
|
|
6
|
+
return new OrchestratorError("ORCH_BAD_EVENT", `A worker sent a coverage event ${why}`, cause === void 0 ? void 0 : { cause });
|
|
7
|
+
}
|
|
8
|
+
/**
|
|
9
|
+
* Creates the store of one run.
|
|
10
|
+
* @public
|
|
11
|
+
*/
|
|
12
|
+
function createRawCoverageStore() {
|
|
13
|
+
const entries = [];
|
|
14
|
+
/** Per worker: the maps its Istanbul files came with. A worker's takes arrive in order. */
|
|
15
|
+
const known = /* @__PURE__ */ new Map();
|
|
16
|
+
/** The paths whose V8 module the store holds with its code, and their keys. */
|
|
17
|
+
const v8Paths = /* @__PURE__ */ new Set();
|
|
18
|
+
const v8Modules = /* @__PURE__ */ new Set();
|
|
19
|
+
return {
|
|
20
|
+
entries,
|
|
21
|
+
v8Modules,
|
|
22
|
+
add(workerId, event) {
|
|
23
|
+
if (event.payload.type !== "json") throw badEvent(`with a ${event.payload.type} payload, which the coordinator does not read yet`);
|
|
24
|
+
let raw;
|
|
25
|
+
try {
|
|
26
|
+
raw = JSON.parse(event.payload.json);
|
|
27
|
+
} catch (cause) {
|
|
28
|
+
throw badEvent("whose payload is not JSON", cause);
|
|
29
|
+
}
|
|
30
|
+
if (raw.kind === "istanbul") {
|
|
31
|
+
let maps = known.get(workerId);
|
|
32
|
+
if (maps === void 0) {
|
|
33
|
+
maps = /* @__PURE__ */ new Map();
|
|
34
|
+
known.set(workerId, maps);
|
|
35
|
+
}
|
|
36
|
+
let expanded;
|
|
37
|
+
try {
|
|
38
|
+
expanded = {
|
|
39
|
+
...raw,
|
|
40
|
+
data: expandIstanbulData(maps, raw.data)
|
|
41
|
+
};
|
|
42
|
+
} catch (cause) {
|
|
43
|
+
throw badEvent("that cannot be expanded", cause);
|
|
44
|
+
}
|
|
45
|
+
entries.push(expanded);
|
|
46
|
+
return expanded;
|
|
47
|
+
}
|
|
48
|
+
if (raw.kind !== "v8") throw badEvent("of an unknown kind");
|
|
49
|
+
if (raw.modules === void 0) {
|
|
50
|
+
entries.push(raw);
|
|
51
|
+
return raw;
|
|
52
|
+
}
|
|
53
|
+
const modules = raw.modules.map((info) => {
|
|
54
|
+
if (!("code" in info)) return info;
|
|
55
|
+
if (v8Paths.has(info.url)) {
|
|
56
|
+
const { code: _code, map: _map, ...ref } = info;
|
|
57
|
+
return ref;
|
|
58
|
+
}
|
|
59
|
+
v8Paths.add(info.url);
|
|
60
|
+
v8Modules.add(info.transformKey);
|
|
61
|
+
return info;
|
|
62
|
+
});
|
|
63
|
+
entries.push({
|
|
64
|
+
...raw,
|
|
65
|
+
modules
|
|
66
|
+
});
|
|
67
|
+
return raw;
|
|
68
|
+
}
|
|
69
|
+
};
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
export { createRawCoverageStore };
|
package/dist/coverage.js
ADDED
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
import { t as crawlFiles } from "./discover-rules.js";
|
|
2
|
+
import { serializeError } from "@provino/rpc";
|
|
3
|
+
import { createCoverageFilter, loadCoverageReporting, loadInstrumenter } from "@provino/coverage/node";
|
|
4
|
+
|
|
5
|
+
// src/coverage.ts
|
|
6
|
+
/**
|
|
7
|
+
* The files of `project` that its include globs name and its filter counts: the candidates for
|
|
8
|
+
* coverage of a file no test loaded. Jest's `hasteFS.matchFilesWithGlob(collectCoverageFrom,
|
|
9
|
+
* rootDir)` over its project's crawl, then `shouldInstrument`.
|
|
10
|
+
*/
|
|
11
|
+
async function untestedCandidates(project) {
|
|
12
|
+
const coverage = project.config.coverage;
|
|
13
|
+
if (coverage === void 0 || coverage.include.length === 0) return [];
|
|
14
|
+
if (!project.policy.coverage.includeUntestedByDefault) return [];
|
|
15
|
+
const { discovery } = project;
|
|
16
|
+
const files = await crawlFiles(discovery ?? {
|
|
17
|
+
roots: [project.rootDir],
|
|
18
|
+
extensions: project.config.loader.extensions.map((extension) => extension.replace(/^\./, "")),
|
|
19
|
+
crawlIgnorePatterns: []
|
|
20
|
+
});
|
|
21
|
+
const counted = createCoverageFilter(coverage);
|
|
22
|
+
return files.filter((path) => counted(path)).sort();
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* Merges what the workers sent, adds the files no test loaded, remaps, and sums the run's coverage.
|
|
26
|
+
* `projects` are the projects that ran a file, in the run's order: a file two of them name is
|
|
27
|
+
* covered for the first. `first` is the run's first project, whose policy words the threshold
|
|
28
|
+
* failures: it is `projects[0]` unless no project had a file (an empty run still checks its
|
|
29
|
+
* thresholds, as Jest's CoverageReporter does over an empty map).
|
|
30
|
+
* @public
|
|
31
|
+
*/
|
|
32
|
+
async function finishCoverage(store, projects, options = {}, first = projects[0]) {
|
|
33
|
+
const reporting = await loadCoverageReporting();
|
|
34
|
+
const aggregate = reporting.createCoverageAggregate();
|
|
35
|
+
for (const raw of store.entries) aggregate.add(raw);
|
|
36
|
+
const v8 = first?.config.coverage?.provider === "v8";
|
|
37
|
+
const emptyV8 = [];
|
|
38
|
+
const untestedFailures = [];
|
|
39
|
+
const candidates = await Promise.all(projects.map((project) => untestedCandidates(project)));
|
|
40
|
+
if (candidates.reduce((sum, list) => sum + list.length, 0) > 0) {
|
|
41
|
+
options.onUntested?.start();
|
|
42
|
+
try {
|
|
43
|
+
const seen = /* @__PURE__ */ new Set();
|
|
44
|
+
for (const [index, project] of projects.entries()) {
|
|
45
|
+
const paths = (candidates[index] ?? []).filter((path) => {
|
|
46
|
+
if (seen.has(path) || aggregate.has(path)) return false;
|
|
47
|
+
seen.add(path);
|
|
48
|
+
return true;
|
|
49
|
+
});
|
|
50
|
+
if (paths.length === 0) continue;
|
|
51
|
+
if (v8) {
|
|
52
|
+
for (const path of paths) try {
|
|
53
|
+
emptyV8.push(reporting.emptyV8Coverage(path));
|
|
54
|
+
} catch (error) {
|
|
55
|
+
untestedFailures.push({
|
|
56
|
+
path,
|
|
57
|
+
error: serializeError(error)
|
|
58
|
+
});
|
|
59
|
+
}
|
|
60
|
+
continue;
|
|
61
|
+
}
|
|
62
|
+
await coverUntested(project, paths, aggregate.addUntested, untestedFailures);
|
|
63
|
+
}
|
|
64
|
+
} finally {
|
|
65
|
+
options.onUntested?.end();
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
const remapped = v8 && first !== void 0 ? await reporting.convertV8Coverage(aggregate.v8, emptyV8, {
|
|
69
|
+
conversion: first.policy.coverage.v8Conversion,
|
|
70
|
+
hashbang: first.policy.coverage.v8Hashbang
|
|
71
|
+
}) : await reporting.remapCoverage(aggregate.map);
|
|
72
|
+
const map = Object.fromEntries(remapped.map.files().map((path) => [path, remapped.map.fileCoverageFor(path).toJSON()]));
|
|
73
|
+
const policy = first?.policy.coverage;
|
|
74
|
+
const thresholdFailures = policy === void 0 || options.thresholds === void 0 ? [] : reporting.checkThresholds(remapped.map, options.thresholds, policy, { cwd: options.thresholdsCwd ?? process.cwd() });
|
|
75
|
+
return {
|
|
76
|
+
totals: reporting.coverageTotals(remapped.map),
|
|
77
|
+
thresholdFailures,
|
|
78
|
+
map,
|
|
79
|
+
...Object.keys(remapped.sources).length === 0 ? {} : { sources: remapped.sources },
|
|
80
|
+
...untestedFailures.length === 0 ? {} : { untestedFailures }
|
|
81
|
+
};
|
|
82
|
+
}
|
|
83
|
+
/**
|
|
84
|
+
* Each of `paths` through `project`'s transform with the instrumenter (the coordinator's own loader,
|
|
85
|
+
* as a worker would load it), its initial coverage added. A file that fails is a failure of its
|
|
86
|
+
* own, as Jest prints one and goes on.
|
|
87
|
+
*/
|
|
88
|
+
async function coverUntested(project, paths, add, failures) {
|
|
89
|
+
const coverage = project.config.coverage;
|
|
90
|
+
if (coverage === void 0) return;
|
|
91
|
+
const [{ createCoordinatorLoader }, { istanbulInstrumenter, readInitialCoverage }] = await Promise.all([import("@provino/loader"), loadInstrumenter()]);
|
|
92
|
+
const loader = await createCoordinatorLoader(project.rootDir, project.config.loader, project.policy.module, { coverage: {
|
|
93
|
+
instrumenter: istanbulInstrumenter({ coverageVariable: project.policy.coverage.istanbulVariable }),
|
|
94
|
+
shouldInstrument: createCoverageFilter(coverage)
|
|
95
|
+
} });
|
|
96
|
+
try {
|
|
97
|
+
for (const path of paths) try {
|
|
98
|
+
const { code } = loader.transformForCoverage(path);
|
|
99
|
+
const initial = readInitialCoverage(code);
|
|
100
|
+
if (initial !== null) add(initial.coverageData);
|
|
101
|
+
} catch (error) {
|
|
102
|
+
failures.push({
|
|
103
|
+
path,
|
|
104
|
+
error: serializeError(error)
|
|
105
|
+
});
|
|
106
|
+
}
|
|
107
|
+
} finally {
|
|
108
|
+
loader[Symbol.dispose]();
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
export { finishCoverage };
|
|
@@ -0,0 +1,290 @@
|
|
|
1
|
+
import { t as OrchestratorError } from "./errors.js";
|
|
2
|
+
import { readdir, stat } from "node:fs/promises";
|
|
3
|
+
import { join, relative, resolve, sep } from "node:path";
|
|
4
|
+
import picomatch from "picomatch";
|
|
5
|
+
import { hash } from "node:crypto";
|
|
6
|
+
|
|
7
|
+
// src/file-id.ts
|
|
8
|
+
/**
|
|
9
|
+
* A file's task id: a SHA-1 over `<project>\0<path>`, cut to 10 hex characters. `relativePath` is
|
|
10
|
+
* the file's path relative to the project's root, with POSIX separators. The id is stable across
|
|
11
|
+
* runs and workers, and every task id in the file derives from it.
|
|
12
|
+
* @public
|
|
13
|
+
*/
|
|
14
|
+
function fileIdOf(project, relativePath) {
|
|
15
|
+
return hash("sha1", `${project}\0${relativePath}`).slice(0, 10);
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* `file` relative to `rootDir`, with `/` separators on every platform: the form task ids,
|
|
19
|
+
* reporters and the results cache know a file by (and what `fileIdOf` takes).
|
|
20
|
+
* @public
|
|
21
|
+
*/
|
|
22
|
+
function relativePosix(rootDir, file) {
|
|
23
|
+
return relative(rootDir, file).split(sep).join("/");
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
// src/util.ts
|
|
27
|
+
/**
|
|
28
|
+
* Whether a run passes with no tests: the run's own option (`--passWithNoTests`) when it has one,
|
|
29
|
+
* else the project's `orchestrator.passWithNoTests`. `exitCodeFor` (a run that found no file) and
|
|
30
|
+
* `runProjects` (a file that declares no test) both ask.
|
|
31
|
+
*/
|
|
32
|
+
function passesWithNoTests(option, orchestrator) {
|
|
33
|
+
return option ?? orchestrator.passWithNoTests;
|
|
34
|
+
}
|
|
35
|
+
/** `-1`, `0` or `1` by UTF-16 code unit order, which is the same on every machine (`localeCompare` is not). */
|
|
36
|
+
function byText(a, b) {
|
|
37
|
+
return a < b ? -1 : a > b ? 1 : 0;
|
|
38
|
+
}
|
|
39
|
+
/** The message of a thrown value: an `Error`'s own, else the value as text. */
|
|
40
|
+
function messageOf(error) {
|
|
41
|
+
return error instanceof Error ? error.message : String(error);
|
|
42
|
+
}
|
|
43
|
+
/** An object that is no array: the shape of a parsed JSON record or of a module's exports. */
|
|
44
|
+
function isRecord(value) {
|
|
45
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
46
|
+
}
|
|
47
|
+
/** What `raceAbort` resolves with when the signal came first. */
|
|
48
|
+
const ABORTED = Symbol("aborted");
|
|
49
|
+
/**
|
|
50
|
+
* `work`'s outcome, or `ABORTED` as soon as `signal` aborts (at once when it already has). Work
|
|
51
|
+
* that can't be cancelled (a hook that hangs) is left running: what it throws after that is
|
|
52
|
+
* nobody's to report, and the listener on `signal` is gone as soon as the race is decided.
|
|
53
|
+
*/
|
|
54
|
+
async function raceAbort(work, signal) {
|
|
55
|
+
work.catch(() => void 0);
|
|
56
|
+
if (signal.aborted) return ABORTED;
|
|
57
|
+
const aborted = Promise.withResolvers();
|
|
58
|
+
const onAbort = () => aborted.resolve(ABORTED);
|
|
59
|
+
signal.addEventListener("abort", onAbort, { once: true });
|
|
60
|
+
try {
|
|
61
|
+
return await Promise.race([work, aborted.promise]);
|
|
62
|
+
} finally {
|
|
63
|
+
signal.removeEventListener("abort", onAbort);
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
/** `fn` over `items`, a bounded number at a time; the results are in the items' order. */
|
|
67
|
+
async function mapInBatches(items, size, fn) {
|
|
68
|
+
const results = [];
|
|
69
|
+
for (let from = 0; from < items.length; from += size) results.push(...await Promise.all(items.slice(from, from + size).map((item) => fn(item))));
|
|
70
|
+
return results;
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
// src/discover-rules.ts
|
|
74
|
+
/** jest-haste-map always ignores these (`VCS_DIRECTORIES`), and files under `node_modules` unless it retains all. */
|
|
75
|
+
const ALWAYS_IGNORED_DIRECTORIES = /* @__PURE__ */ new Set([
|
|
76
|
+
"node_modules",
|
|
77
|
+
".git",
|
|
78
|
+
".hg",
|
|
79
|
+
".sl"
|
|
80
|
+
]);
|
|
81
|
+
const NODE_MODULES = `${sep}node_modules${sep}`;
|
|
82
|
+
const VCS_PATH = [
|
|
83
|
+
`${sep}.git${sep}`,
|
|
84
|
+
`${sep}.hg${sep}`,
|
|
85
|
+
`${sep}.sl${sep}`
|
|
86
|
+
];
|
|
87
|
+
/** How many directories are read at once. */
|
|
88
|
+
const CONCURRENCY = 64;
|
|
89
|
+
/** `new RegExp` of the sources joined by `|`, as Jest builds its ignore patterns; none: undefined. */
|
|
90
|
+
function alternation(sources, what) {
|
|
91
|
+
if (sources.length === 0) return void 0;
|
|
92
|
+
try {
|
|
93
|
+
return new RegExp(sources.join("|"));
|
|
94
|
+
} catch (cause) {
|
|
95
|
+
throw new OrchestratorError("ORCH_BAD_PATTERN", `${what} ${JSON.stringify(sources)} is not a valid regular expression`, { cause });
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
/** jest-util `replacePathSepForGlob` (a no-op on POSIX paths without a backslash). */
|
|
99
|
+
function replacePathSepForGlob(path) {
|
|
100
|
+
return path.replaceAll(/\\(?![$()+.?^{}])/g, "/");
|
|
101
|
+
}
|
|
102
|
+
/**
|
|
103
|
+
* jest-util `globsToMatcher` with `dot: true`: every glob that matches keeps the path, every
|
|
104
|
+
* negated glob that does not match drops it, the last verdict wins; with only negated globs a path
|
|
105
|
+
* is kept unless dropped.
|
|
106
|
+
*/
|
|
107
|
+
function globsToMatcher(globs) {
|
|
108
|
+
if (globs.length === 0) return () => false;
|
|
109
|
+
const matchers = globs.map((glob) => {
|
|
110
|
+
let isMatch;
|
|
111
|
+
try {
|
|
112
|
+
isMatch = picomatch(glob, { dot: true }, true);
|
|
113
|
+
} catch (cause) {
|
|
114
|
+
throw new OrchestratorError("ORCH_BAD_PATTERN", `the test glob "${glob}" is not valid`, { cause });
|
|
115
|
+
}
|
|
116
|
+
const state = isMatch.state;
|
|
117
|
+
return {
|
|
118
|
+
isMatch,
|
|
119
|
+
negated: state.negated === true || state.negatedExtglob === true
|
|
120
|
+
};
|
|
121
|
+
});
|
|
122
|
+
const onlyNegated = matchers.every(({ negated }) => negated);
|
|
123
|
+
return (path) => {
|
|
124
|
+
const replaced = replacePathSepForGlob(path);
|
|
125
|
+
let kept;
|
|
126
|
+
for (const { isMatch, negated } of matchers) {
|
|
127
|
+
const matched = isMatch(replaced);
|
|
128
|
+
if (!matched && negated) kept = false;
|
|
129
|
+
else if (matched && !negated) kept = true;
|
|
130
|
+
}
|
|
131
|
+
return onlyNegated ? kept !== false : kept === true;
|
|
132
|
+
};
|
|
133
|
+
}
|
|
134
|
+
/** The sources as regular expressions: a path matches when any of them does. */
|
|
135
|
+
function regexMatcher(sources) {
|
|
136
|
+
const regexes = sources.map((source) => {
|
|
137
|
+
try {
|
|
138
|
+
return new RegExp(source);
|
|
139
|
+
} catch (cause) {
|
|
140
|
+
throw new OrchestratorError("ORCH_BAD_PATTERN", `the test regular expression ${JSON.stringify(source)} is not valid`, { cause });
|
|
141
|
+
}
|
|
142
|
+
});
|
|
143
|
+
return (path) => regexes.some((regex) => regex.test(path));
|
|
144
|
+
}
|
|
145
|
+
/**
|
|
146
|
+
* The test-file predicate of a project's rules, on an absolute path: roots are the crawl's, so
|
|
147
|
+
* this is `testMatch` or `testRegex`, and not matching `excludePatterns`. The crawl applies it to
|
|
148
|
+
* every file it keeps.
|
|
149
|
+
* @public
|
|
150
|
+
*/
|
|
151
|
+
function testFilePredicate(options) {
|
|
152
|
+
const { rootDir, discovery, globMatchesOn } = options;
|
|
153
|
+
const { includePatterns } = discovery;
|
|
154
|
+
const matches = includePatterns.kind === "regex" ? regexMatcher(includePatterns.patterns) : (() => {
|
|
155
|
+
const glob = globsToMatcher(includePatterns.patterns);
|
|
156
|
+
return globMatchesOn === "absolute-path" ? glob : (path) => glob(relativePosix(rootDir, path));
|
|
157
|
+
})();
|
|
158
|
+
const ignored = alternation(discovery.excludePatterns, "testPathIgnorePatterns");
|
|
159
|
+
return (path) => matches(path) && !(ignored?.test(path) ?? false);
|
|
160
|
+
}
|
|
161
|
+
/** Every file under `root` that the crawl keeps: no symlinks, no ignored path, a listed extension. */
|
|
162
|
+
async function crawlRoot(root, extensions, crawlIgnore, found) {
|
|
163
|
+
const pending = [root];
|
|
164
|
+
let active = 0;
|
|
165
|
+
await new Promise((done, fail) => {
|
|
166
|
+
const pump = () => {
|
|
167
|
+
while (active < CONCURRENCY && pending.length > 0) {
|
|
168
|
+
const directory = pending.pop();
|
|
169
|
+
active++;
|
|
170
|
+
readdir(directory, { withFileTypes: true }).then((entries) => {
|
|
171
|
+
for (const entry of entries) {
|
|
172
|
+
if (entry.isSymbolicLink()) continue;
|
|
173
|
+
const path = join(directory, entry.name);
|
|
174
|
+
if (entry.isDirectory()) {
|
|
175
|
+
if (!ALWAYS_IGNORED_DIRECTORIES.has(entry.name)) pending.push(path);
|
|
176
|
+
} else if (entry.isFile()) {
|
|
177
|
+
const dot = entry.name.lastIndexOf(".");
|
|
178
|
+
if (dot < 0 || !extensions.has(entry.name.slice(dot + 1).toLowerCase())) continue;
|
|
179
|
+
if (path.includes(NODE_MODULES) || VCS_PATH.some((vcs) => path.includes(vcs))) continue;
|
|
180
|
+
if (crawlIgnore?.test(path) === true) continue;
|
|
181
|
+
found.add(path);
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
active--;
|
|
185
|
+
if (active === 0 && pending.length === 0) done();
|
|
186
|
+
else pump();
|
|
187
|
+
}, (error) => {
|
|
188
|
+
active--;
|
|
189
|
+
if (error.code === "ENOENT" || error.code === "EACCES" || error.code === "ENOTDIR") {
|
|
190
|
+
if (active === 0 && pending.length === 0) done();
|
|
191
|
+
else pump();
|
|
192
|
+
return;
|
|
193
|
+
}
|
|
194
|
+
fail(error);
|
|
195
|
+
});
|
|
196
|
+
}
|
|
197
|
+
if (active === 0 && pending.length === 0) done();
|
|
198
|
+
};
|
|
199
|
+
pump();
|
|
200
|
+
});
|
|
201
|
+
}
|
|
202
|
+
/**
|
|
203
|
+
* Finds a project's test files by a dialect reader's rules. The result is sorted by relative path;
|
|
204
|
+
* a file that vanishes between the crawl and its `stat` is left out.
|
|
205
|
+
* @public
|
|
206
|
+
*/
|
|
207
|
+
async function discoverByRules(options) {
|
|
208
|
+
const { rootDir } = options;
|
|
209
|
+
const isTestFile = testFilePredicate(options);
|
|
210
|
+
return (await sized((await crawlFiles(options.discovery)).filter((path) => isTestFile(path)), rootDir)).sort((a, b) => byText(a.relativePath, b.relativePath));
|
|
211
|
+
}
|
|
212
|
+
/**
|
|
213
|
+
* Every file the crawl of a dialect reader's rules keeps, test file or not (Jest's haste map:
|
|
214
|
+
* `roots`, `extensions`, `modulePathIgnorePatterns`, no symlink, nothing under `node_modules` or a
|
|
215
|
+
* VCS directory), in no particular order. What the coverage of untested files is chosen from.
|
|
216
|
+
* @internal
|
|
217
|
+
*/
|
|
218
|
+
async function crawlFiles(discovery) {
|
|
219
|
+
const extensions = new Set(discovery.extensions.map((extension) => extension.toLowerCase()));
|
|
220
|
+
const crawlIgnore = alternation(discovery.crawlIgnorePatterns, "modulePathIgnorePatterns");
|
|
221
|
+
const found = /* @__PURE__ */ new Set();
|
|
222
|
+
await Promise.all(discovery.roots.map((root) => crawlRoot(resolve(root), extensions, crawlIgnore, found)));
|
|
223
|
+
return [...found];
|
|
224
|
+
}
|
|
225
|
+
/** Each path as a `DiscoveredFile`; one that is gone, or not a file, is left out. */
|
|
226
|
+
async function sized(paths, rootDir) {
|
|
227
|
+
const sizes = await mapInBatches(paths, 256, (path) => stat(path).then((info) => info.isFile() ? info.size : void 0, () => void 0));
|
|
228
|
+
return paths.flatMap((path, index) => {
|
|
229
|
+
const sizeBytes = sizes[index];
|
|
230
|
+
return sizeBytes === void 0 ? [] : [{
|
|
231
|
+
path,
|
|
232
|
+
relativePath: relativePosix(rootDir, path),
|
|
233
|
+
sizeBytes
|
|
234
|
+
}];
|
|
235
|
+
});
|
|
236
|
+
}
|
|
237
|
+
function escapeRegExp(text) {
|
|
238
|
+
return text.replaceAll(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
239
|
+
}
|
|
240
|
+
/**
|
|
241
|
+
* One walk of a project's roots for the affected-test graph (B23c, T9.12): every file whose
|
|
242
|
+
* extension is one of the project's module file extensions, or `snap`, with jest-haste-map's rules
|
|
243
|
+
* (no symlinks, nothing under `node_modules` or a VCS directory), leaving out what
|
|
244
|
+
* `crawlIgnorePatterns` (`modulePathIgnorePatterns`) and `options.ignorePatterns` match and a
|
|
245
|
+
* cache directory under the root (`createHasteMap` L333-342). The test files are the crawl
|
|
246
|
+
* filtered by the project's rules, or by its `include` and `exclude` globs when it has none.
|
|
247
|
+
* @public
|
|
248
|
+
*/
|
|
249
|
+
async function crawlProject(project, options = {}) {
|
|
250
|
+
const { rootDir, discovery } = project;
|
|
251
|
+
const extensions = new Set((discovery?.extensions ?? project.config.loader.extensions.map((e) => e.replace(/^\./, ""))).map((extension) => extension.toLowerCase()).concat("snap"));
|
|
252
|
+
const sources = [...discovery?.crawlIgnorePatterns ?? [], ...options.ignorePatterns ?? []];
|
|
253
|
+
const cache = project.cacheDirectory;
|
|
254
|
+
if (cache !== void 0 && resolve(cache).startsWith(resolve(rootDir) + sep)) sources.push(escapeRegExp(resolve(cache)));
|
|
255
|
+
const crawlIgnore = alternation(sources, "modulePathIgnorePatterns");
|
|
256
|
+
const found = /* @__PURE__ */ new Set();
|
|
257
|
+
const roots = discovery?.roots ?? [rootDir];
|
|
258
|
+
await Promise.all(roots.map((root) => crawlRoot(resolve(root), extensions, crawlIgnore, found)));
|
|
259
|
+
const files = [...found].sort(byText);
|
|
260
|
+
const resolvedRoots = roots.map((root) => resolve(root));
|
|
261
|
+
const keeps = (path) => {
|
|
262
|
+
if (!resolvedRoots.some((root) => path.startsWith(root + sep))) return false;
|
|
263
|
+
const dot = path.lastIndexOf(".");
|
|
264
|
+
if (dot < 0 || path.lastIndexOf(sep) > dot) return false;
|
|
265
|
+
if (!extensions.has(path.slice(dot + 1).toLowerCase())) return false;
|
|
266
|
+
if (path.includes(NODE_MODULES) || VCS_PATH.some((vcs) => path.includes(vcs))) return false;
|
|
267
|
+
return crawlIgnore?.test(path) !== true;
|
|
268
|
+
};
|
|
269
|
+
if (discovery !== null) return {
|
|
270
|
+
files,
|
|
271
|
+
keeps,
|
|
272
|
+
isTest: testFilePredicate({
|
|
273
|
+
rootDir,
|
|
274
|
+
discovery,
|
|
275
|
+
globMatchesOn: project.policy.orchestrator.globMatchesOn
|
|
276
|
+
})
|
|
277
|
+
};
|
|
278
|
+
const included = globsToMatcher(project.include);
|
|
279
|
+
const excluded = globsToMatcher(project.exclude);
|
|
280
|
+
return {
|
|
281
|
+
files,
|
|
282
|
+
keeps,
|
|
283
|
+
isTest: (path) => {
|
|
284
|
+
const relative = relativePosix(rootDir, path);
|
|
285
|
+
return included(relative) && !excluded(relative);
|
|
286
|
+
}
|
|
287
|
+
};
|
|
288
|
+
}
|
|
289
|
+
|
|
290
|
+
export { ABORTED as a, mapInBatches as c, raceAbort as d, fileIdOf as f, testFilePredicate as i, messageOf as l, crawlProject as n, byText as o, relativePosix as p, discoverByRules as r, isRecord as s, crawlFiles as t, passesWithNoTests as u };
|
package/dist/errors.js
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
// src/errors.ts
|
|
2
|
+
/**
|
|
3
|
+
* A coordinator error with a stable code. For `ORCH_WORKER_EXITED` the `cause` is the
|
|
4
|
+
* `WorkerExit`.
|
|
5
|
+
* @public
|
|
6
|
+
*/
|
|
7
|
+
var OrchestratorError = class extends Error {
|
|
8
|
+
code;
|
|
9
|
+
constructor(code, message, options) {
|
|
10
|
+
super(message, options);
|
|
11
|
+
this.name = "OrchestratorError";
|
|
12
|
+
this.code = code;
|
|
13
|
+
}
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
export { OrchestratorError as t };
|