| 1 | import { CONFIGURED_LOCAL_SERVER_URLS_MAX_ITEMS, PREVIEW_URL_MAX_LENGTH } from "@t3tools/contracts"; |
| 2 | import { describe, expect, it } from "vite-plus/test"; |
| 3 | |
| 4 | import { boundConfiguredLocalServerUrls } from "./portDiscoveryState"; |
| 5 | |
| 6 | describe("boundConfiguredLocalServerUrls", () => { |
| 7 | it("keeps subscription payloads within the discovery RPC bounds", () => { |
| 8 | const urls = Array.from( |
| 9 | { length: CONFIGURED_LOCAL_SERVER_URLS_MAX_ITEMS + 1 }, |
| 10 | (_, index) => `http://localhost:${3_000 + index}`, |
| 11 | ); |
| 12 | urls.unshift( |
| 13 | "https://example.com", |
| 14 | "not a URL", |
| 15 | `http://localhost/${"a".repeat(PREVIEW_URL_MAX_LENGTH)}`, |
| 16 | ); |
| 17 | |
| 18 | const bounded = boundConfiguredLocalServerUrls(urls); |
| 19 | |
| 20 | expect(bounded).toHaveLength(CONFIGURED_LOCAL_SERVER_URLS_MAX_ITEMS); |
| 21 | expect(bounded.every((url) => url.startsWith("http://localhost:"))).toBe(true); |
| 22 | }); |
| 23 | |
| 24 | it("does not let fragment-only variants crowd out another server", () => { |
| 25 | const fragments = Array.from( |
| 26 | { length: CONFIGURED_LOCAL_SERVER_URLS_MAX_ITEMS }, |
| 27 | (_, index) => `http://localhost:3000/docs#section-${index}`, |
| 28 | ); |
| 29 | |
| 30 | expect(boundConfiguredLocalServerUrls([...fragments, "http://localhost:4000/app"])).toEqual([ |
| 31 | "http://localhost:3000/docs#section-0", |
| 32 | "http://localhost:4000/app", |
| 33 | ]); |
| 34 | }); |
| 35 | }); |