import { beforeEach, expect, test, vi } from "vitest"; import type { RunConfig } from "@/platform/ipc"; const { startRun, executeAction } = vi.hoisted(() => ({ startRun: vi.fn(), executeAction: vi.fn() })); vi.mock("./store", () => ({ startRun })); vi.mock("@/platform/actions", () => ({ executeAction })); import { debugXcodeApp, launchedPid } from "./xcodeDebug"; const config = { id: "xcode:run:App.xcodeproj:App", name: "App", kind: "xcode", params: { container: "App.xcodeproj", scheme: "App" }, } as unknown as RunConfig; beforeEach(() => { startRun.mockReset(); executeAction.mockReset(); }); test("simctl's launch line gives the pid", () => { expect(launchedPid("dev.example.App: 4321")).toBe(4321); expect(launchedPid("dev.example.App: 4321\r\n")).toBe(4321); expect(launchedPid("note: 12")).toBeNull(); expect(launchedPid("** BUILD SUCCEEDED **")).toBeNull(); }); test("Debug launches the app suspended and attaches lldb-dap to its pid once", async () => { startRun.mockImplementation(async (_c, _r, _b, options) => { // The launch line can arrive before startRun returns the run's id. options.onLine("Build succeeded"); options.onLine("dev.example.App: 4321"); options.onLine("dev.example.App: 9999"); return { runId: 7 }; }); await debugXcodeApp(config, false); const [, , , options] = startRun.mock.calls[0]!; expect(options.launch.params).toEqual({ container: "App.xcodeproj", scheme: "App", waitForDebugger: "1" }); expect(executeAction).toHaveBeenCalledTimes(1); expect(executeAction).toHaveBeenCalledWith("debug.attach", { attachable: { pid: 4321, name: "App", commandLine: "", kind: "native", adapter: "lldb-dap", host: null, port: null, }, process: 7, runConfig: config, show: false, extra: { sourceMap: [ ["/tmp", "/private/tmp"], ["/var", "/private/var"], ["/etc", "/private/etc"], ], }, }); });