ts-mcp-template/tests/config.test.ts
Jax 8df0a58dfa feat: migrate verified template implementation into main repo
Ultraworked with [Sisyphus](https://github.com/code-yeongyu/oh-my-opencode)

Co-authored-by: Sisyphus <clio-agent@sisyphuslabs.ai>
2026-03-11 22:10:25 +08:00

70 lines
1.5 KiB
TypeScript

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/);
});
});