Bake server env into HTML bootstrap

This commit is contained in:
scamiv
2026-03-22 20:30:49 +01:00
parent 9e6140667b
commit 3d73f182b2
5 changed files with 48 additions and 3 deletions
@@ -0,0 +1,24 @@
import { beforeEach, describe, expect, test, vi } from "vitest";
import { GameEnv } from "../../../src/core/configuration/Config";
import {
clearCachedServerConfig,
getServerConfigFromClient,
} from "../../../src/core/configuration/ConfigLoader";
describe("ConfigLoader", () => {
beforeEach(() => {
vi.restoreAllMocks();
window.BOOTSTRAP_CONFIG = undefined;
clearCachedServerConfig();
});
test("uses bootstrap config without fetching /api/env", async () => {
window.BOOTSTRAP_CONFIG = { gameEnv: "prod" };
const fetchSpy = vi.spyOn(globalThis, "fetch");
const config = await getServerConfigFromClient();
expect(config.env()).toBe(GameEnv.Prod);
expect(fetchSpy).not.toHaveBeenCalled();
});
});