【发布时间】:2020-01-11 17:44:59
【问题描述】:
我有一些 mocha 测试在连接到 Wifi 时完成且没有错误。我正在使用命令运行测试:
./node_modules/.bin/mocha --recursive -R spec path/to/bootstrap.integration.js path/to/testfile.test.js
当我关闭 Wifi 连接时,相同的测试在之前的引导程序中失败并出现此错误:
Uncaught Error: ENOENT: no such file or directory, open '/etc/resolv.conf'
我实际上是通过 vpn 连接到互联网,当 vpn 断开连接但 wifi 仍然打开并连接时,测试全部通过。防火墙只允许通过 vpn 的出站连接。
在调试器中单步执行代码,在我清除数据库(mongodb)后立即抛出错误。
之前在引导文件中调用的相关代码:
function emptyCollection(collectionName, callback) {
debug(`emptying collection: ${collectionName}`);
models[collectionName].deleteMany({}, function(err, result) {
if (err) { // <--- Never reached when Wifi is disconnected
return callback(err);
}
debug(`emptied collection: ${collectionName}`);
return callback(null, result);
});
}
debug('emptying all collections...');
async.map(Object.keys(models), emptyCollection, function(err, results) {
if (err) { // <--- Never reached when Wifi is disconnected
return cb(err);
}
debug('emptied all collections');
return cb();
});
当 Wifi 断开连接时,从未达到任何 deleteMany 回调。也永远不会到达 async.map 回调。
我一直在尝试找到一种方法来在“/etc/resolv.conf”打开时设置断点,以便确定代码的哪一部分正在尝试读取文件,但我没有找到一种方法。
我已经看了好几个小时了,我完全没有想法。
是否有任何机构有任何故障排除建议?
[更新:我正在寻找针对上述问题的故障排除建议]
【问题讨论】:
标签: node.js mongodb debugging mocha.js