Fix unit tests

This commit is contained in:
Sander Declerck 2025-10-23 10:52:03 +02:00
parent 8447d3cac5
commit c74c23b0ff
No known key found for this signature in database
2 changed files with 8 additions and 1 deletions

View file

@ -1,4 +1,5 @@
import { spawn, execSync } from "child_process"; import { spawn, execSync } from "child_process";
import os from "os";
function escapeArg(arg) { function escapeArg(arg) {
// Shell metacharacters that need escaping // Shell metacharacters that need escaping
@ -42,7 +43,7 @@ export async function safeSpawn(command, args, options = {}) {
// array args (safer, no escaping needed). // array args (safer, no escaping needed).
// See: https://nodejs.org/api/child_process.html#child_processspawncommand-args-options // See: https://nodejs.org/api/child_process.html#child_processspawncommand-args-options
let child; let child;
if (process.platform === "win32") { if (os.platform() === "win32") {
const fullCommand = buildCommand(command, args); const fullCommand = buildCommand(command, args);
child = spawn(fullCommand, { ...options, shell: true }); child = spawn(fullCommand, { ...options, shell: true });
} else { } else {

View file

@ -33,6 +33,12 @@ describe("safeSpawn", () => {
}, },
}); });
mock.module("os", {
namedExports: {
platform: () => "win32",
},
});
// Import after mocking // Import after mocking
const safeSpawnModule = await import("./safeSpawn.js"); const safeSpawnModule = await import("./safeSpawn.js");
safeSpawn = safeSpawnModule.safeSpawn; safeSpawn = safeSpawnModule.safeSpawn;