在运行之前,我需要检查是否安装了"mocha".我想出了以下代码:
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);
}
Run Code Online (Sandbox Code Playgroud)
我不喜欢捕捉异常的想法.有没有更好的办法?