Split the game page into partials under src/, assembled into one index.html at build
site/index.html (900 KB of HTML, CSS and JS in one file) becomes src/: a shell (src/index.html), styles/ and game/, concatenated in path order by scripts/lib/page.js. The assembled page is byte-identical to the old file, so load time and in-game performance are unchanged. - scripts/build.js replaces build.sh (same env vars, same output) - npm run dev: a zero-dependency dev server that assembles on every request - tests assemble the page in memory; npm test runs every tests/*.test.js - perf-bench takes --base-ref to build a git ref's page - scripts/legacy/split-index-html.js is the splitter, kept for older branches
This commit is contained in:
parent
295e68cc46
commit
67a40942b4
113 changed files with 5584 additions and 5195 deletions
|
|
@ -8,7 +8,7 @@ const OUT = require('node:fs').mkdtempSync(require('node:path').join(require('no
|
|||
const root = path.join(__dirname, '..');
|
||||
|
||||
test('build stamps version and date into the site', () => {
|
||||
execFileSync('bash', ['scripts/build.sh'], { cwd: root, env: { ...process.env, OUT, VERSION: '9.9.9', BUILD_DATE: '2030-01-01' } });
|
||||
execFileSync(process.execPath, ['scripts/build.js'], { cwd: root, env: { ...process.env, OUT, VERSION: '9.9.9', BUILD_DATE: '2030-01-01' } });
|
||||
const html = fs.readFileSync(path.join(OUT, 'index.html'), 'utf8');
|
||||
assert.match(html, /const APP_VERSION='9\.9\.9'/);
|
||||
assert.match(html, /"softwareVersion": "9\.9\.9"/);
|
||||
|
|
@ -19,7 +19,7 @@ test('build stamps version and date into the site', () => {
|
|||
});
|
||||
|
||||
test('version.json carries the release notes from the changelog', () => {
|
||||
execFileSync('bash', ['scripts/build.sh'], { cwd: root, env: { ...process.env, OUT, VERSION: '1.0.0', BUILD_DATE: '2026-10-23' } });
|
||||
execFileSync(process.execPath, ['scripts/build.js'], { cwd: root, env: { ...process.env, OUT, VERSION: '1.0.0', BUILD_DATE: '2026-10-23' } });
|
||||
const v = JSON.parse(fs.readFileSync(path.join(OUT, 'version.json'), 'utf8'));
|
||||
assert.equal(v.version, '1.0.0');
|
||||
assert.ok(v.notes.length >= 5);
|
||||
|
|
@ -27,7 +27,7 @@ test('version.json carries the release notes from the changelog', () => {
|
|||
});
|
||||
|
||||
test('head carries the SEO and social metadata', () => {
|
||||
const html = fs.readFileSync(path.join(root, 'site', 'index.html'), 'utf8');
|
||||
const html = require('../scripts/lib/page').assemble().html;
|
||||
for (const needle of ['<link rel="canonical" href="https://seriesoftub.es/">', 'property="og:image"', 'name="twitter:card"', 'application/ld+json', 'rel="manifest"', 'name="description"']) {
|
||||
assert.ok(html.includes(needle), `missing ${needle}`);
|
||||
}
|
||||
|
|
@ -37,6 +37,6 @@ test('head carries the SEO and social metadata', () => {
|
|||
});
|
||||
|
||||
test('a release build refuses to ship without release notes', () => {
|
||||
assert.throws(() => execFileSync('bash', ['scripts/build.sh'], { cwd: root, stdio: 'pipe', env: { ...process.env, OUT, VERSION: '9.9.9', REQUIRE_NOTES: '1' } }));
|
||||
assert.throws(() => execFileSync('bash', ['scripts/build.sh'], { cwd: root, stdio: 'pipe', env: { ...process.env, OUT, VERSION: '1.0; rm -rf /' } }), 'junk versions are rejected');
|
||||
assert.throws(() => execFileSync(process.execPath, ['scripts/build.js'], { cwd: root, stdio: 'pipe', env: { ...process.env, OUT, VERSION: '9.9.9', REQUIRE_NOTES: '1' } }));
|
||||
assert.throws(() => execFileSync(process.execPath, ['scripts/build.js'], { cwd: root, stdio: 'pipe', env: { ...process.env, OUT, VERSION: '1.0; rm -rf /' } }), 'junk versions are rejected');
|
||||
});
|
||||
|
|
|
|||
|
|
@ -1,12 +1,17 @@
|
|||
// Loads site/index.html in jsdom with the animation loop disabled, so tests can
|
||||
// drive the simulation directly through the game's globals (ACT, S, R, dayTick…).
|
||||
// Loads the game page in jsdom with the animation loop disabled, so tests can drive the simulation
|
||||
// directly through the game's globals (ACT, S, R, dayTick…). The page is assembled from src/ once per
|
||||
// test process (scripts/lib/page.js), so tests always run what is in src/, never a stale build.
|
||||
const fs = require('node:fs');
|
||||
const path = require('node:path');
|
||||
const { JSDOM, VirtualConsole } = require('jsdom');
|
||||
const { assemble } = require('../scripts/lib/page');
|
||||
|
||||
let PAGE = null;
|
||||
const page = () => PAGE || (PAGE = assemble().html);
|
||||
|
||||
// opts.file: a built or older page to load instead (the perf bench, the release build test).
|
||||
function load(opts = {}) {
|
||||
const file = opts.file || path.join(__dirname, '..', 'site', 'index.html');
|
||||
const html = fs.readFileSync(file, 'utf8');
|
||||
const html = opts.file ? fs.readFileSync(opts.file, 'utf8') : page();
|
||||
const errors = [];
|
||||
const vc = new VirtualConsole();
|
||||
vc.on('jsdomError', (e) => {
|
||||
|
|
|
|||
|
|
@ -25,7 +25,7 @@ test('perf bench: runs end to end on a small save and compares a version with it
|
|||
const save = path.join(dir, 'save.json'), js = path.join(dir, 'out.json');
|
||||
fs.writeFileSync(save, JSON.stringify({ app: 'series-of-tubes', version: 'test', S: JSON.parse(ev('JSON.stringify(S)')) }));
|
||||
const md = execFileSync(process.execPath, [path.join(__dirname, '..', 'scripts', 'perf-bench.js'), '--save', save,
|
||||
'--base', path.join(__dirname, '..', 'site', 'index.html'), '--runs', '3', '--json', js], { encoding: 'utf8' });
|
||||
'--base', require('../scripts/lib/page').pageFile(path.join(dir, 'base.html')), '--runs', '3', '--json', js], { encoding: 'utf8' });
|
||||
assert.match(md, /2 POPs/, 'reads an exported save');
|
||||
assert.match(md, /Routing results are identical to the base/);
|
||||
assert.match(md, /\| Routing: compute\(\) \|/);
|
||||
|
|
|
|||
|
|
@ -32,7 +32,7 @@ test('leaving the page saves the game', () => {
|
|||
|
||||
test('returning players see what is new after an update, once', () => {
|
||||
const { saved } = playedGame();
|
||||
execFileSync('bash', ['scripts/build.sh'], { cwd: root, env: { ...process.env, OUT, VERSION: '1.1.0', BUILD_DATE: '2026-10-23' } });
|
||||
execFileSync(process.execPath, ['scripts/build.js'], { cwd: root, env: { ...process.env, OUT, VERSION: '1.1.0', BUILD_DATE: '2026-10-23' } });
|
||||
const file = path.join(OUT, 'index.html');
|
||||
const b = load({ file, storage: { 'sot-save-v1': saved, 'sot-seen-version': '1.0.0' } });
|
||||
const text = b.ev("document.getElementById('modalCard').textContent");
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue