44 lines
2.3 KiB
TypeScript
44 lines
2.3 KiB
TypeScript
import assert from 'node:assert/strict';
|
|
import test from 'node:test';
|
|
import { registerHooks } from 'node:module';
|
|
import { readFileSync } from 'node:fs';
|
|
import { createElement } from 'react';
|
|
import { renderToStaticMarkup } from 'react-dom/server';
|
|
import { applyAction, createGame, joinGame, newPlayer, viewGame } from '../game/engine';
|
|
|
|
const aliases = registerHooks({
|
|
resolve(specifier, context, next) {
|
|
return next(specifier === 'next/image' ? 'vinext/shims/image' :
|
|
specifier === 'next/link' ? 'vinext/shims/link' : specifier, context);
|
|
},
|
|
load(url, context, next) {
|
|
if (!url.endsWith('.module.css')) return next(url, context);
|
|
const css = readFileSync(new URL(url), 'utf8');
|
|
const classes = Object.fromEntries([...css.matchAll(/\.([a-zA-Z_][\w-]*)/g)].map(match => [match[1], match[1]]));
|
|
return {format:'module', source:`export default ${JSON.stringify(classes)}`, shortCircuit:true};
|
|
},
|
|
});
|
|
const { GameTable } = await import('../components/game-table');
|
|
aliases.deregister();
|
|
|
|
for (const advanced of [false, true]) void test(
|
|
`public ${advanced ? 'Advanced' : 'Basic'} Richese Homeworld setup displays its bounded Semuta preview`, () => {
|
|
let game = createGame('SEMUTAHOMEWORLDUI', newPlayer('r', 'Richese', 'richese'), advanced, ['choam']);
|
|
joinGame(game, newPlayer('a', 'Atreides', 'atreides'));
|
|
joinGame(game, newPlayer('e', 'Emperor', 'emperor'));
|
|
game = applyAction(game, game.host, {type:'homeworlds', enabled:true});
|
|
for (const player of game.players) game = applyAction(game, player.id, {type:'ready'});
|
|
game = applyAction(game, game.host, {type:'start', ...(advanced ? {advancedPreview:true} : {})});
|
|
assert.equal(game.status, 'setup');
|
|
assert.ok(game.homeworlds);
|
|
assert.equal(game.semutaPreview, true);
|
|
const html = renderToStaticMarkup(createElement(GameTable, {
|
|
game:viewGame(game, 'r'), busy:false, send:async () => {}, onExit() {},
|
|
})).replace(/\s+/g, ' ');
|
|
assert.match(html, /Semuta Drug with Homeworlds development preview/);
|
|
assert.match(html, /Sapho can also reorder supported simultaneous Truthtrance questions; the same question queue resumes after the Semuta reaction/);
|
|
assert.match(html, /Other Homeworld producers and Basic unresolved Tupile loss remain guarded/);
|
|
assert.match(html, /Not complete or certified Homeworld rules/);
|
|
},
|
|
);
|