Files
Fishing/tools/run-tests.js
T
2026-11-11 15:53:07 +03:00

29 lines
1.6 KiB
JavaScript
Raw Blame History

This file contains invisible Unicode characters
This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
// Тесты экономики в открытом Studio (Rojo подключён): node tools/run-tests.js [имя]
// Каждый tests/*.spec.lua выполняется в Edit-режиме через Studio MCP вместе с tests/lib.lua.
// Код плейса не меняется: модули клонируются во временную папку ServerStorage и удаляются после прогона.
const { execFileSync } = require('child_process');
const fs = require('fs');
const path = require('path');
const root = path.resolve(__dirname, '..');
const tests = path.join(root, 'tests');
const only = process.argv[2];
const lib = fs.readFileSync(path.join(tests, 'lib.lua'), 'utf8').replace(/^/, '');
const specs = fs.readdirSync(tests).filter(f => f.endsWith('.spec.lua') && (!only || f.includes(only)));
const outDir = path.join(tests, '.out');
fs.mkdirSync(outDir, { recursive: true });
const steps = specs.map(f => ({
tool: 'execute_luau',
args: {
datamodel_type: 'Edit',
code: 'local T = (function()\n' + lib + '\nend)()\n' + fs.readFileSync(path.join(tests, f), 'utf8').replace(/^/, ''),
},
}));
const stepsFile = path.join(outDir, 'steps.json');
fs.writeFileSync(stepsFile, JSON.stringify(steps));
const out = execFileSync('node', [path.join(__dirname, 'mcp', 'run.js'), stepsFile], { maxBuffer: 1 << 26 }).toString('utf8');
process.stdout.write(out + '\n');
const failed = [...out.matchAll(/(\d+) passed, (\d+) failed/g)];
const bad = failed.length < specs.length || failed.some(m => m[2] !== '0') || /\(ERROR\)/.test(out);
console.log(bad ? 'TESTS FAILED' : `ALL ${specs.length} SUITES PASSED`);
process.exit(bad ? 1 : 0);