mirror of
https://github.com/Pandipipas/scoreko-electron-dev.git
synced 2026-06-06 05:32:06 +00:00
feat: Implement application bootstrap and window management
- Added bootstrap functionality to initialize the Electron application. - Created a new paths module to manage application paths and URLs. - Introduced a shutdown service to handle graceful application shutdowns. - Refactored error logging to use a dedicated logger module. - Implemented process killing logic for NodeCG processes across platforms. - Established navigation policies for internal and external URL handling in windows. - Developed window service for creating and managing application windows. - Added tests for application paths, application controller, navigation policies, process killer, and shutdown service.
This commit is contained in:
@@ -0,0 +1,65 @@
|
||||
import assert from "node:assert/strict";
|
||||
import { EventEmitter } from "node:events";
|
||||
import { SpawnOptions } from "node:child_process";
|
||||
import test from "node:test";
|
||||
|
||||
import { killProcessTree } from "../main/nodecg/platform-process-killer";
|
||||
|
||||
test("killProcessTree validates pid before building Windows taskkill command", () => {
|
||||
const spawnCalls: Array<{ command: string; args: string[]; options: SpawnOptions }> = [];
|
||||
|
||||
const killed = killProcessTree(Number.NaN, "SIGTERM", {
|
||||
platform: "win32",
|
||||
spawnProcess: (command, args, options) => {
|
||||
spawnCalls.push({ command, args, options });
|
||||
return new EventEmitter() as import("node:child_process").ChildProcess;
|
||||
},
|
||||
killProcess: () => undefined,
|
||||
log: () => undefined,
|
||||
});
|
||||
|
||||
assert.equal(killed, false);
|
||||
assert.deepEqual(spawnCalls, []);
|
||||
});
|
||||
|
||||
test("killProcessTree builds a narrow Windows taskkill invocation", () => {
|
||||
const spawnCalls: Array<{ command: string; args: string[]; options: SpawnOptions }> = [];
|
||||
|
||||
const killed = killProcessTree(1234, "SIGKILL", {
|
||||
platform: "win32",
|
||||
spawnProcess: (command, args, options) => {
|
||||
spawnCalls.push({ command, args, options });
|
||||
return new EventEmitter() as import("node:child_process").ChildProcess;
|
||||
},
|
||||
killProcess: () => undefined,
|
||||
log: () => undefined,
|
||||
});
|
||||
|
||||
assert.equal(killed, true);
|
||||
assert.equal(spawnCalls[0]?.command, "taskkill");
|
||||
assert.deepEqual(spawnCalls[0]?.args, ["/pid", "1234", "/T", "/F"]);
|
||||
assert.equal(spawnCalls[0]?.options.shell, false);
|
||||
assert.equal(spawnCalls[0]?.options.windowsHide, true);
|
||||
});
|
||||
|
||||
test("killProcessTree falls back from POSIX process group to child pid", () => {
|
||||
const killCalls: Array<{ pid: number; signal: NodeJS.Signals }> = [];
|
||||
|
||||
const killed = killProcessTree(1234, "SIGTERM", {
|
||||
platform: "linux",
|
||||
spawnProcess: () => new EventEmitter() as import("node:child_process").ChildProcess,
|
||||
killProcess: (pid, signal) => {
|
||||
killCalls.push({ pid, signal });
|
||||
if (pid < 0) {
|
||||
throw new Error("process group unavailable");
|
||||
}
|
||||
},
|
||||
log: () => undefined,
|
||||
});
|
||||
|
||||
assert.equal(killed, true);
|
||||
assert.deepEqual(killCalls, [
|
||||
{ pid: -1234, signal: "SIGTERM" },
|
||||
{ pid: 1234, signal: "SIGTERM" },
|
||||
]);
|
||||
});
|
||||
Reference in New Issue
Block a user