Skip to content

Commit 710da2f

Browse files
committed
refactoring changes
1 parent bb13c81 commit 710da2f

File tree

3 files changed

+32
-21
lines changed

3 files changed

+32
-21
lines changed

src/toolchain/swiftly.ts

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,9 @@ export class Swiftly {
8585
const response = ListAvailableResult.parse(JSON.parse(stdout));
8686
return response.toolchains.map(t => t.name);
8787
} catch (error) {
88-
throw new Error(`Failed to retrieve Swiftly installations from disk: ${(error as Error).message}`);
88+
throw new Error(
89+
`Failed to retrieve Swiftly installations from disk: ${(error as Error).message}`
90+
);
8991
}
9092
}
9193

@@ -107,7 +109,9 @@ export class Swiftly {
107109
.filter((toolchain): toolchain is string => typeof toolchain === "string")
108110
.map(toolchain => path.join(swiftlyHomeDir, "toolchains", toolchain));
109111
} catch (error) {
110-
throw new Error(`Failed to retrieve Swiftly installations from disk: ${(error as Error).message}`);
112+
throw new Error(
113+
`Failed to retrieve Swiftly installations from disk: ${(error as Error).message}`
114+
);
111115
}
112116
}
113117

@@ -143,7 +147,9 @@ export class Swiftly {
143147
} catch (err: unknown) {
144148
const error = err as ExecFileError;
145149
// Its possible the toolchain in .swift-version is misconfigured or doesn't exist.
146-
void vscode.window.showErrorMessage(`Failed to load toolchain from Swiftly: ${error.stderr}`);
150+
void vscode.window.showErrorMessage(
151+
`Failed to load toolchain from Swiftly: ${error.stderr}`
152+
);
147153
}
148154
}
149155
}

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

Lines changed: 22 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ suite("Swiftly Unit Tests", () => {
2525
// Mock version check to return 1.1.0
2626
mockUtilities.execFile.withArgs("swiftly", ["--version"]).resolves({
2727
stdout: "1.1.0\n",
28-
stderr: ""
28+
stderr: "",
2929
});
3030

3131
// Mock list-available command with JSON output
@@ -40,8 +40,8 @@ suite("Swiftly Unit Tests", () => {
4040
major: 5,
4141
minor: 9,
4242
patch: 0,
43-
type: "stable"
44-
}
43+
type: "stable",
44+
},
4545
},
4646
{
4747
inUse: false,
@@ -52,8 +52,8 @@ suite("Swiftly Unit Tests", () => {
5252
major: 5,
5353
minor: 8,
5454
patch: 0,
55-
type: "stable"
56-
}
55+
type: "stable",
56+
},
5757
},
5858
{
5959
inUse: false,
@@ -65,34 +65,39 @@ suite("Swiftly Unit Tests", () => {
6565
minor: 10,
6666
branch: "development",
6767
date: "2023-10-15",
68-
type: "snapshot"
69-
}
70-
}
71-
]
68+
type: "snapshot",
69+
},
70+
},
71+
],
7272
};
7373

74-
mockUtilities.execFile.withArgs("swiftly", ["list-available", "--format=json"]).resolves({
75-
stdout: JSON.stringify(jsonOutput),
76-
stderr: ""
77-
});
74+
mockUtilities.execFile
75+
.withArgs("swiftly", ["list-available", "--format=json"])
76+
.resolves({
77+
stdout: JSON.stringify(jsonOutput),
78+
stderr: "",
79+
});
7880

7981
const result = await Swiftly.listAvailableToolchains();
8082

8183
expect(result).to.deep.equal([
8284
"swift-5.9.0-RELEASE",
8385
"swift-5.8.0-RELEASE",
84-
"swift-DEVELOPMENT-SNAPSHOT-2023-10-15-a"
86+
"swift-DEVELOPMENT-SNAPSHOT-2023-10-15-a",
8587
]);
8688

8789
expect(mockUtilities.execFile).to.have.been.calledWith("swiftly", ["--version"]);
88-
expect(mockUtilities.execFile).to.have.been.calledWith("swiftly", ["list-available", "--format=json"]);
90+
expect(mockUtilities.execFile).to.have.been.calledWith("swiftly", [
91+
"list-available",
92+
"--format=json",
93+
]);
8994
});
9095

9196
test("should return empty array when platform is not supported", async () => {
9297
const originalPlatform = process.platform;
9398
Object.defineProperty(process, "platform", {
9499
value: "win32",
95-
writable: true
100+
writable: true,
96101
});
97102

98103
const result = await Swiftly.listAvailableToolchains();
@@ -102,7 +107,7 @@ suite("Swiftly Unit Tests", () => {
102107

103108
Object.defineProperty(process, "platform", {
104109
value: originalPlatform,
105-
writable: true
110+
writable: true,
106111
});
107112
});
108113
});

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ suite("SwiftToolchain Unit Test Suite", () => {
2929
mockFS({});
3030
mockedUtilities.execFile.withArgs("swiftly", ["--version"]).resolves({
3131
stdout: "1.0.0\n",
32-
stderr: ""
32+
stderr: "",
3333
});
3434
});
3535

0 commit comments

Comments
 (0)