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