test(main): completar fase 2 con cobertura de iconos y timing

This commit is contained in:
Pandipipas
2026-02-21 18:42:27 +01:00
parent d3d33324ff
commit 50b145a320
7 changed files with 154 additions and 16 deletions
+68
View File
@@ -122,3 +122,71 @@ test("stopNodeCG envía SIGTERM y luego SIGKILL si el proceso no sale", async ()
child.emit("exit", 0, null);
await stopPromise;
});
test("stopNodeCG reutiliza la misma promesa cuando se invoca en paralelo", async () => {
const child = new MockChildProcess(5555);
const manager = createNodecgProcessManager({
isDev: true,
nodecgPath: "/fake/nodecg",
baseUrl: "http://127.0.0.1:9090",
runtimeConfig: getBaseConfig(),
log: () => undefined,
deps: {
pathExists: () => true,
spawnProcess: () => child as unknown as import("node:child_process").ChildProcess,
fetchUrl: async () => ({ ok: false, status: 404 } as Response),
killProcess: () => undefined,
setTimer: () => 0,
stdoutWrite: () => undefined,
stderrWrite: () => undefined,
},
});
manager.startNodeCG();
const firstStop = manager.stopNodeCG();
const secondStop = manager.stopNodeCG();
assert.equal(firstStop, secondStop);
child.emit("exit", 0, null);
await firstStop;
});
test("stopNodeCG normaliza timeout negativo a cero", async () => {
const child = new MockChildProcess(7777);
const timeouts: number[] = [];
const manager = createNodecgProcessManager({
isDev: true,
nodecgPath: "/fake/nodecg",
baseUrl: "http://127.0.0.1:9090",
runtimeConfig: {
...getBaseConfig(),
nodecgKillTimeoutMs: -10,
},
log: () => undefined,
deps: {
pathExists: () => true,
spawnProcess: () => child as unknown as import("node:child_process").ChildProcess,
fetchUrl: async () => ({ ok: false, status: 404 } as Response),
killProcess: () => undefined,
setTimer: (handler, timeoutMs) => {
timeouts.push(timeoutMs);
handler();
return 0;
},
stdoutWrite: () => undefined,
stderrWrite: () => undefined,
},
});
manager.startNodeCG();
const stopPromise = manager.stopNodeCG();
assert.ok(timeouts.includes(0));
child.emit("exit", 0, null);
await stopPromise;
});