дзеркало
https://github.com/l0ng-ai/openidea.git
синхронізовано 2026-12-04 01:01:17 +02:00
xcodebuild compiles only the files a target lists, so a source file created or renamed in the IDE inside a classic .xcodeproj group was silently left out of the build. After file operations in the IDE (one check per burst), an XcodeGen or Tuist project gets an offer to regenerate it, and a classic project without synchronized folders gets a warning naming the files project.pbxproj doesn't list, with Open in Xcode. Regenerate Xcode Project is also in Find Action and in the context menus of project.yml / Project.swift. Names are matched as whole file names, and file operations without source files skip the check. Closes #6887 Co-authored-by: wildcatDownstairs <[email protected]> Co-authored-by: wildcatDownstairs <[email protected]>
94 рядки
3.5 KiB
TypeScript
94 рядки
3.5 KiB
TypeScript
import { afterEach, beforeEach, expect, it, vi } from "vitest";
|
|
|
|
const ipc = vi.hoisted(() => ({ xcodeFileSync: vi.fn(), runApplySettings: vi.fn() }));
|
|
const run = vi.hoisted(() => ({ startRun: vi.fn() }));
|
|
vi.mock("@/platform/ipc", async (importOriginal) => ({
|
|
...(await importOriginal<typeof import("@/platform/ipc")>()),
|
|
isTauri: () => true,
|
|
commands: ipc,
|
|
}));
|
|
vi.mock("@/platform/keymap", async (importOriginal) => ({
|
|
...(await importOriginal<typeof import("@/platform/keymap")>()),
|
|
isMacHost: () => true,
|
|
}));
|
|
vi.mock("./store", () => run);
|
|
|
|
import { notifyFileOperation, notifyFilesMoved } from "@/platform/fileOps";
|
|
import type { RunConfig } from "@/platform/ipc";
|
|
import { useProject } from "@/platform/project";
|
|
import { provideNotificationService } from "@/workbench/contributions";
|
|
import { registerXcodeFiles } from "./xcodeFiles";
|
|
|
|
const ok = <T>(data: T) => Promise.resolve({ status: "ok" as const, data });
|
|
const notify = vi.fn();
|
|
provideNotificationService({ notify, expire: vi.fn() });
|
|
const act = (label: string) =>
|
|
notify.mock.calls
|
|
.at(-1)![0]
|
|
.actions.find((a: { label: string }) => a.label === label)
|
|
.run();
|
|
|
|
let dispose: () => void;
|
|
beforeEach(() => {
|
|
vi.useFakeTimers();
|
|
useProject.setState({ project: { root: "/p", trusted: true } as never });
|
|
ipc.runApplySettings.mockImplementation((configs: RunConfig[]) => ok(configs));
|
|
run.startRun.mockResolvedValue(null);
|
|
dispose = registerXcodeFiles();
|
|
});
|
|
afterEach(() => {
|
|
dispose();
|
|
vi.useRealTimers();
|
|
vi.clearAllMocks();
|
|
useProject.setState({ project: null });
|
|
});
|
|
|
|
it("checks a burst of file operations once and names the files a classic project misses", async () => {
|
|
ipc.xcodeFileSync.mockReturnValue(ok({ kind: "notInProject", project: "/p/App.xcodeproj", files: ["New.swift"] }));
|
|
notifyFileOperation({ kind: "created", paths: ["/p/App/New.swift"] });
|
|
notifyFileOperation({ kind: "deleted", paths: ["/p/App/Old.swift"] });
|
|
await notifyFilesMoved([{ from: "/p/App/A.swift", to: "/p/App/B.swift" }]);
|
|
await vi.advanceTimersByTimeAsync(1000);
|
|
|
|
expect(ipc.xcodeFileSync).toHaveBeenCalledTimes(1);
|
|
expect(ipc.xcodeFileSync).toHaveBeenCalledWith(
|
|
["/p/App/New.swift", "/p/App/B.swift"],
|
|
["/p/App/Old.swift", "/p/App/A.swift"],
|
|
);
|
|
expect(notify).toHaveBeenCalledTimes(1);
|
|
expect(notify.mock.calls[0]![0].title).toBe("New.swift isn't in the Xcode project");
|
|
|
|
act("Open in Xcode");
|
|
await vi.waitFor(() => expect(run.startRun).toHaveBeenCalled());
|
|
expect(run.startRun.mock.calls[0]![0]).toMatchObject({
|
|
command: "open",
|
|
args: ["-a", "Xcode", "App.xcodeproj"],
|
|
cwd: "/p",
|
|
});
|
|
});
|
|
|
|
it("offers to regenerate a generated project", async () => {
|
|
ipc.xcodeFileSync.mockReturnValue(ok({ kind: "generated", dir: "/p", tool: "tuist" }));
|
|
notifyFileOperation({ kind: "created", paths: ["/p/Sources/New.swift"] });
|
|
await vi.advanceTimersByTimeAsync(1000);
|
|
|
|
expect(notify.mock.calls[0]![0].body).toBe(
|
|
"Files changed in a project generated by tuist. Run 'tuist generate --no-open' so Xcode builds them.",
|
|
);
|
|
act("Regenerate");
|
|
await vi.waitFor(() => expect(run.startRun).toHaveBeenCalled());
|
|
expect(run.startRun.mock.calls[0]![0]).toMatchObject({
|
|
command: "tuist",
|
|
args: ["generate", "--no-open"],
|
|
cwd: "/p",
|
|
});
|
|
});
|
|
|
|
it("stays quiet when the project picks the files up itself", async () => {
|
|
ipc.xcodeFileSync.mockReturnValue(ok(null));
|
|
notifyFileOperation({ kind: "created", paths: ["/p/App/New.swift"] });
|
|
await vi.advanceTimersByTimeAsync(1000);
|
|
expect(ipc.xcodeFileSync).toHaveBeenCalled();
|
|
expect(notify).not.toHaveBeenCalled();
|
|
});
|