devDesktopRemoteProdScript.test.ts 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. import { readFileSync } from "node:fs";
  2. import { resolve } from "node:path";
  3. import { describe, expect, it } from "vitest";
  4. import {
  5. buildDesktopRemoteProdEnv,
  6. resolvePnpmCommand,
  7. resolveProductionRemoteAssetCacheDir,
  8. } from "../../../scripts/dev-desktop-remote-prod.mjs";
  9. const rootPackageJsonPath = resolve(import.meta.dirname, "../../../package.json");
  10. const rootPackageJson = JSON.parse(readFileSync(rootPackageJsonPath, "utf8")) as {
  11. scripts: Record<string, string | undefined>;
  12. };
  13. describe("dev desktop remote production-like script", () => {
  14. it("根 package.json 应提供生产态 remote 行为的 desktop dev 启动脚本", () => {
  15. expect(rootPackageJson.scripts["dev:desktop:remote-prod"]).toBe(
  16. "node scripts/dev-desktop-remote-prod.mjs",
  17. );
  18. });
  19. it("macOS 默认应复用正式版 ZCode remote cache", () => {
  20. expect(resolveProductionRemoteAssetCacheDir({}, "darwin", "/Users/alice")).toBe(
  21. "/Users/alice/Library/Application Support/ZCode/remote-assets-cache",
  22. );
  23. });
  24. it("Linux 默认应复用正式版 ZCode remote cache", () => {
  25. expect(resolveProductionRemoteAssetCacheDir({}, "linux", "/home/alice")).toBe(
  26. "/home/alice/.config/ZCode/remote-assets-cache",
  27. );
  28. expect(
  29. resolveProductionRemoteAssetCacheDir(
  30. { XDG_CONFIG_HOME: "/home/alice/.config-custom" },
  31. "linux",
  32. "/home/alice",
  33. ),
  34. ).toBe("/home/alice/.config-custom/ZCode/remote-assets-cache");
  35. });
  36. it("Windows 默认应复用正式版 ZCode remote cache", () => {
  37. expect(
  38. resolveProductionRemoteAssetCacheDir(
  39. { APPDATA: "C:\\Users\\Alice\\AppData\\Roaming" },
  40. "win32",
  41. "C:\\Users\\Alice",
  42. ),
  43. ).toBe("C:\\Users\\Alice\\AppData\\Roaming\\ZCode\\remote-assets-cache");
  44. });
  45. it("启动 env 应强制走 CDN,并允许显式 cache 覆盖", () => {
  46. const env = buildDesktopRemoteProdEnv(
  47. {
  48. ZCODE_ENV: "test",
  49. ZCODE_DEV_REMOTE_ASSET_USE_CDN: "0",
  50. ZCODE_REMOTE_ASSET_CACHE_DIR: "/tmp/custom-cache",
  51. },
  52. "darwin",
  53. "/Users/alice",
  54. );
  55. expect(env.ZCODE_ENV).toBe("production");
  56. expect(env.ZCODE_DEV_REMOTE_ASSET_USE_CDN).toBe("1");
  57. expect(env.ZCODE_REMOTE_ASSET_CACHE_DIR).toBe("/tmp/custom-cache");
  58. });
  59. it("Windows 下应使用 pnpm.cmd 启动", () => {
  60. expect(resolvePnpmCommand("win32")).toBe("pnpm.cmd");
  61. expect(resolvePnpmCommand("darwin")).toBe("pnpm");
  62. });
  63. });