diff --git a/packages/safe-chain/src/shell-integration/supported-shells/bash.spec.js b/packages/safe-chain/src/shell-integration/supported-shells/bash.spec.js index e23addb..ebe0676 100644 --- a/packages/safe-chain/src/shell-integration/supported-shells/bash.spec.js +++ b/packages/safe-chain/src/shell-integration/supported-shells/bash.spec.js @@ -8,6 +8,8 @@ import { knownAikidoTools } from "../helpers.js"; describe("Bash shell integration", () => { let mockStartupFile; let bash; + let windowsCygwinPath = ""; + let platform = "linux"; beforeEach(async () => { // Create temporary startup file for testing @@ -37,6 +39,35 @@ describe("Bash shell integration", () => { mock.module("child_process", { namedExports: { 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 mock.reset(); + platform = "linux"; }); 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", () => {