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/