windows-file-reveal.test.ts 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637
  1. import { mkdtemp, rm, writeFile } from "node:fs/promises";
  2. import { tmpdir } from "node:os";
  3. import { join } from "node:path";
  4. import { waitForDefaultWorkspaceReady } from "#e2e/helpers/desktop-app";
  5. describe("Windows 本地文件定位 IPC", () => {
  6. it("同一请求只通过 shell 定位一次中文及空格文件", async function () {
  7. if (process.platform !== "win32") this.skip();
  8. await waitForDefaultWorkspaceReady(30000);
  9. const directory = await mkdtemp(join(tmpdir(), "zcode-reveal-"));
  10. const filePath = join(directory, "生成 文件.html");
  11. try {
  12. await writeFile(filePath, "<html></html>");
  13. const reveal = await browser.electron.mock("shell", "showItemInFolder");
  14. await reveal.mockReturnValue(undefined);
  15. const open = await browser.electron.mock("shell", "openPath");
  16. await open.mockResolvedValue("");
  17. const result = await browser.execute(async (path) => {
  18. const bridge = (
  19. window as unknown as {
  20. zcode: {
  21. openInEditor(editorId: string, path: string): Promise<{ success: boolean }>;
  22. };
  23. }
  24. ).zcode;
  25. return bridge.openInEditor("explorer", path);
  26. }, filePath);
  27. expect(result).toEqual({ success: true });
  28. await expect(reveal).toHaveBeenCalledTimes(1);
  29. await expect(reveal).toHaveBeenCalledWith(filePath);
  30. await expect(open).not.toHaveBeenCalled();
  31. } finally {
  32. await browser.electron.restoreAllMocks();
  33. await rm(directory, { recursive: true, force: true });
  34. }
  35. });
  36. });