我正在开发一个 MANE(Node + Express + Mongo + Angular)应用程序。
在开发过程中,我目前使用这样的package.json
文件:
"scripts": {
"start": "nodemon ./bin/www",
"test": "mocha",
}
所以,当我开始开发时。我运行npm start
,并nodemon
开始观看我的资源,当有任何变化时重新启动快速服务器。
如果我想运行测试,我运行npm test
,然后 mocha 测试就完成了。
由于我还需要测试路线,我必须运行npm start
(在终端窗口中)然后npm test
(在第二个终端窗口中)。
到目前为止,一切都很好。
但是,如果我想对每个更改重新运行测试怎么办?
我确实尝试过这样的事情:
"scripts": {
"start": "npm run test && nodemon ./bin/www",
"test": "mocha",
}
但这不起作用,因为当测试完成时,nodemon 尚未启动,所以我收到此错误:
Uncaught AssertionError: expected [Error: connect ECONNREFUSED 127.0.0.1:3000] to deeply equal null
另一方面,我不能颠倒命令(nodemon ./bin/www && npm run test
)的顺序,因为 nodemod 正在阻塞......
任何线索如何解决这个“难题”?