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 Discovery setup displays its bounded Semuta preview`, () => { let game = createGame('SEMUTADISCOVERYUI', newPlayer('r', 'Richese', 'richese'), advanced, ['choam']); joinGame(game, newPlayer('a', 'Atreides', 'atreides')); joinGame(game, newPlayer('e', 'Emperor', 'emperor')); game = applyAction(game, game.host, {type:'moduleOption', module:'discoveries', 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.equal(game.discoveryEnabled, true); 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 Discoveries preview/); assert.match(html, /Other discard opportunities remain unfinished\./); }, );