48 lines
1.4 KiB
TypeScript
48 lines
1.4 KiB
TypeScript
import { describe, expect, it } from "vitest";
|
|
import { loadConfig, ConfigError } from "../src/config.ts";
|
|
|
|
const baseEnv = {
|
|
STATION: "minecraft",
|
|
RTMP_URL: "rtmp://example/live/key",
|
|
LIQUIDSOAP_PCM: "tcp://liquidsoap:9100",
|
|
NOW_PLAYING_DIR: "/now-playing",
|
|
LIBRARY_DIR: "/library",
|
|
STYLE: "denpa",
|
|
TZ: "Asia/Tokyo",
|
|
VIDEO_BITRATE: "4500k",
|
|
AUDIO_BITRATE: "160k",
|
|
FRAMERATE: "30",
|
|
RESOLUTION: "1920x1080",
|
|
STATION_TUNE_IN_URL: "denpa.femboy.page",
|
|
HEALTH_PORT: "12010",
|
|
LOG_LEVEL: "info",
|
|
};
|
|
|
|
describe("loadConfig", () => {
|
|
it("parses required fields", () => {
|
|
const cfg = loadConfig(baseEnv);
|
|
expect(cfg.station).toBe("minecraft");
|
|
expect(cfg.rtmpUrl).toBe("rtmp://example/live/key");
|
|
expect(cfg.style).toBe("denpa");
|
|
expect(cfg.framerate).toBe(30);
|
|
});
|
|
|
|
it("rejects invalid style", () => {
|
|
expect(() => loadConfig({ ...baseEnv, STYLE: "weird" })).toThrow(ConfigError);
|
|
});
|
|
|
|
it("rejects malformed rtmp url", () => {
|
|
expect(() => loadConfig({ ...baseEnv, RTMP_URL: "not-a-url" })).toThrow(ConfigError);
|
|
});
|
|
|
|
it("rejects missing required field", () => {
|
|
const { STATION: _omit, ...rest } = baseEnv;
|
|
expect(() => loadConfig(rest)).toThrow(ConfigError);
|
|
});
|
|
|
|
it("parses pcm tcp url", () => {
|
|
const cfg = loadConfig(baseEnv);
|
|
expect(cfg.pcmHost).toBe("liquidsoap");
|
|
expect(cfg.pcmPort).toBe(9100);
|
|
});
|
|
});
|