import { describe, expect, it } from "vitest"; import { parseRuntimeConfig } from "../src/config/index.js"; describe("parseRuntimeConfig", () => { it("returns defaults when env values are missing", () => { expect(parseRuntimeConfig({})).toEqual({ mode: "development", port: 3000, }); }); it("parses valid runtime mode and port", () => { expect( parseRuntimeConfig({ RUNTIME_MODE: "production", HTTP_PORT: "8080", }), ).toEqual({ mode: "production", port: 8080, }); }); it("normalizes mode casing and surrounding whitespace", () => { expect( parseRuntimeConfig({ RUNTIME_MODE: " PrOdUcTiOn ", HTTP_PORT: " 8081 ", }), ).toEqual({ mode: "production", port: 8081, }); }); it("rejects invalid runtime mode", () => { expect(() => parseRuntimeConfig({ RUNTIME_MODE: "staging", }), ).toThrow(/Invalid RUNTIME_MODE/); }); it("rejects invalid http port", () => { expect(() => parseRuntimeConfig({ HTTP_PORT: "0", }), ).toThrow(/Invalid HTTP_PORT/); expect(() => parseRuntimeConfig({ HTTP_PORT: "not-a-number", }), ).toThrow(/Invalid HTTP_PORT/); expect(() => parseRuntimeConfig({ HTTP_PORT: "65536", }), ).toThrow(/Invalid HTTP_PORT/); expect(() => parseRuntimeConfig({ HTTP_PORT: "42.5", }), ).toThrow(/Invalid HTTP_PORT/); }); });