umpirix/sdk/js/test/runtime.test.ts
caelum0x 4847e35451 OpenJev: open-source typed decision service
Typed decision/classification service with an in-process gte-small ONNX
embedding engine and lexical fallback, JS/Python SDKs, adapters, and the
otsone model family. Apache-2.0 (sub-packages keep their MIT licenses).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-09-25 00:12:36 +03:00

40 lines
1.4 KiB
TypeScript

import { afterEach, describe, expect, it, vi } from "vitest";
import { describeRuntime, isBrowser } from "../src/runtime";
describe("describeRuntime", () => {
afterEach(() => vi.unstubAllGlobals());
it("reports node with platform and arch here", () => {
expect(describeRuntime()).toMatch(/^node\/\d+\.\d+\.\d+ \(\w+; \w+\)$/);
});
it("prefers Bun over node when both are present", () => {
vi.stubGlobal("Bun", { version: "1.2.3" });
expect(describeRuntime()).toMatch(/^bun\/1\.2\.3 \(\w+; \w+\)$/);
});
it("recognizes Deno", () => {
vi.stubGlobal("Deno", { version: { deno: "2.1.0" } });
expect(describeRuntime()).toMatch(/^deno\/2\.1\.0/);
});
it("recognizes edge runtimes by their markers", () => {
vi.stubGlobal("EdgeRuntime", "edge-runtime");
expect(describeRuntime()).toBe("vercel-edge");
vi.unstubAllGlobals();
vi.stubGlobal("navigator", { userAgent: "Cloudflare-Workers" });
expect(describeRuntime()).toBe("cloudflare-workers");
});
it("falls back to browser, then unknown", () => {
vi.stubGlobal("process", undefined);
vi.stubGlobal("window", { document: {} });
vi.stubGlobal("navigator", { userAgent: "Mozilla/5.0" });
expect(isBrowser()).toBe(true);
expect(describeRuntime()).toBe("browser");
vi.stubGlobal("window", undefined);
expect(isBrowser()).toBe(false);
expect(describeRuntime()).toBe("unknown");
});
});