testProxyFor

tcmts.cli.sync.testProxyFor · #55maa455 · term

import { proxyFor } from "#codebase/tcmts/cli/sync";

export const testProxyFor = () => {
  const proxies = [
    { path: "/examples/notes", to: "http://127.0.0.1:1" },
    { path: "/examples", to: "http://127.0.0.1:2" },
  ];
  const cases: [string, string | undefined][] = [
    ["/examples/notes", "http://127.0.0.1:1"],
    ["/examples/notes/", "http://127.0.0.1:1"],
    ["/examples/notes/__tcm/rpc/abc?x=1", "http://127.0.0.1:1"],
    ["/examples/notesy", "http://127.0.0.1:2"],
    ["/examples", "http://127.0.0.1:2"],
    ["/cli.html", undefined],
  ];
  for (const [url, want] of cases)
    if (proxyFor(proxies, url)?.to !== want)
      throw new Error(`${url}: ${proxyFor(proxies, url)?.to}, not ${want}`);
}

uses