node.js - 使用 --config 设置 Mocha 的路径

标签 node.js shell path mocha.js nodemon

Mocha 找不到具有配置的 .mocharc.js 文件的路径。

文件位于:app/test/.mocharc.js

我尝试设置相对路径和完整路径,但它总是抛出错误。使用引号、双引号、转义引号...我仍然遇到同样的错误。

在 package.json 中:

"scripts":{
    test": "nodemon --exec \"mocha --config \"./test/.mocharc.js\""
},

命令行错误日志:

throw new Error(`failed to parse ${filepath}: ${err}`);
^
Error: failed to parse ./test/.mocharc.js: Error: Cannot find module './test/.mocharc.js'

最佳答案

您的test脚本命令的格式不正确(不必要的双引号)。

"scripts":{
    test": "nodemon --exec \"mocha --config ./test/.mocharc.js\""
},

您想运行mocha --config ./test/.mocharc.js .

并将其包装到 nodemon 中,你会:

nodemon --exec \"<command here>\"

替换<command here>像这样用你的命令。

nodemon --exec \"mocha --config ./test/.mocharc.js\"

关于node.js - 使用 --config 设置 Mocha 的路径,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55638809/

相关文章:

emacs - PATH Mac OSX 终端中的脚本不起作用

android - 为什么我们应该使用 XMPP 而不是 JSON 作为简单的(纯文本)消息传递应用程序?

node.js - --killSignal 标志是否已永久删除?

bash - 脚本 shell 如何将 x 分钟减少到给定日期?

macos - 如何使用 mac os x leopard 将目录添加到 $PATH 变量

path - 如何在Qt Creator中添加包含路径?

javascript - 两个 Array.map 内的异步请求

node.js - http statusCode 有时未定义

bash - 在 shell 中实现通配符扩展

linux - 如何遍历给定目录的所有子目录?