如何重置环回内存 DB

How to reset the loopback memory DB

我正在 运行通过 mocha 进行几个环回测试(我们称它们为 test1.jstest2.jstest3.js)。

当我 运行 独立时一切正常。但是,当我要求 mocha 到 运行 全部时,内存数据库中第一个测试中创建的内容与稍后进行的测试(测试 2 或 3)发生冲突。

有没有办法确保我们从空数据库开始每个测试?类似于:

app.dataSources.db.reset()

非常感谢!

更新:我最后做了什么:我查看了 DataSource 代码,发现您可以在内存数据库上执行 automigrate

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

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

你可以使用hooks,比如afterEach

通过 app.dataSources.db 获取 db 并执行 automigrate 如下:

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

干杯。