e2eAppOutputStage.test.ts 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. import { mkdir, mkdtemp, readFile, rm, stat, writeFile } from "node:fs/promises";
  2. import { resolve } from "node:path";
  3. import { afterEach, describe, expect, it, vi } from "vitest";
  4. import { stageE2EAppOutput } from "./e2e/helpers/e2e-app-output-stage.js";
  5. const testDirs: string[] = [];
  6. afterEach(async () => {
  7. await Promise.all(testDirs.splice(0).map((dir) => rm(dir, { force: true, recursive: true })));
  8. });
  9. async function createTestDirs() {
  10. const root = await mkdtemp(resolve("packages/desktop", ".e2e-stage-test-"));
  11. testDirs.push(root);
  12. return {
  13. destination: resolve(root, "destination"),
  14. root,
  15. source: resolve(root, "source"),
  16. };
  17. }
  18. describe("desktop E2E app output staging", () => {
  19. it("creates a recursive hard-link snapshot", async () => {
  20. const { destination, source } = await createTestDirs();
  21. await mkdir(resolve(source, "renderer"), { recursive: true });
  22. await writeFile(resolve(source, "renderer", "main.js"), "main");
  23. await stageE2EAppOutput(source, destination);
  24. expect(await readFile(resolve(destination, "renderer", "main.js"), "utf8")).toBe("main");
  25. const [sourceStat, destinationStat] = await Promise.all([
  26. stat(resolve(source, "renderer", "main.js")),
  27. stat(resolve(destination, "renderer", "main.js")),
  28. ]);
  29. expect(destinationStat.ino).toBe(sourceStat.ino);
  30. });
  31. it("falls back to copying when the filesystem rejects links", async () => {
  32. const { destination, source } = await createTestDirs();
  33. await mkdir(source, { recursive: true });
  34. await writeFile(resolve(source, "main.js"), "main");
  35. const linkFile = vi.fn(async () => {
  36. throw Object.assign(new Error("cross-device link"), { code: "EXDEV" });
  37. });
  38. await stageE2EAppOutput(source, destination, { linkFile });
  39. expect(linkFile).toHaveBeenCalledOnce();
  40. expect(await readFile(resolve(destination, "main.js"), "utf8")).toBe("main");
  41. });
  42. });