Files
OpenFrontIO/tests/core/game/Cluster.test.ts
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

67 lines
1.9 KiB
TypeScript

import { vi, type Mocked } from "vitest";
import { Cluster, TrainStation } from "../../../src/core/game/TrainStation";
const createMockStation = (id: string): Mocked<TrainStation> => {
return {
id,
setCluster: vi.fn(),
getCluster: vi.fn(() => null),
} as any;
};
describe("Cluster tests", () => {
let cluster: Cluster;
let stationA: Mocked<TrainStation>;
let stationB: Mocked<TrainStation>;
let stationC: Mocked<TrainStation>;
beforeEach(() => {
cluster = new Cluster();
stationA = createMockStation("A");
stationB = createMockStation("B");
stationC = createMockStation("C");
});
test("addStation adds a station and sets cluster", () => {
cluster.addStation(stationA);
expect(cluster.has(stationA)).toBe(true);
expect(stationA.setCluster).toHaveBeenCalledWith(cluster);
});
test("removeStation removes station from cluster", () => {
cluster.addStation(stationA);
cluster.removeStation(stationA);
expect(cluster.has(stationA)).toBe(false);
});
test("addStations adds multiple stations and sets cluster", () => {
const set = new Set([stationA, stationB]);
cluster.addStations(set);
expect(cluster.has(stationA)).toBe(true);
expect(cluster.has(stationB)).toBe(true);
expect(stationA.setCluster).toHaveBeenCalledWith(cluster);
expect(stationB.setCluster).toHaveBeenCalledWith(cluster);
});
test("merge combines stations from another cluster", () => {
const otherCluster = new Cluster();
otherCluster.addStation(stationB);
otherCluster.addStation(stationC);
cluster.addStation(stationA);
cluster.merge(otherCluster);
expect(cluster.has(stationA)).toBe(true);
expect(cluster.has(stationB)).toBe(true);
expect(cluster.has(stationC)).toBe(true);
});
test("has returns false for non-member stations", () => {
expect(cluster.has(stationA)).toBe(false);
});
});