Files
OpenFrontIO/tests/core/game/GameImpl.test.ts
T
Wraith 26f5d40819 build: migrate build system to Vite and test runner to Vitest & Remove depracated husky usage (#2703)
- Replace Webpack with Vite for faster client bundling and HMR.
- Migrate tests from Jest to Vitest and update configuration.
- Update Web Worker instantiation to standard ESM syntax.
- Implement Env utility in `src/core` for safe, hybrid environment
variable access (Vite vs Node).
- Refactor configuration loaders to remove direct `process.env`
dependencies in shared code.
- Update TypeScript environment definitions and project scripts for the
new toolchain.
- Remove the [depracated usage of the
husky](https://github.com/typicode/husky/releases/tag/v9.0.1).

## Description:

migrate build system to Vite and test runner to Vitest & Remove
depracated husky usage

## Please complete the following:

- [X] I have added screenshots for all UI updates
- [X] I process any text displayed to the user through translateText()
and I've added it to the en.json file
- [ ] I have added relevant tests to the test directory
- [X] I confirm I have thoroughly tested these changes and take full
responsibility for any bugs introduced

## Please put your Discord username so you can be contacted if a bug or
regression is found:

wraith4081

---------

Co-authored-by: evanpelle <evanpelle@gmail.com>
2025-12-28 22:10:26 -08:00

147 lines
4.1 KiB
TypeScript

import { GameID } from "../../../src/core/Schemas";
import { AttackExecution } from "../../../src/core/execution/AttackExecution";
import { SpawnExecution } from "../../../src/core/execution/SpawnExecution";
//import { TransportShipExecution } from "../../../src/core/execution/TransportShipExecution";
import { AllianceRequestExecution } from "../../../src/core/execution/alliance/AllianceRequestExecution";
import { AllianceRequestReplyExecution } from "../../../src/core/execution/alliance/AllianceRequestReplyExecution";
import {
Game,
Player,
PlayerInfo,
PlayerType,
} from "../../../src/core/game/Game";
import { TileRef } from "../../../src/core/game/GameMap";
import { setup } from "../../util/Setup";
const gameID: GameID = "game_id";
let game: Game;
let attacker: Player;
let defender: Player;
let defenderSpawn: TileRef;
let attackerSpawn: TileRef;
describe("GameImpl", () => {
beforeEach(async () => {
game = await setup("ocean_and_land", {
infiniteGold: true,
instantBuild: true,
infiniteTroops: true,
});
const attackerInfo = new PlayerInfo(
"attacker dude",
PlayerType.Human,
null,
"attacker_id",
);
game.addPlayer(attackerInfo);
const defenderInfo = new PlayerInfo(
"defender dude",
PlayerType.Human,
null,
"defender_id",
);
game.addPlayer(defenderInfo);
defenderSpawn = game.ref(0, 15);
attackerSpawn = game.ref(0, 14);
game.addExecution(
new SpawnExecution(
gameID,
game.player(attackerInfo.id).info(),
attackerSpawn,
),
new SpawnExecution(
gameID,
game.player(defenderInfo.id).info(),
defenderSpawn,
),
);
while (game.inSpawnPhase()) {
game.executeNextTick();
}
attacker = game.player(attackerInfo.id);
defender = game.player(defenderInfo.id);
});
test("Don't become traitor when betraying inactive player", async () => {
vi.spyOn(attacker, "canSendAllianceRequest").mockReturnValue(true);
game.addExecution(new AllianceRequestExecution(attacker, defender.id()));
game.executeNextTick();
game.executeNextTick();
game.addExecution(
new AllianceRequestReplyExecution(attacker.id(), defender, true),
);
game.executeNextTick();
game.executeNextTick();
expect(attacker.allianceWith(defender)).toBeTruthy();
expect(defender.allianceWith(attacker)).toBeTruthy();
//Defender is marked disconnected
defender.markDisconnected(true);
game.executeNextTick();
game.executeNextTick();
// STEP 1: First betray (manually break alliance)
const alliance = attacker.allianceWith(defender);
expect(alliance).toBeTruthy();
attacker.breakAlliance(alliance!);
// STEP 2: Then attack after betrayal
game.addExecution(new AttackExecution(100, attacker, defender.id()));
do {
game.executeNextTick();
} while (attacker.outgoingAttacks().length > 0);
expect(attacker.isTraitor()).toBe(false);
expect(attacker.allianceWith(defender)).toBeFalsy();
});
test("Do become traitor when betraying active player", async () => {
vi.spyOn(attacker, "canSendAllianceRequest").mockReturnValue(true);
game.addExecution(new AllianceRequestExecution(attacker, defender.id()));
game.executeNextTick();
game.executeNextTick();
game.addExecution(
new AllianceRequestReplyExecution(attacker.id(), defender, true),
);
game.executeNextTick();
game.executeNextTick();
expect(attacker.allianceWith(defender)).toBeTruthy();
expect(defender.allianceWith(attacker)).toBeTruthy();
//Defender is NOT marked disconnected
game.executeNextTick();
game.executeNextTick();
// First betray (manually break alliance)
const alliance = attacker.allianceWith(defender);
expect(alliance).toBeTruthy();
attacker.breakAlliance(alliance!);
game.executeNextTick();
game.addExecution(new AttackExecution(100, attacker, defender.id()));
do {
game.executeNextTick();
} while (attacker.outgoingAttacks().length > 0);
expect(attacker.isTraitor()).toBe(true);
expect(attacker.allianceWith(defender)).toBeFalsy();
});
});