bundle-boundary.test.ts 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. import { fileURLToPath } from "node:url";
  2. import { build } from "esbuild";
  3. import { describe, expect, it } from "vitest";
  4. const packageRoot = fileURLToPath(new URL("..", import.meta.url));
  5. const MAX_BROWSER_CLIENT_BUNDLE_BYTES = 150_000;
  6. function normalizePath(value: string): string {
  7. return value.replaceAll("\\", "/");
  8. }
  9. describe("browser-client bundle boundary", () => {
  10. it("只打包 Browser runtime,不带入 Agent Core", async () => {
  11. const result = await build({
  12. absWorkingDir: packageRoot,
  13. bundle: true,
  14. entryPoints: ["src/browser-client.ts"],
  15. format: "esm",
  16. legalComments: "none",
  17. metafile: true,
  18. platform: "node",
  19. target: "node24",
  20. write: false,
  21. });
  22. const output = result.outputFiles[0];
  23. expect(output!.contents.byteLength).toBeLessThanOrEqual(MAX_BROWSER_CLIENT_BUNDLE_BYTES);
  24. const inputs = Object.keys(result.metafile.inputs).map(normalizePath);
  25. const coreInputs = inputs.filter((path) => /(?:^|\/)core\/dist\//u.test(path));
  26. expect(coreInputs.length).toBeGreaterThan(0);
  27. expect(coreInputs.every((path) => /(?:^|\/)core\/dist\/browser-client\//u.test(path))).toBe(
  28. true,
  29. );
  30. const contractInputs = inputs.filter((path) => /(?:^|\/)contracts\/dist\//u.test(path));
  31. expect(contractInputs).toEqual([
  32. expect.stringMatching(/contracts\/dist\/interfaces\/browser-control\.port\.js$/u),
  33. ]);
  34. });
  35. });