Node.js 为什么摩卡在我使用--watch模式时不能正确重启Express?

Node.js 为什么摩卡在我使用--watch模式时不能正确重启Express?,node.js,mongodb,mongoose,mocha.js,supertest,Node.js,Mongodb,Mongoose,Mocha.js,Supertest,我想在我的Express应用程序的API路由上运行测试。我使用Mongoose及其模式进行DB操作。这是我的测试设置(它首先成功运行,但在重新加载时失败…): 当我开始摩卡咖啡时,这个测试成功了。我在--监视模式下启动它,每当我保存一个文件并且mocha重新启动测试时,我都会得到以下错误: MongooseError: Cannot overwrite `user` model once compiled. at Mongoose.model (...\node_modules\mong

我想在我的Express应用程序的API路由上运行测试。我使用Mongoose及其模式进行DB操作。这是我的测试设置(它首先成功运行,但在重新加载时失败…):

当我开始摩卡咖啡时,这个测试成功了。我在
--监视模式下启动它,每当我保存一个文件并且mocha重新启动测试时,我都会得到以下错误:

MongooseError: Cannot overwrite `user` model once compiled.
    at Mongoose.model (...\node_modules\mongoose\lib\index.js:376:13)
    ...
我尝试的是在
before
after
钩子中连接和断开Mongoose,但这并没有改变任何事情


在我看来,摩卡只是在重新加载我的应用程序而没有先停止它。我错过了什么?最佳做法是什么?

我也想知道这一点。我可以按住ctrl-c键并重新启动,所有测试都通过。。但是如果我保存一个文件,它会抛出这个错误。那是很久以前的事了,我实际上没有找到答案。我通过不再使用摩卡咖啡解决了这个问题。它对Tape()和Jest()都非常有效,我在Hydra和TypeORM中也看到了类似的行为,它只是在不停止它们的情况下重新加载。
MongooseError: Cannot overwrite `user` model once compiled.
    at Mongoose.model (...\node_modules\mongoose\lib\index.js:376:13)
    ...