perf(test): eliminate resetModules via injectable seams

This commit is contained in:
Peter Steinberger
2026-02-13 16:20:31 +00:00
parent a844fb161c
commit b272158fe4
21 changed files with 223 additions and 188 deletions

View File

@@ -144,6 +144,19 @@ type PtySpawn = (
env?: Record<string, string>;
},
) => PtyHandle;
type PtyModule = {
spawn?: PtySpawn;
default?: { spawn?: PtySpawn };
};
type PtyModuleLoader = () => Promise<PtyModule>;
const loadPtyModuleDefault: PtyModuleLoader = async () =>
(await import("@lydell/node-pty")) as unknown as PtyModule;
let loadPtyModule: PtyModuleLoader = loadPtyModuleDefault;
export function setPtyModuleLoaderForTests(loader?: PtyModuleLoader): void {
loadPtyModule = loader ?? loadPtyModuleDefault;
}
type ExecProcessOutcome = {
status: "completed" | "failed";
@@ -477,10 +490,7 @@ async function runExecProcess(opts: {
} else if (opts.usePty) {
const { shell, args: shellArgs } = getShellConfig();
try {
const ptyModule = (await import("@lydell/node-pty")) as unknown as {
spawn?: PtySpawn;
default?: { spawn?: PtySpawn };
};
const ptyModule = await loadPtyModule();
const spawnPty = ptyModule.spawn ?? ptyModule.default?.spawn;
if (!spawnPty) {
throw new Error("PTY support is unavailable (node-pty spawn not found).");