test child.js

This commit is contained in:
littlefairy 2024-03-19 13:08:20 +08:00
parent 9b388ec9ba
commit 3577bc56d7

View File

@ -77,6 +77,27 @@ const cqd_name_list = [
'Iwn<Zo@nan', 'Iwn<Zo@nan',
'U>7D3Ol7uWKIfTC@XJ联队' 'U>7D3Ol7uWKIfTC@XJ联队'
] ]
function createJSDOMForOpponent(opponent, name, mode, testString, config, localStorageMock, path, results) {
return new Promise((resolve) => {
new JSDOM(fs.readFileSync(path.join(__dirname, 'static/md5.html'), 'utf-8'), {
url: 'file://' + path.join(__dirname, 'static/'),
runScripts: 'dangerously',
resources: 'usable',
beforeParse(window) {
window.FakelocalStorage = localStorageMock;
window.config = config[mode].thresholds;
window.name_input = testString[mode].replace(/\$name1/g, name).replace(/\$name2/g, opponent);
window.stage = 0;
window.skillData = [];
window.resolve = (...args) => {
results.push(args[2]);
window.close();
resolve(); // 解决Promise表示当前JSDOM操作完成
}
}
});
});
}
console.log(chalk`{gray child {bold ${id}} started.}`); console.log(chalk`{gray child {bold ${id}} started.}`);
process.on('message', ([mode, name]) => { process.on('message', ([mode, name]) => {
@ -102,32 +123,16 @@ process.on('message', ([mode, name]) => {
}; };
} }
}); });
} else if (mode == "CQD") { }else if(mode == "CQD"){
var results = [] var results=[];
for (i = 0; i < cqd_name_list.length; i++) { (async () => {
var opponent = cqd_name_list[i] for (let i = 0; i < cqd_name_list.length; i++) {
new JSDOM(fs.readFileSync(path.join(__dirname, 'static/md5.html'), 'utf-8'), { var opponent = cqd_name_list[i];
url: 'file://' + path.join(__dirname, 'static/'), // 等待当前的JSDOM操作完成
runScripts: 'dangerously', await createJSDOMForOpponent(opponent, name, mode, testString, config, localStorageMock, path, results);
resources: 'usable', }
beforeParse(window) { })();
window.FakelocalStorage = localStorageMock;
window.config = config[mode].thresholds;
window.name_input = testString[mode].replace(/\$name1/g, name).replace(/\$name2/g, opponent);
window.stage = 0;
window.skillData = [];
window.resolve = (...args) => {
console.log(results)
results.push(args[2]);
window.close();
};
window.output = (...message) => {
console.log('page:', message);
};
}
});
}
console.log(results) console.log(results)
} }
} catch (e) { } catch (e) {