e2eAppOutputStage.test.ts 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. import { mkdir, mkdtemp, readFile, rm, writeFile } from "node:fs/promises";
  2. import { resolve } from "node:path";
  3. import { afterEach, describe, expect, it } 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("共享构建被类型检查原地覆盖后,递归快照保持原产物", async () => {
  20. const { destination, source } = await createTestDirs();
  21. await mkdir(resolve(source, "host"), { recursive: true });
  22. const sourceEntry = resolve(source, "host", "index.js");
  23. await writeFile(sourceEntry, "bundled-host");
  24. await stageE2EAppOutput(source, destination);
  25. await writeFile(sourceEntry, "unbundled-tsc-output");
  26. expect(await readFile(resolve(destination, "host", "index.js"), "utf8")).toBe("bundled-host");
  27. });
  28. it("用例修改隔离副本时,不污染共享构建或其他 shard", async () => {
  29. const { destination, root, source } = await createTestDirs();
  30. await mkdir(source, { recursive: true });
  31. await writeFile(resolve(source, "main.js"), "original");
  32. const another = resolve(root, "another-shard");
  33. await stageE2EAppOutput(source, destination);
  34. await stageE2EAppOutput(source, another);
  35. await writeFile(resolve(destination, "main.js"), "case-specific");
  36. expect(await readFile(resolve(source, "main.js"), "utf8")).toBe("original");
  37. expect(await readFile(resolve(another, "main.js"), "utf8")).toBe("original");
  38. });
  39. });