Add test for cygwin flow

This commit is contained in:
Sander Declerck 2025-09-10 14:10:25 +02:00
parent 0a6fd4cbb7
commit 6826728481
No known key found for this signature in database

View file

@ -8,6 +8,8 @@ import { knownAikidoTools } from "../helpers.js";
describe("Bash shell integration", () => { describe("Bash shell integration", () => {
let mockStartupFile; let mockStartupFile;
let bash; let bash;
let windowsCygwinPath = "";
let platform = "linux";
beforeEach(async () => { beforeEach(async () => {
// Create temporary startup file for testing // Create temporary startup file for testing
@ -37,6 +39,35 @@ describe("Bash shell integration", () => {
mock.module("child_process", { mock.module("child_process", {
namedExports: { namedExports: {
execSync: () => mockStartupFile, execSync: () => mockStartupFile,
spawnSync: (command, args) => {
if (platform !== "win32") {
return { status: 0 };
}
if (command === "where" && args[0] === "cygpath") {
return {
status: 0,
stdout: Buffer.from("C:\\cygwin64\\bin\\cygpath.exe\n"),
};
}
if (
command === "cygpath" &&
args[0] === "-w" &&
args[1] === mockStartupFile
) {
return {
status: 0,
stdout: windowsCygwinPath + "\n",
};
}
},
},
});
mock.module("os", {
namedExports: {
platform: () => platform,
}, },
}); });
@ -52,6 +83,7 @@ describe("Bash shell integration", () => {
// Reset mocks // Reset mocks
mock.reset(); mock.reset();
platform = "linux";
}); });
describe("isInstalled", () => { describe("isInstalled", () => {
@ -77,6 +109,23 @@ describe("Bash shell integration", () => {
) )
); );
}); });
it("should use the correct startup file for cygwin bash on Windows", () => {
platform = "win32";
// set windows path to the correct filename
windowsCygwinPath = mockStartupFile;
mockStartupFile = "DUMMY"; // This will be overridden by the mocked execSync
const result = bash.setup();
assert.strictEqual(result, true);
const content = fs.readFileSync(windowsCygwinPath, "utf-8");
assert.ok(
content.includes(
"source ~/.safe-chain/scripts/init-posix.sh # Safe-chain bash initialization script"
)
);
});
}); });
describe("teardown", () => { describe("teardown", () => {