mirror of
https://github.com/morluto/rea.git
synced 2026-11-21 22:15:50 +00:00
test: prune redundant and implementation-coupled coverage
This commit is contained in:
1 parent
14b15ba8a5
commit
48e27e19b7
191 files changed
+2757
-5418
No files matched your search
+18
-29
@@ -1,37 +1,26 @@
|
||||
/** Closers of process-owned CLI resources, by owner name. */
|
||||
export class CliResourceOwners {
|
||||
readonly #closers = new Map<string, () => Promise<void>>();
|
||||
|
||||
/** Register an owner's closer; a repeated name keeps its first closer. */
|
||||
own(name: string, close: () => Promise<void>): void {
|
||||
if (!this.#closers.has(name)) this.#closers.set(name, close);
|
||||
}
|
||||
|
||||
/** Settle every owner, then report each failure. */
|
||||
async close(): Promise<void> {
|
||||
const results = await Promise.allSettled(
|
||||
[...this.#closers.values()].map((close) => close()),
|
||||
);
|
||||
const failures = results.flatMap((result) =>
|
||||
result.status === "rejected" ? [result.reason] : [],
|
||||
);
|
||||
if (failures.length === 1) throw failures[0];
|
||||
if (failures.length > 1)
|
||||
throw new AggregateError(failures, "CLI resource cleanup failed");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Process-owned CLI resources. Each owning module registers its closer when it
|
||||
* loads, so a CLI that loads only some command families closes exactly the
|
||||
* owners it loaded without importing the others.
|
||||
* loads, so a CLI closes only the command families it loaded.
|
||||
*/
|
||||
const processOwners = new CliResourceOwners();
|
||||
const closers = new Map<string, () => Promise<void>>();
|
||||
|
||||
/** Register an owner's closer. A repeated name keeps its first closer. */
|
||||
export const ownCliProcessResource = (
|
||||
name: string,
|
||||
close: () => Promise<void>,
|
||||
): void => processOwners.own(name, close);
|
||||
): void => {
|
||||
if (!closers.has(name)) closers.set(name, close);
|
||||
};
|
||||
|
||||
/** Close every process-owned resource used by CLI commands. */
|
||||
export const closeCliResources = (): Promise<void> => processOwners.close();
|
||||
/** Settle every process-owned resource, then report each failure. */
|
||||
export const closeCliResources = async (): Promise<void> => {
|
||||
const results = await Promise.allSettled(
|
||||
[...closers.values()].map((close) => close()),
|
||||
);
|
||||
const failures = results.flatMap((result) =>
|
||||
result.status === "rejected" ? [result.reason] : [],
|
||||
);
|
||||
if (failures.length === 1) throw failures[0];
|
||||
if (failures.length > 1)
|
||||
throw new AggregateError(failures, "CLI resource cleanup failed");
|
||||
};
|
||||
Reference in new issue
Block a user