如何重置回送内存数据库

我通过mocha运行几个环回testing(让我们称之为test1.jstest2.jstest3.js )。

当我独立运行一切运作良好。 但是,当我要求mocha运行它们时,内存数据库中的第一个testing中创build的内容与稍后进行的testing(testing2或3)相冲突。

有没有办法确保我们开始每个testing与空数据库? 就像是:

 app.dataSources.db.reset() 

非常感谢!

更新:我做了什么:我看了DataSource代码,发现你可以在内存数据库上进行automigrate

 before("wipe DB (if used with other tests)", function(done) { app.dataSources.db.automigrate(function(err) { done(err); }); }); 

通过app.dataSources.db获取db ,并执行app.dataSources.db ,如下所示:

 before("wipe DB (if used with other tests)", function(done) { app.dataSources.db.automigrate(function(err) { done(err); }); }); 

干杯。

通常你应该在每次testing后清理。

你可以使用hook ,像afterEach