Fed*_* E. 19 mocha.js node.js chai
我从Node中的测试开始。使用mocha,chai和nock(拦截外部HTTP api调用)。
我已经编写了3个测试,所有这些都通过了,但是,当我添加了第3个测试时,mocha在运行测试后停止退出,没有错误或任何错误的迹象。
如果我对第三项测试发表评论,那么摩卡咖啡就可以退出。
这是导致“问题”的测试:
describe('tokenizer.processFile(req, \'tokenize\')', () => {
it('should tokenize a file', async () => {
req = {
file: {
originalname: 'randomcards.txt',
buffer: cardsFile_buffer
},
user: {
displayName: user
}
};
expect(Buffer.from(await tokenizer.processFile(req, 'tokenize'))).to.deep.equal(tokensFile_buffer);
});
});
Run Code Online (Sandbox Code Playgroud)
再次,那个测试是通过,这使我感到困惑。
这是tokenizer.processFile的代码:
processFile: function(req, whatTo){
combinedLogger.info(`Request to ${whatTo} ${req.file.originalname} received. Made by: ${req.user.displayName}`);
return new Promise(function(resolve, reject){
const lines = [], responses = [];
const lineReader = require('readline').createInterface({
input: require('streamifier').createReadStream(req.file.buffer)
});
lineReader.on('line', line => {
lines.push(line);
});
lineReader.on('close', async () => {
//process every line sequentially
try {
//ensure DB connected to mass insert
await db_instance.get_pool();
for(const line of lines) {
var response;
req.current_value = line;
if (whatTo == 'tokenize'){
response = await Tokenize(line);
db_instance.insertAction(req, 'tokenize', response);
}
else if (whatTo == 'detokenize'){
combinedLogger.info(`Request to detokenize ${line} received. Made by: ${req.user.displayName}`);
response = await Detokenize(line);
db_instance.insertAction(req, 'detokenize', line);
}
responses.push(response);
}
resolve(responses.join("\r\n"));
}
catch(error){
reject(error);
}
});
});
}
Run Code Online (Sandbox Code Playgroud)
在其他2个测试中还调用了Tokenize(value)和Detokenize(value)函数,在运行时,mocha退出就可以了。
知道是什么原因造成的吗?
摩卡版本:5.1.1
Ale*_*aut 38
我知道现在回答这个问题有点晚了,但是我遇到了类似的问题,看到了您的帖子。
在摩卡4.0.0,他们改变了对finalization.From测试的行为在这里:
如果在您的测试似乎“完成”之后,mocha进程仍然有效,则说明您的测试已安排了一些事情(异步),并且没有对其进行适当的清理。你没有打开插座吗?
在您的情况下,似乎createReadStream()
从未终止对的致电。
因此,您有2个选择:
选项A:关闭fs,并打开其他流(推荐)
选项B:使用该--exit
选项运行摩卡咖啡。
归档时间: |
|
查看次数: |
6445 次 |
最近记录: |