mirror of
https://github.com/openfrontio/OpenFrontIO.git
synced 2026-06-21 13:40:46 +00:00
26f5d40819
- 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>
153 lines
4.7 KiB
TypeScript
153 lines
4.7 KiB
TypeScript
import { AutoUpgradeEvent } from "../src/client/InputHandler";
|
|
import { EventBus } from "../src/core/EventBus";
|
|
|
|
describe("AutoUpgrade Feature", () => {
|
|
let eventBus: EventBus;
|
|
|
|
beforeEach(() => {
|
|
eventBus = new EventBus();
|
|
});
|
|
|
|
describe("AutoUpgradeEvent", () => {
|
|
test("should create AutoUpgradeEvent with correct coordinates", () => {
|
|
const event = new AutoUpgradeEvent(100, 200);
|
|
expect(event.x).toBe(100);
|
|
expect(event.y).toBe(200);
|
|
});
|
|
|
|
test("should emit AutoUpgradeEvent when created", () => {
|
|
const mockEmit = vi.spyOn(eventBus, "emit");
|
|
|
|
const event = new AutoUpgradeEvent(150, 250);
|
|
eventBus.emit(event);
|
|
|
|
expect(mockEmit).toHaveBeenCalledWith(event);
|
|
expect(mockEmit).toHaveBeenCalledWith(
|
|
expect.objectContaining({
|
|
x: 150,
|
|
y: 250,
|
|
}),
|
|
);
|
|
});
|
|
});
|
|
|
|
describe("AutoUpgradeEvent Integration", () => {
|
|
test("should handle multiple AutoUpgradeEvents", () => {
|
|
const mockEmit = vi.spyOn(eventBus, "emit");
|
|
|
|
const event1 = new AutoUpgradeEvent(100, 200);
|
|
const event2 = new AutoUpgradeEvent(300, 400);
|
|
|
|
eventBus.emit(event1);
|
|
eventBus.emit(event2);
|
|
|
|
expect(mockEmit).toHaveBeenCalledTimes(2);
|
|
expect(mockEmit).toHaveBeenNthCalledWith(1, event1);
|
|
expect(mockEmit).toHaveBeenNthCalledWith(2, event2);
|
|
});
|
|
|
|
test("should handle AutoUpgradeEvent with zero coordinates", () => {
|
|
const event = new AutoUpgradeEvent(0, 0);
|
|
expect(event.x).toBe(0);
|
|
expect(event.y).toBe(0);
|
|
});
|
|
|
|
test("should handle AutoUpgradeEvent with negative coordinates", () => {
|
|
const event = new AutoUpgradeEvent(-100, -200);
|
|
expect(event.x).toBe(-100);
|
|
expect(event.y).toBe(-200);
|
|
});
|
|
|
|
test("should handle AutoUpgradeEvent with decimal coordinates", () => {
|
|
const event = new AutoUpgradeEvent(100.5, 200.7);
|
|
expect(event.x).toBe(100.5);
|
|
expect(event.y).toBe(200.7);
|
|
});
|
|
});
|
|
|
|
describe("AutoUpgradeEvent Event Bus Integration", () => {
|
|
test("should allow event listeners to subscribe to AutoUpgradeEvent", () => {
|
|
const mockListener = vi.fn();
|
|
const event = new AutoUpgradeEvent(100, 200);
|
|
|
|
eventBus.on(AutoUpgradeEvent, mockListener);
|
|
eventBus.emit(event);
|
|
|
|
expect(mockListener).toHaveBeenCalledWith(event);
|
|
});
|
|
|
|
test("should allow multiple listeners for AutoUpgradeEvent", () => {
|
|
const mockListener1 = vi.fn();
|
|
const mockListener2 = vi.fn();
|
|
const event = new AutoUpgradeEvent(100, 200);
|
|
|
|
eventBus.on(AutoUpgradeEvent, mockListener1);
|
|
eventBus.on(AutoUpgradeEvent, mockListener2);
|
|
eventBus.emit(event);
|
|
|
|
expect(mockListener1).toHaveBeenCalledWith(event);
|
|
expect(mockListener2).toHaveBeenCalledWith(event);
|
|
});
|
|
|
|
test("should not call unsubscribed listeners", () => {
|
|
const mockListener = vi.fn();
|
|
const event = new AutoUpgradeEvent(100, 200);
|
|
|
|
eventBus.on(AutoUpgradeEvent, mockListener);
|
|
eventBus.off(AutoUpgradeEvent, mockListener);
|
|
eventBus.emit(event);
|
|
|
|
expect(mockListener).not.toHaveBeenCalled();
|
|
});
|
|
});
|
|
|
|
describe("AutoUpgradeEvent Edge Cases", () => {
|
|
test("should handle very large coordinates", () => {
|
|
const event = new AutoUpgradeEvent(
|
|
Number.MAX_SAFE_INTEGER,
|
|
Number.MAX_SAFE_INTEGER,
|
|
);
|
|
expect(event.x).toBe(Number.MAX_SAFE_INTEGER);
|
|
expect(event.y).toBe(Number.MAX_SAFE_INTEGER);
|
|
});
|
|
|
|
test("should handle very small coordinates", () => {
|
|
const event = new AutoUpgradeEvent(
|
|
Number.MIN_SAFE_INTEGER,
|
|
Number.MIN_SAFE_INTEGER,
|
|
);
|
|
expect(event.x).toBe(Number.MIN_SAFE_INTEGER);
|
|
expect(event.y).toBe(Number.MIN_SAFE_INTEGER);
|
|
});
|
|
|
|
test("should handle NaN coordinates", () => {
|
|
const event = new AutoUpgradeEvent(NaN, NaN);
|
|
expect(isNaN(event.x)).toBe(true);
|
|
expect(isNaN(event.y)).toBe(true);
|
|
});
|
|
|
|
test("should handle Infinity coordinates", () => {
|
|
const event = new AutoUpgradeEvent(Infinity, -Infinity);
|
|
expect(event.x).toBe(Infinity);
|
|
expect(event.y).toBe(-Infinity);
|
|
});
|
|
});
|
|
|
|
describe("AutoUpgradeEvent Serialization", () => {
|
|
test("should maintain coordinate precision", () => {
|
|
const event = new AutoUpgradeEvent(100.123456789, 200.987654321);
|
|
expect(event.x).toBe(100.123456789);
|
|
expect(event.y).toBe(200.987654321);
|
|
});
|
|
|
|
test("should handle string conversion", () => {
|
|
const event = new AutoUpgradeEvent(100, 200);
|
|
const eventString = JSON.stringify(event);
|
|
const parsedEvent = JSON.parse(eventString);
|
|
|
|
expect(parsedEvent.x).toBe(100);
|
|
expect(parsedEvent.y).toBe(200);
|
|
});
|
|
});
|
|
});
|