test: remove dynamic level parser execution

This commit is contained in:
2026-07-27 17:16:19 +08:00
parent 5105464a1f
commit 513241b7d4
+9 -3
View File
@@ -22,9 +22,15 @@ await writeFile(scriptPath, script);
const syntax = spawnSync(process.execPath, ['--check', scriptPath], { encoding: 'utf8' }); const syntax = spawnSync(process.execPath, ['--check', scriptPath], { encoding: 'utf8' });
assert.equal(syntax.status, 0, `browser script has syntax errors:\n${syntax.stderr}`); assert.equal(syntax.status, 0, `browser script has syntax errors:\n${syntax.stderr}`);
const levelsMatch = script.match(/const LEVELS = Object\.freeze\((\[[\s\S]*?\])\);\s*\n\s*const state/); const levelsBlockMatch = script.match(/const LEVELS = Object\.freeze\(\[([\s\S]*?)\]\);\s*\n\s*const state/);
assert.ok(levelsMatch, 'could not extract level definitions'); assert.ok(levelsBlockMatch, 'could not extract level definitions');
const levels = Function(`"use strict"; return (${levelsMatch[1]});`)(); const levels = [...levelsBlockMatch[1].matchAll(/id:\s*'([^']+)'[\s\S]*?name:\s*'([^']+)'[\s\S]*?title:\s*'([^']+)'[\s\S]*?map:\s*\[([\s\S]*?)\n\s*\]/g)].map((match) => ({
id: match[1],
name: match[2],
title: match[3],
map: [...match[4].matchAll(/'([^']*)'/g)].map((row) => row[1])
}));
assert.equal(levels.length, 4, 'could not extract all level definitions');
assert.equal(levels.length, 4, 'the game must contain four experiments'); assert.equal(levels.length, 4, 'the game must contain four experiments');
for (const [index, level] of levels.entries()) { for (const [index, level] of levels.entries()) {