Skip to content

Self-hosted, plugin-based server management.

1.1 KB
Raw Blame
import { describe, it, expect, afterEach } from "vitest";
import { getBasePath } from "../../lib/base-path.js";

const win = window as unknown as Record<string, unknown>;

afterEach(() => {
  delete win.__TERMIX_BASE_PATH__;
  document.querySelector('meta[name="termix-base-path"]')?.remove();
});

describe("getBasePath", () => {
  it("returns empty string when no runtime override is set (default base)", () => {
    // Vite test env BASE_URL is "/" which the helper normalizes to "".
    expect(getBasePath()).toBe("");
  });

  it("uses the runtime override when present", () => {
    win.__TERMIX_BASE_PATH__ = "/termix";
    expect(getBasePath()).toBe("/termix");
  });

  it("uses the CSP-safe runtime meta value when present", () => {
    const meta = document.createElement("meta");
    meta.name = "termix-base-path";
    meta.content = "/gateway/termix";
    document.head.append(meta);

    expect(getBasePath()).toBe("/gateway/termix");
  });

  it("strips a trailing slash from the runtime override", () => {
    win.__TERMIX_BASE_PATH__ = "/termix/";
    expect(getBasePath()).toBe("/termix");
  });
});