在运行之前,我需要判断是否安装了"摩卡".我想出了以下代码:
try {
var mocha = require("mocha");
} catch(e) {
console.error(e.message);
console.error("Mocha is probably not found. Try running `npm install mocha`.");
process.exit(e.code);
}
我不喜欢抓住例外的 idea .有更好的办法吗?