| 1 | import { afterEach, beforeEach, describe, expect, it, vi } from "vitest"; |
| 2 | |
| 3 | vi.mock("node:os", () => ({ |
| 4 | platform: vi.fn(), |
| 5 | arch: vi.fn(), |
| 6 | })); |
| 7 | |
| 8 | vi.mock("vscode", () => ({ |
| 9 | extensions: { |
| 10 | getExtension: vi.fn(), |
| 11 | }, |
| 12 | })); |
| 13 | |
| 14 | describe("isUnsupportedPlatform", () => { |
| 15 | beforeEach(() => { |
| 16 | vi.resetModules(); |
| 17 | }); |
| 18 | |
| 19 | afterEach(() => { |
| 20 | vi.resetAllMocks(); |
| 21 | }); |
| 22 | |
| 23 | it("should be true when os is winarm64", async () => { |
| 24 | const { platform, arch } = await import("node:os"); |
| 25 | vi.mocked(platform).mockReturnValue("win32"); |
| 26 | vi.mocked(arch).mockReturnValue("arm64"); |
| 27 | |
| 28 | const { isUnsupportedPlatform } = await import("./util"); |
| 29 | |
| 30 | const platformCheck = isUnsupportedPlatform(); |
| 31 | |
| 32 | expect(platformCheck.isUnsupported).toBe(true); |
| 33 | expect(platformCheck.reason).toMatch(/windows/gi); |
| 34 | expect(platformCheck.reason).toMatch(/arm64/gi); |
| 35 | }); |
| 36 | |
| 37 | it("should not be true when os is supported", async () => { |
| 38 | const { platform, arch } = await import("node:os"); |
| 39 | vi.mocked(platform).mockReturnValue("linux"); |
| 40 | vi.mocked(arch).mockReturnValue("arm64"); |
| 41 | |
| 42 | const { isUnsupportedPlatform } = await import("./util"); |
| 43 | |
| 44 | const platformCheck = isUnsupportedPlatform(); |
| 45 | |
| 46 | expect(platformCheck.isUnsupported).toBe(false); |
| 47 | }); |
| 48 | }); |
| 49 | |
| 50 | describe("isExtensionPrerelease", () => { |
| 51 | beforeEach(() => { |
| 52 | vi.resetModules(); |
| 53 | }); |
| 54 | |
| 55 | afterEach(() => { |
| 56 | vi.resetAllMocks(); |
| 57 | }); |
| 58 | |
| 59 | it("detects prerelease versions correctly", async () => { |
| 60 | const vscode = await import("vscode"); |
| 61 | const getExtensionMock = vi.mocked(vscode.extensions.getExtension); |
| 62 | |
| 63 | // 1.0.0 is not prerelease (even minor version) |
| 64 | getExtensionMock.mockReturnValue({ |
| 65 | packageJSON: { version: "1.0.0" }, |
| 66 | } as any); |
| 67 | |
| 68 | const { isExtensionPrerelease } = await import("./util"); |
| 69 | |
| 70 | expect(isExtensionPrerelease()).toBe(false); |
| 71 | |
| 72 | // 1.1.0 is prerelease (odd minor version) |
| 73 | getExtensionMock.mockReturnValue({ |
| 74 | packageJSON: { version: "1.1.0" }, |
| 75 | } as any); |
| 76 | |
| 77 | expect(isExtensionPrerelease()).toBe(true); |
| 78 | }); |
| 79 | }); |