// The single-file build. // // A build that produces a file proves nothing; this one runs the bundled // script against the fake DOM and plays a turn through it. That is the closest // thing to opening dist/theladder.html that is available without a browser — // it catches a broken bundle, which is otherwise only discovered by whoever // was handed the file. import { test } from 'node:test'; import assert from 'node:assert/strict'; import { execFileSync } from 'node:child_process'; import { readFileSync } from 'node:fs'; import { resolve, dirname } from 'node:path'; import { fileURLToPath } from 'node:url'; import { installFakeDom, byClass, firstByClass } from './fixtures/fake-dom.js'; const root = resolve(dirname(fileURLToPath(import.meta.url)), '..'); test('the bundle builds, and the bundled game boots and plays', () => { execFileSync('node', ['tools/build.js'], { cwd: root, stdio: 'pipe' }); const html = readFileSync(resolve(root, 'dist/theladder.html'), 'utf8'); assert.doesNotMatch(html, /([\s\S]*?)<\/script>/)?.[1]; assert.ok(script, 'the bundled script is present'); const dom = installFakeDom(); try { // eslint-disable-next-line no-new-func -- running the build output is the point new Function(script)(); assert.ok(firstByClass(dom.root, 'screen--turn'), 'the bundled game rendered a turn'); assert.match(dom.root.textContent, /Day 1/); assert.match(dom.root.textContent, /Marlene Hobb/); const playable = byClass(dom.root, 'option').filter((b) => !b.disabled); assert.ok(playable.length > 0, 'the bundled game offers choices'); playable[0].click(); assert.ok(firstByClass(dom.root, 'outcome'), 'a turn can be played in the bundle'); } finally { dom.restore(); } });