devWatchBlacklist.test.ts 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. import { readFileSync } from "node:fs";
  2. import { resolve } from "node:path";
  3. import { describe, expect, it } from "vitest";
  4. const desktopPackageJsonPath = resolve(import.meta.dirname, "../package.json");
  5. const desktopPackageJson = JSON.parse(readFileSync(desktopPackageJsonPath, "utf8")) as {
  6. scripts: Record<string, string | undefined>;
  7. };
  8. const generatedWatchBlacklist = [
  9. "mock-cdn/**",
  10. "bundled-agents/**",
  11. ".e2e-cache/**",
  12. ".e2e-artifacts/**",
  13. ".e2e-home-*/**",
  14. "dist-cua-helper/**",
  15. ];
  16. const workspaceWatchRoots = [
  17. "src",
  18. "../services/src",
  19. "../server/src",
  20. "../shared/src",
  21. "../rpc/src",
  22. "../client/src",
  23. "../provider/src",
  24. "../provider-node/src",
  25. ];
  26. describe("desktop dev tsup watcher", () => {
  27. it("标准和 local-cli 开发入口都排除生成目录", () => {
  28. for (const scriptName of ["dev:runtime", "dev:local-cli"]) {
  29. const script = desktopPackageJson.scripts[scriptName];
  30. expect(script).toBeDefined();
  31. expect(script).toContain("tsup --watch src");
  32. for (const path of workspaceWatchRoots.slice(1)) {
  33. expect(script).toContain(`--watch ${path}`);
  34. }
  35. for (const path of generatedWatchBlacklist) {
  36. expect(script).toContain(`--ignore-watch '${path}'`);
  37. }
  38. }
  39. });
  40. it("黑名单 glob 必须保留在 shell 引号内", () => {
  41. for (const scriptName of ["dev:runtime", "dev:local-cli"]) {
  42. const script = desktopPackageJson.scripts[scriptName] ?? "";
  43. expect(script).not.toMatch(
  44. /--ignore-watch (?:mock-cdn|bundled-agents|\.e2e|dist-cua-helper)\/\*/u,
  45. );
  46. }
  47. });
  48. });