import assert from 'node:assert/strict'; import test from 'node:test'; import { registerHooks } from 'node:module'; import { readFileSync } from 'node:fs'; import { Children, createElement, isValidElement } from 'react'; import { renderToStaticMarkup } from 'react-dom/server'; import { viewGame, type Action, type GameView } from '../game/engine'; import { act, askTruthCharityEarly as ask, createTruthCharityEarlyFixture as fixture, declareTruthCharityEarly as declare, inventory, player, reachEarlyCharity as reach, rejectTruthCharityEarly as reject } from './fixture-truth-charity-early'; 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'); const {Truthtrance} = await import('../components/truthtrance'); const {TruthCharityPromise} = await import('../components/truth-charity-promise'); aliases.deregister(); const table = (game: GameView) => renderToStaticMarkup(createElement(GameTable,{game,busy:false,send:async()=>{},onExit(){}})); const truth = (game: GameView) => renderToStaticMarkup(createElement(Truthtrance,{game,busy:false,act(){}})); for (const phase of [0,1] as const) { void test(`Basic phase ${phase} Truthtrance presents Charity question and private answer controls`, () => { const f=fixture(phase), declared=declare(f), asker=viewGame(declared,f.asker); assert.ok(asker.truthCharityTargets.includes(f.target)); assert.match(truth(asker),/