当我使用--watch模式时,为什么Mocha没有正确重启Express?

Chr*_*ris 5 mocha.js mongoose mongodb node.js supertest

我想在我的Express App的API路线上运行测试.我使用Mongoose和它的数据库操作架构.这是我的测试设置(它首先成功运行,但在重新加载时失败...):

const request = require('supertest');
// this loads the whole express app
const app = require('../../server');

describe('[Auth]', function () {
  it('returns 401 with invalid credentials', function (done) {
    request(app)
      .post('/auth/login')
      .field('email', 'invalidMail')
      .field('password', 'invalidPassword')
      .expect('Content-Type', contentType)
      .expect(401, done);
  }
}
Run Code Online (Sandbox Code Playgroud)

当我启动mocha时,此测试成功.我启动它,--watch mode每当我保存文件和摩卡重新启动测试我得到以下错误:

MongooseError: Cannot overwrite `user` model once compiled.
    at Mongoose.model (...\node_modules\mongoose\lib\index.js:376:13)
    ...
Run Code Online (Sandbox Code Playgroud)

我尝试的是连接和断开beforeafter钩子中的Mongoose,但这并没有改变任何东西.

在我看来,Mocha只是在不停止它的情况下重新加载我的应用程序.我在这里错过了什么?什么是最佳做法?