macosUpdateManifest.test.ts 2.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. import { mkdtemp, readFile, writeFile, rm } from "node:fs/promises";
  2. import { tmpdir } from "node:os";
  3. import { join } from "node:path";
  4. import { afterEach, expect, it } from "vitest";
  5. import { parse } from "yaml";
  6. import { stampMacosUpdateManifests } from "../scripts/macos-update-manifest.mjs";
  7. const roots: string[] = [];
  8. const macosManifestNames = ["latest", "preview"].flatMap((channel) =>
  9. ["", "-arm64", "-x64"].flatMap((arch) =>
  10. ["yml", "yaml"].map((extension) => `${channel}-mac${arch}.${extension}`),
  11. ),
  12. );
  13. afterEach(async () => {
  14. await Promise.all(roots.splice(0).map((root) => rm(root, { recursive: true, force: true })));
  15. });
  16. async function fixture(name = "latest-mac.yml") {
  17. const outputDir = await mkdtemp(join(tmpdir(), "zcode-update-manifest-"));
  18. roots.push(outputDir);
  19. const file = join(outputDir, name);
  20. const manifest =
  21. "version: 3.15.1\nfiles:\n - url: ZCode.zip\n sha512: checksum\nreleaseNotes: release notes\n";
  22. await writeFile(file, manifest);
  23. return { outputDir, file, manifest };
  24. }
  25. it.each(macosManifestNames)("%s 保留下载与日志字段,并写入 Darwin 22 下限", async (name) => {
  26. const { outputDir, file, manifest } = await fixture(name);
  27. await stampMacosUpdateManifests({ outputDir, platform: "mac" });
  28. expect(parse(await readFile(file, "utf8"))).toEqual({
  29. ...parse(manifest),
  30. minimumSystemVersion: "22.0.0",
  31. });
  32. });
  33. it.each(["win", "linux"])("%s 不改变更新清单", async (platform) => {
  34. const { outputDir, file, manifest } = await fixture();
  35. await stampMacosUpdateManifests({ outputDir, platform });
  36. expect(await readFile(file, "utf8")).toBe(manifest);
  37. });
  38. it.each(macosManifestNames)("%s 保留更严格的系统下限,不处理非更新 YAML", async (name) => {
  39. const { outputDir, file } = await fixture(name);
  40. await writeFile(file, "version: 3.15.1\nminimumSystemVersion: 23.0.0\n");
  41. const debug = join(outputDir, "builder-debug.yml");
  42. await writeFile(debug, "debug: true\n");
  43. await stampMacosUpdateManifests({ outputDir, platform: "mac" });
  44. expect(parse(await readFile(file, "utf8")).minimumSystemVersion).toBe("23.0.0");
  45. expect(await readFile(debug, "utf8")).toBe("debug: true\n");
  46. });
  47. it("macOS 构建不修改同一输出目录里的 Windows/Linux 清单,并覆盖预览渠道", async () => {
  48. const { outputDir, manifest } = await fixture();
  49. const windows = join(outputDir, "latest.yml");
  50. const linux = join(outputDir, "latest-linux.yml");
  51. const preview = join(outputDir, "preview-mac.yml");
  52. await Promise.all([windows, linux, preview].map((file) => writeFile(file, manifest)));
  53. await stampMacosUpdateManifests({ outputDir, platform: "mac" });
  54. expect(await readFile(windows, "utf8")).toBe(manifest);
  55. expect(await readFile(linux, "utf8")).toBe(manifest);
  56. expect(parse(await readFile(preview, "utf8")).minimumSystemVersion).toBe("22.0.0");
  57. });