/** * @file Tests for server/lib/windows-hide.js: on win32 every child process, * async or sync, is started with `windowsHide: true`; elsewhere nothing changes. * @author Nguyễn Ngọc Trí Vĩ */ const { test } = require("node:test"); const assert = require("node:assert/strict"); const { install } = require("../lib/windows-hide"); function fakeCp() { const seen = []; class ChildProcess { spawn(options) { seen.push(options); } } const rec = (...args) => seen.push(args); return { seen, cp: { ChildProcess, spawnSync: rec, execFileSync: rec, execSync: rec } }; } test("win32: async spawns and every sync form get windowsHide", () => { const { seen, cp } = fakeCp(); install(cp, "win32"); install(cp, "win32"); // idempotent: no double wrap new cp.ChildProcess().spawn({ file: "git", windowsHide: false }); cp.execFileSync("git", ["status"]); cp.execFileSync("git", ["status"], { cwd: "x" }); cp.execFileSync("git", { cwd: "x" }); cp.execSync("dir"); cp.spawnSync("git", ["log"], undefined); assert.deepEqual(seen, [ { file: "git", windowsHide: true }, ["git", ["status"], { windowsHide: true }], ["git", ["status"], { cwd: "x", windowsHide: true }], ["git", { cwd: "x", windowsHide: true }], ["dir", { windowsHide: true }], ["git", ["log"], { windowsHide: true }], ]); }); test("other platforms are left alone", () => { const { cp } = fakeCp(); const before = { ...cp, spawn: cp.ChildProcess.prototype.spawn }; install(cp, "linux"); assert.equal(cp.execSync, before.execSync); assert.equal(cp.ChildProcess.prototype.spawn, before.spawn); });