Skip to content

Commit c5df068

Browse files
committed
Detect if swiftly is already installed
1 parent d58b133 commit c5df068

File tree

1 file changed

+42
-0
lines changed

1 file changed

+42
-0
lines changed

test/unit-tests/toolchain/swiftly.test.ts

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,4 +103,46 @@ suite("Swiftly Unit Tests", () => {
103103
expect(mockUtilities.execFile).not.have.been.called;
104104
});
105105
});
106+
107+
suite("isInstalled", () => {
108+
test("should return false when platform is not supported", async () => {
109+
mockedPlatform.setValue("win32");
110+
111+
const result = await Swiftly.isInstalled();
112+
113+
expect(result).to.be.false;
114+
expect(mockUtilities.execFile).not.have.been.called;
115+
});
116+
117+
test("should return true when swiftly is installed", async () => {
118+
mockedPlatform.setValue("darwin");
119+
120+
mockUtilities.execFile.withArgs("swiftly", ["--version"]).resolves({
121+
stdout: "1.1.0\n",
122+
stderr: "",
123+
});
124+
125+
const result = await Swiftly.isInstalled();
126+
127+
expect(result).to.be.true;
128+
expect(mockUtilities.execFile).to.have.been.calledWith("swiftly", ["--version"]);
129+
});
130+
131+
test("should throw error when swiftly command fails with non-ENOENT error", async () => {
132+
mockedPlatform.setValue("darwin");
133+
134+
const otherError = new Error("Other error");
135+
136+
mockUtilities.execFile.withArgs("swiftly", ["--version"]).rejects(otherError);
137+
138+
try {
139+
await Swiftly.isInstalled();
140+
expect.fail("Should have thrown an error");
141+
} catch (error) {
142+
expect(error).to.equal(otherError);
143+
}
144+
145+
expect(mockUtilities.execFile).to.have.been.calledWith("swiftly", ["--version"]);
146+
});
147+
});
106148
});

0 commit comments

Comments
 (0)