tsupConfig.test.ts 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. import { readFileSync } from "node:fs";
  2. import { resolve } from "node:path";
  3. import { describe, expect, it } from "vitest";
  4. import { SERVER_HTTP_DEFINES, SERVER_HTTP_EXTERNAL_DEPENDENCIES } from "../tsup.config.js";
  5. import { loadBuiltinProviderConfig } from "../../../scripts/builtin-provider-config.mjs";
  6. describe("server tsup config", () => {
  7. it("embeds the selected environment's Built-in config used by the HTTP entry", async () => {
  8. const expected = await loadBuiltinProviderConfig();
  9. expect(JSON.parse(SERVER_HTTP_DEFINES.__ZCODE_BUILTIN_PROVIDER_CONFIG_JSON__)).toBe(
  10. expected.content,
  11. );
  12. expect(JSON.parse(SERVER_HTTP_DEFINES.__ZCODE_ENV__)).toBe(expected.environment);
  13. });
  14. it("externalizes CommonJS multipart dependencies for the ESM HTTP dev bundle", () => {
  15. expect(SERVER_HTTP_EXTERNAL_DEPENDENCIES).toEqual(
  16. expect.arrayContaining([
  17. "axios",
  18. "form-data",
  19. "combined-stream",
  20. "proxy-from-env",
  21. "follow-redirects",
  22. "yazl",
  23. "node-forge",
  24. "yaml",
  25. ]),
  26. );
  27. });
  28. it("declares external runtime dependencies in the server package", () => {
  29. const packageJsonPath = resolve(import.meta.dirname, "../package.json");
  30. const packageJson = JSON.parse(readFileSync(packageJsonPath, "utf-8")) as {
  31. dependencies?: Record<string, string>;
  32. };
  33. // Bugfix: pnpm 不会把传递依赖暴露给 @zcode/server;HTTP bundle 外置后必须从 server 自身解析。
  34. expect(Object.keys(packageJson.dependencies ?? {})).toEqual(
  35. expect.arrayContaining(SERVER_HTTP_EXTERNAL_DEPENDENCIES),
  36. );
  37. });
  38. });