import { test } from 'node:test'; import assert from 'node:assert/strict'; import { ActiveGame } from '../../YouleNexus/assets/framework/protocol/active-game.ts'; import type { IGameModule, GameContext } from '../../YouleNexus/assets/framework/sdk/index.ts'; class MockGame implements IGameModule { readonly route = 'mock'; events: string[] = []; onEnter(_ctx: GameContext): void { this.events.push('onEnter'); } onExit(): void { this.events.push('onExit'); } onReceive(rpc: string, _d: unknown): void { this.events.push(`onReceive:${rpc}`); } onReconnect(_d: unknown): void { this.events.push('onReconnect'); } } test('初始: getGame 返回 null', () => { assert.equal(new ActiveGame().get(), null); }); test('setGame: 设置后 get 返回同一实例', () => { const slot = new ActiveGame(); const g = new MockGame(); slot.set(g); assert.equal(slot.get(), g); }); test('clear: 清空后 get 返回 null', () => { const slot = new ActiveGame(); slot.set(new MockGame()); slot.clear(); assert.equal(slot.get(), null); }); test('set 覆盖前一个 game', () => { const slot = new ActiveGame(); const g1 = new MockGame(); const g2 = new MockGame(); slot.set(g1); slot.set(g2); assert.equal(slot.get(), g2); });