import { describe, expect, it } from "vitest"; import type { RunConfig } from "@/platform/ipc"; import { useMenuSlotItems } from "@/workbench/contributions"; import { useRun } from "./store"; import { cleanConfig, registerXcodeCleanActions, xcodeConfigFor } from "./xcodeClean"; const config = (id: string, kind: string, container: string, scheme = id): RunConfig => ({ id, name: scheme, kind, command: "xcodebuild", args: ["-project", container, "-scheme", scheme], cwd: null, env: { A: "1" }, params: { container, scheme, configuration: "Debug" }, detected: true, isTest: false, debugAdapter: null, }); describe("xcode clean", () => { const configs = [ config("node", "node", ""), config("a", "xcode", "App.xcodeproj"), config("b", "xcode", "App.xcodeproj"), config("w", "xcode", "Other.xcworkspace"), ]; it("acts on the selected Xcode configuration, else the first", () => { expect(xcodeConfigFor(configs, "b")?.id).toBe("b"); expect(xcodeConfigFor(configs, "node")?.id).toBe("a"); expect(xcodeConfigFor([configs[0]!], "node")).toBeNull(); }); it("acts on a scheme of the right-clicked container", () => { expect(xcodeConfigFor(configs, "b", "/p/Other.xcworkspace")?.id).toBe("w"); expect(xcodeConfigFor(configs, "w", "/p/App.xcodeproj/")?.id).toBe("a"); expect(xcodeConfigFor(configs, "a", "/p/Missing.xcodeproj")).toBeNull(); }); it("cleans with the configuration's params on the chosen simulator", () => { const clean = cleanConfig(configs[1]!, "UDID"); expect(clean).toMatchObject({ id: "xcode:clean:App.xcodeproj:a", kind: "xcode-clean", args: [], env: {}, params: { container: "App.xcodeproj", scheme: "a", configuration: "Debug", simulator: "UDID" }, }); }); it("lists Build › Xcode only while the project has an Xcode configuration", () => { const listed = () => (useMenuSlotItems.getState().slots.xcodeBuild ?? []).map((i) => i.label); useRun.setState({ configs: [configs[0]!] }); const dispose = registerXcodeCleanActions(); expect(listed()).toEqual([]); useRun.setState({ configs }); expect(listed()).toEqual(["Clean Build Folder", "Delete DerivedData"]); useRun.setState({ configs: [configs[0]!] }); expect(listed()).toEqual([]); useRun.setState({ configs }); dispose(); expect(listed()).toEqual([]); }); });