我有一个文件来处理验证码,在captcha.js中有一个变量module.exports.taskCaptchas = [] 在consortium.js中,我有const captcha = require(“ ./ captcha.js”) 当我尝试使用captcha.taskCaptcha [0]检索consortium.js中的值时,它返回未定义的值,但我已经确认其中存在一个值。我在做什么错了?
Captcha.js
module.exports.taskCaptchas = [];
ipcMain.on("updateCaptchaQueue", (event, token) => {
global.captchaQueue.shift();
console.log('New captcha token received. Captcha token: ' + token)
console.log("Sending to task")
module.exports.taskCaptchas.push(token)
console.log(module.exports.taskCaptchas[0])
console.log(module.exports.taskCaptchas[0] == token)
if (global.captchaQueue.length >= 1) {
module.exports.requestCaptcha(global.captchaQueue[0], false)
} else {
module.exports.capWin.hide();
}
});
Consortium.js
const captcha = require('./captcha.js')
function solveCap(productID, formKey, attributeID){
ipcRenderer.send("captcha","Consortium")
const capHandler = () => {
console.log(captcha.taskCaptchas[0])
if (captcha.taskCaptchas[0] == undefined || captcha.taskCaptchas[0] == '') {
setTimeout(() => capHandler(), 1000);
}else{
var response = captcha.taskCaptchas[0];
setTimeout(atc, delayTime, productID, formKey, attributeID, response);
return;
}
}
capHandler();
}
答案 0 :(得分:-1)
我尝试这样做是为了验证您的模块定义(基本上是相同的,但是没有功能):
expect(dbl1).to receive(:one)
expect(dbl2).to receive(:two)
expect(dbl3).to receive(:three)
verify(dbl1, dbl2, dbl3).during do
my_code
end
// taskcaptchas.js
const captchas = [];
setInterval(() => {
captchas.push("token");
}, 3000);
module.exports = { captchas };
这是输出:
我认为您需要在
//consortium.js
const taskCaptchas = require("./taskcaptchas.js");
setInterval(() => {
console.log(taskCaptchas.captchas);
}, 1000);
上花更多时间,以便等到setTimeout(() => capHandler(), 1000);
事件填充taskCaptcha数组。让我们给它2或3秒钟。