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(); void test('public Advanced Richese setup displays the limited ordinary Semuta notice', () => { let game = createGame('ADVSEMUTAUI', newPlayer('a', 'Atreides', 'atreides'), true, ['choam']); joinGame(game, newPlayer('r', 'Richese', 'richese')); joinGame(game, newPlayer('e', 'Emperor', 'emperor')); for (const player of game.players) game = applyAction(game, player.id, {type:'ready'}); game = applyAction(game, 'a', {type:'start', advancedPreview:true}); assert.equal(game.status, 'setup'); const view = viewGame(game, 'r'); assert.equal(view.semutaAdvancedOrdinaryPreview, true); assert.equal(view.semutaPreview, false); const html = renderToStaticMarkup(createElement(GameTable, { game:view, busy:false, send:async () => {}, onExit() {}, })); assert.match(html, /Advanced Semuta preview: supported Hajr, Ghola, Harvester, Weather Control, completed Box, Distrans, simple Truthtrance, Residual Poison and CHOAM sale or Worthless discards can be claimed/); assert.match(html, /supported battle cleanup/); assert.match(html, /Other discard opportunities remain unfinished/); assert.doesNotMatch(html, /Semuta Drug development preview/); assert.doesNotMatch(html, /Semuta Drug with Homeworlds development preview/); });