Files
copilotkit__copilotkit/showcase/shell-dashboard/src/lib/runtime-config.client.test.ts
Jordan Ritter 8714ab569b chore(showcase): apply oxfmt formatting across showcase scripts and shells
oxfmt --write normalized formatting on showcase scripts, the four shells, and the
new oxlint rule; required for the repo-root oxfmt --check CI gate.
2026-05-29 11:45:16 -07:00

58 lines
2.0 KiB
TypeScript

import { afterEach, beforeEach, describe, expect, it } from "vitest";
import { getRuntimeConfig } from "./runtime-config.client";
describe("client getRuntimeConfig (shell-dashboard)", () => {
const originalWindow = globalThis.window;
beforeEach(() => {
// jsdom provides `window` by default in this vitest config.
// Reset any prior injection.
delete (globalThis.window as Window & { __SHOWCASE_CONFIG__?: unknown })
.__SHOWCASE_CONFIG__;
});
afterEach(() => {
(globalThis as { window?: Window }).window = originalWindow;
});
it("returns the injected config", () => {
(window as Window & { __SHOWCASE_CONFIG__?: unknown }).__SHOWCASE_CONFIG__ =
{
pocketbaseUrl: "https://pb.example.com",
shellUrl: "https://shell.example.com",
opsBaseUrl: "https://ops.example.com",
};
expect(getRuntimeConfig()).toEqual({
pocketbaseUrl: "https://pb.example.com",
shellUrl: "https://shell.example.com",
opsBaseUrl: "https://ops.example.com",
});
});
it("throws when __SHOWCASE_CONFIG__ is missing (wiring bug)", () => {
expect(() => getRuntimeConfig()).toThrow(
/window\.__SHOWCASE_CONFIG__ is missing/,
);
});
it("returns SSR sentinel placeholder when window is undefined", () => {
// Simulate SSR by removing window. "use client" component
// bodies execute on the server during SSR, so this reader
// MUST be SSR-safe (returns parseable-URL placeholders so
// `new URL()` in consumers doesn't throw) and NOT throw —
// otherwise the whole server-rendered HTML 500s.
const w = globalThis.window;
// @ts-expect-error — deliberately removing window for the test
delete globalThis.window;
try {
const cfg = getRuntimeConfig();
// URL fields must be parseable.
expect(() => new URL(cfg.pocketbaseUrl)).not.toThrow();
expect(() => new URL(cfg.shellUrl)).not.toThrow();
expect(() => new URL(cfg.opsBaseUrl)).not.toThrow();
} finally {
(globalThis as { window?: typeof w }).window = w;
}
});
});