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 { viewGame, type Action, type GameView } from '../game/engine'; import { PhaseBidPromiseGuideButton } from '../components/phase-bid-promises'; import { actTruthTurnBid, advanceTruthTurnBid, bindTruthTurnBid, createTruthTurnBidFixture, truthTurnBidClean } from './fixture-truth-turn-bid'; import { truthBidInventory } from './fixture-truth-bid'; 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'); aliases.deregister(); function table(game: GameView) { return renderToStaticMarkup(createElement(GameTable, { game, busy: false, send: async () => {}, onExit() {} })); } function truth(game: GameView) { return renderToStaticMarkup(createElement(Truthtrance, { game, busy: false, act() {} })); } for (const advanced of [false, true]) void test( `${advanced ? 'Advanced' : 'Basic'} actual phase-bid question, private answer and current owned guide connect to the original table`, () => { // Genuine original public setup/card deal and actual question/answer; the // selected unopened deck/Spice positions are documented by the source fixture. const f = createTruthTurnBidFixture({ advanced }), b = bindTruthTurnBid(f, 'yes'); const asker = viewGame(b.declared.game, f.asker); assert.ok(asker.truthPhaseBidTargets.includes(f.target)); const authored = truth(asker); assert.match(authored, /