WIP! A BB-style forum, on the ATmosphere! We're still working... we'll be back soon when we have something to show off!
node typescript hono htmx atproto
at root/atb-54-add-lightdark-mode-toggle 59 lines 1.9 kB view raw
1import { describe, it, expect, vi, beforeEach, afterEach } from "vitest"; 2 3describe("loadConfig", () => { 4 const originalEnv = { ...process.env }; 5 6 beforeEach(() => { 7 vi.resetModules(); 8 }); 9 10 afterEach(() => { 11 process.env = { ...originalEnv }; 12 }); 13 14 async function loadConfig() { 15 const mod = await import("../config.js"); 16 return mod.loadConfig(); 17 } 18 19 it("returns default port 3001 when WEB_PORT is undefined", async () => { 20 delete process.env.WEB_PORT; 21 const config = await loadConfig(); 22 expect(config.port).toBe(3001); 23 }); 24 25 it("parses WEB_PORT as an integer", async () => { 26 process.env.WEB_PORT = "8080"; 27 const config = await loadConfig(); 28 expect(config.port).toBe(8080); 29 expect(typeof config.port).toBe("number"); 30 }); 31 32 it("returns default appview URL when APPVIEW_URL is undefined", async () => { 33 delete process.env.APPVIEW_URL; 34 const config = await loadConfig(); 35 expect(config.appviewUrl).toBe("http://localhost:3000"); 36 }); 37 38 it("uses provided environment variables", async () => { 39 process.env.WEB_PORT = "9000"; 40 process.env.APPVIEW_URL = "https://api.atbb.space"; 41 const config = await loadConfig(); 42 expect(config.port).toBe(9000); 43 expect(config.appviewUrl).toBe("https://api.atbb.space"); 44 }); 45 46 it("returns NaN for port when WEB_PORT is empty string (?? does not catch empty strings)", async () => { 47 process.env.WEB_PORT = ""; 48 const config = await loadConfig(); 49 // Documents a gap: ?? only catches null/undefined, not "" 50 expect(config.port).toBeNaN(); 51 }); 52 53 it("returns empty string for appviewUrl when APPVIEW_URL is empty string", async () => { 54 process.env.APPVIEW_URL = ""; 55 const config = await loadConfig(); 56 // Documents a gap: ?? only catches null/undefined, not "" 57 expect(config.appviewUrl).toBe(""); 58 }); 59});