test: remove dynamic level parser execution
This commit is contained in:
+9
-3
@@ -22,9 +22,15 @@ await writeFile(scriptPath, script);
|
||||
const syntax = spawnSync(process.execPath, ['--check', scriptPath], { encoding: 'utf8' });
|
||||
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/);
|
||||
assert.ok(levelsMatch, 'could not extract level definitions');
|
||||
const levels = Function(`"use strict"; return (${levelsMatch[1]});`)();
|
||||
const levelsBlockMatch = script.match(/const LEVELS = Object\.freeze\(\[([\s\S]*?)\]\);\s*\n\s*const state/);
|
||||
assert.ok(levelsBlockMatch, 'could not extract level definitions');
|
||||
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');
|
||||
|
||||
for (const [index, level] of levels.entries()) {
|
||||
|
||||
Reference in New Issue
Block a user