mirror of
https://github.com/openfrontio/OpenFrontIO.git
synced 2026-07-21 01:56:11 +00:00
add testing infrastructure and example test (#276)
This commit is contained in:
@@ -0,0 +1,38 @@
|
||||
import { generateMap } from "../../src/scripts/TerrainMapGenerator";
|
||||
import fs from "fs/promises";
|
||||
import path from "path";
|
||||
import { createGame } from "../../src/core/game/GameImpl";
|
||||
import { genTerrainFromBin } from "../../src/core/game/TerrainMapLoader";
|
||||
import { TestConfig } from "./TestConfig";
|
||||
import { TestServerConfig } from "./TestServerConfig";
|
||||
import { UserSettings } from "../../src/core/game/UserSettings";
|
||||
import { Difficulty, GameType } from "../../src/core/game/Game";
|
||||
|
||||
export async function setup(mapName: string) {
|
||||
// Load the specified map
|
||||
const mapPath = path.join(__dirname, "..", "testdata", `${mapName}.png`);
|
||||
const imageBuffer = await fs.readFile(mapPath);
|
||||
const { map, miniMap } = await generateMap(imageBuffer);
|
||||
const gameMap = await genTerrainFromBin(String.fromCharCode.apply(null, map));
|
||||
const miniGameMap = await genTerrainFromBin(
|
||||
String.fromCharCode.apply(null, miniMap),
|
||||
);
|
||||
const nationMap = { nations: [] };
|
||||
|
||||
// Configure the game
|
||||
const serverConfig = new TestServerConfig();
|
||||
const gameConfig = {
|
||||
gameMap: null,
|
||||
gameType: GameType.Singleplayer,
|
||||
difficulty: Difficulty.Medium,
|
||||
disableNPCs: false,
|
||||
bots: 0,
|
||||
infiniteGold: false,
|
||||
infiniteTroops: false,
|
||||
instantBuild: false,
|
||||
};
|
||||
const config = new TestConfig(serverConfig, gameConfig, new UserSettings());
|
||||
|
||||
// Create and return the game
|
||||
return createGame(gameMap, miniGameMap, nationMap, config);
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
import { DefaultConfig } from "../../src/core/configuration/DefaultConfig";
|
||||
|
||||
export class TestConfig extends DefaultConfig {}
|
||||
@@ -0,0 +1,57 @@
|
||||
import { GameEnv, ServerConfig } from "../../src/core/configuration/Config";
|
||||
import { GameMapType } from "../../src/core/game/Game";
|
||||
import { GameID } from "../../src/core/Schemas";
|
||||
|
||||
export class TestServerConfig implements ServerConfig {
|
||||
turnIntervalMs(): number {
|
||||
throw new Error("Method not implemented.");
|
||||
}
|
||||
gameCreationRate(): number {
|
||||
throw new Error("Method not implemented.");
|
||||
}
|
||||
lobbyMaxPlayers(map: GameMapType): number {
|
||||
throw new Error("Method not implemented.");
|
||||
}
|
||||
discordRedirectURI(): string {
|
||||
throw new Error("Method not implemented.");
|
||||
}
|
||||
numWorkers(): number {
|
||||
throw new Error("Method not implemented.");
|
||||
}
|
||||
workerIndex(gameID: GameID): number {
|
||||
throw new Error("Method not implemented.");
|
||||
}
|
||||
workerPath(gameID: GameID): string {
|
||||
throw new Error("Method not implemented.");
|
||||
}
|
||||
workerPort(gameID: GameID): number {
|
||||
throw new Error("Method not implemented.");
|
||||
}
|
||||
workerPortByIndex(workerID: number): number {
|
||||
throw new Error("Method not implemented.");
|
||||
}
|
||||
env(): GameEnv {
|
||||
throw new Error("Method not implemented.");
|
||||
}
|
||||
adminToken(): string {
|
||||
throw new Error("Method not implemented.");
|
||||
}
|
||||
adminHeader(): string {
|
||||
throw new Error("Method not implemented.");
|
||||
}
|
||||
gitCommit(): string {
|
||||
throw new Error("Method not implemented.");
|
||||
}
|
||||
r2Bucket(): string {
|
||||
throw new Error("Method not implemented.");
|
||||
}
|
||||
r2Endpoint(): string {
|
||||
throw new Error("Method not implemented.");
|
||||
}
|
||||
r2AccessKey(): string {
|
||||
throw new Error("Method not implemented.");
|
||||
}
|
||||
r2SecretKey(): string {
|
||||
throw new Error("Method not implemented.");
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user