16 lines
1.3 KiB
TypeScript
16 lines
1.3 KiB
TypeScript
import {test} from 'node:test';
|
|
import assert from 'node:assert/strict';
|
|
import {createTemplateGame} from '../../YouleNexus/assets/games/template/template-game.ts';
|
|
test('template module attaches only when opened and releases its view and subscription',()=>{
|
|
let unsubscribed=0;const commands:unknown[]=[];const views:unknown[]=[];
|
|
const snapshot={connection:{phase:'logged-in'},self:{playerId:1,seat:0},room:{roomcode:'123456',roomtype:[],stage:0,needprepare:0,infinite:0},seats:[]};
|
|
const game=createTemplateGame('g');const probe=game.entry.createModule();probe.dispose();
|
|
assert.throws(()=>game.mount({render:s=>views.push(s),close(){}}));
|
|
const module=game.entry.createModule();
|
|
module.attach({getSnapshot:()=>snapshot,subscribe:()=>()=>unsubscribed++,execute:(c:unknown)=>commands.push(c),seat:{toView:(n:number)=>n,toServer:(n:number)=>n},sendGameMessage(){}} as any);
|
|
let actions:any;game.mount({render:(s,a)=>{views.push(s);actions=a;},close:()=>views.push('closed')});
|
|
actions.exit();actions.prepare();assert.deepEqual(commands,[{type:'room.exit'},{type:'room.prepare'}]);
|
|
const deskinfo={nested:[1,2]};module.restore(deskinfo);assert.equal(game.restoredSnapshot,deskinfo);
|
|
module.dispose();assert.equal(unsubscribed,1);assert.equal(views[views.length - 1],'closed');assert.throws(()=>actions.exit());
|
|
});
|