mirror of
https://github.com/openfrontio/OpenFrontIO.git
synced 2026-07-01 02:02:02 +00:00
Split runtime and game logic env loading
This commit is contained in:
@@ -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);
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user