Skip to content

Commit 3861f3e

Browse files
authored
Merge pull request #424 from soumyamahunt/win-support
Add Windows support
2 parents 0ce29fe + d8a4759 commit 3861f3e

File tree

10 files changed

+1414
-3726
lines changed

10 files changed

+1414
-3726
lines changed

.github/workflows/ci.yml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,11 @@ jobs:
2222
runs-on: ${{ matrix.os }}
2323
strategy:
2424
matrix:
25-
os: [ubuntu-latest, macos-latest]
25+
os: [ubuntu-latest, macos-latest, windows-latest]
2626
swift: ["5.6.1"]
27+
include:
28+
- os: windows-latest
29+
swift: "5.3"
2730
steps:
2831
- uses: actions/checkout@v3
2932
- run: npm install

__tests__/os.test.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,13 @@ describe("os resolver", () => {
1919
expect(mac.os).toBe(os.OS.MacOS);
2020
expect(mac.version).toBe("latest");
2121
expect(mac.name).toBe("macOS");
22+
23+
setSystem({ os: "win32", dist: "Windows", release: "latest" });
24+
25+
let windows = await os.getSystem();
26+
expect(windows.os).toBe(os.OS.Windows);
27+
expect(windows.version).toBe("latest");
28+
expect(windows.name).toBe("Windows");
2229
});
2330

2431
it("throws an error if the os is not supported", async () => {

__tests__/swift-versions.test.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import * as versions from "../src/swift-versions";
33

44
const macOS: System = { os: OS.MacOS, version: "latest", name: "macOS" };
55
const ubuntu: System = { os: OS.Ubuntu, version: "latest", name: "Ubuntu" };
6+
const windows: System = { os: OS.Windows, version: "latest", name: "Windows" };
67

78
describe("swift version resolver", () => {
89
it("identifies X.X.X versions", async () => {
@@ -39,12 +40,19 @@ describe("swift version resolver", () => {
3940
});
4041

4142
it("throws an error if the version isn't available for the system", async () => {
42-
expect.assertions(1);
43+
expect.assertions(2);
44+
4345
try {
4446
await versions.verify("5.0.3", macOS);
4547
} catch (e) {
4648
expect(e).toEqual(new Error('Version "5.0.3" is not available'));
4749
}
50+
51+
try {
52+
await versions.verify("5.2", windows);
53+
} catch (e) {
54+
expect(e).toEqual(new Error('Version "5.2" is not available'));
55+
}
4856
});
4957

5058
it("throws an error if version is invalid", async () => {

__tests__/visual-studio.test.ts

Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
import os from "os";
2+
import * as vs from "../src/visual-studio";
3+
import { swiftPackage } from "../src/swift-versions";
4+
import { OS, System } from "../src/os";
5+
6+
jest.mock("fs", () => {
7+
const original = jest.requireActual("fs");
8+
return {
9+
...original,
10+
existsSync: jest.fn((path) => true),
11+
};
12+
});
13+
14+
const windows: System = { os: OS.Windows, version: "latest", name: "Windows" };
15+
16+
describe("visual studio resolver", () => {
17+
const env = process.env;
18+
19+
beforeEach(() => {
20+
jest.resetModules();
21+
process.env = { ...env };
22+
});
23+
24+
afterEach(() => {
25+
process.env = env;
26+
});
27+
28+
it("fetches visual studio requirement for swift version", async () => {
29+
jest.spyOn(os, "release").mockReturnValue("10.0.17763");
30+
31+
const req5_3 = vs.vsRequirement(swiftPackage("5.3", windows));
32+
expect(req5_3.version).toBe("16");
33+
expect(req5_3.components).toContain(
34+
"Microsoft.VisualStudio.Component.VC.Tools.x86.x64"
35+
);
36+
expect(req5_3.components).toContain(
37+
"Microsoft.VisualStudio.Component.Windows10SDK.17763"
38+
);
39+
40+
const req5_6 = vs.vsRequirement(swiftPackage("5.6", windows));
41+
expect(req5_6.version).toBe("16");
42+
expect(req5_6.components).toContain(
43+
"Microsoft.VisualStudio.Component.VC.Tools.x86.x64"
44+
);
45+
expect(req5_6.components).toContain(
46+
"Microsoft.VisualStudio.Component.Windows10SDK.17763"
47+
);
48+
});
49+
50+
it("adds latest sdk for release newer than or equal to build 17763", async () => {
51+
jest.spyOn(os, "release").mockReturnValue("10.0.17763");
52+
const req17763 = vs.vsRequirement(swiftPackage("5.3", windows));
53+
expect(req17763.components).toContain(
54+
"Microsoft.VisualStudio.Component.Windows10SDK.17763"
55+
);
56+
57+
jest.spyOn(os, "release").mockReturnValue("10.0.18363");
58+
const req18363 = vs.vsRequirement(swiftPackage("5.3", windows));
59+
expect(req18363.components).toContain(
60+
"Microsoft.VisualStudio.Component.Windows10SDK.18363"
61+
);
62+
});
63+
64+
it("adds recommended sdk for release older than build 17763", async () => {
65+
jest.spyOn(os, "release").mockReturnValue("10.0.16299");
66+
const req16299 = vs.vsRequirement(swiftPackage("5.3", windows));
67+
expect(req16299.components).toContain(
68+
"Microsoft.VisualStudio.Component.Windows10SDK.17763"
69+
);
70+
});
71+
72+
it("finds vswhere path from environment value", async () => {
73+
const vswherePath = "C:\\bin\\";
74+
const vswhereExe = "C:\\bin\\vswhere.exe";
75+
process.env.VSWHERE_PATH = vswherePath;
76+
expect(await vs.getVsWherePath()).toBe(vswhereExe);
77+
});
78+
79+
it("finds vswhere path from ProgramFiles environment value", async () => {
80+
const vswhereExe =
81+
"C:\\Program Files (x86)\\Microsoft Visual Studio\\Installer\\vswhere.exe";
82+
process.env["ProgramFiles(x86)"] = "C:\\Program Files (x86)";
83+
expect(await vs.getVsWherePath()).toBe(vswhereExe);
84+
});
85+
});

0 commit comments

Comments
 (0)