Split runtime and game logic env loading

This commit is contained in:
scamiv
2026-03-24 16:43:15 +01:00
parent 496f1008bb
commit d6cbf36d94
12 changed files with 122 additions and 55 deletions
+27 -7
View File
@@ -1,24 +1,44 @@
import { beforeEach, describe, expect, test, vi } from "vitest";
import { GameEnv } from "../../../src/core/configuration/Config";
import {
clearCachedServerConfig,
getServerConfigFromClient,
clearCachedRuntimeClientServerConfig,
GameLogicEnv,
getBuildTimeGameLogicEnv,
getGameLogicConfig,
getRuntimeClientServerConfig,
getServerConfigForGameLogicEnv,
} from "../../../src/core/configuration/ConfigLoader";
describe("ConfigLoader", () => {
const originalGameEnv = process.env.GAME_ENV;
beforeEach(() => {
vi.restoreAllMocks();
window.BOOTSTRAP_CONFIG = undefined;
clearCachedServerConfig();
process.env.GAME_ENV = originalGameEnv;
clearCachedRuntimeClientServerConfig();
});
test("uses bootstrap config without fetching /api/env", async () => {
window.BOOTSTRAP_CONFIG = { gameEnv: "prod" };
test("uses runtime bootstrap config without fetching /api/env", async () => {
window.BOOTSTRAP_CONFIG = { gameEnv: "staging" };
const fetchSpy = vi.spyOn(globalThis, "fetch");
const config = await getServerConfigFromClient();
const config = await getRuntimeClientServerConfig();
expect(config.env()).toBe(GameEnv.Prod);
expect(config.env()).toBe(GameEnv.Preprod);
expect(fetchSpy).not.toHaveBeenCalled();
});
test("maps staging builds to the default game logic config", async () => {
process.env.GAME_ENV = "staging";
expect(getBuildTimeGameLogicEnv()).toBe(GameLogicEnv.Default);
expect(getServerConfigForGameLogicEnv(GameLogicEnv.Default).env()).toBe(
GameEnv.Prod,
);
const config = await getGameLogicConfig({} as any, null);
expect(config.serverConfig().env()).toBe(GameEnv.Prod);
});
});