I'm using Node and the node-postgres package and I would like to perform some unit tests using jest and supertest without saving to the actual database.
When using sequelize it is possible to configure the storage in memory, like so:
const sequelize = new Sequelize({
...
storage: ":memory:"
});
I know it is possible to set the dialect to Postgres in sequelize, but I was wondering how would one go about to set the in memory storage using node-postgres. Is that possible?
Thanks
2条答案
按热度按时间7y4bm7vi1#
我认为在sequelize中,“:memory:“存储只能用于sqlite,就像内存数据库一样。在内存中运行postgresql是不可能的,所以你不能从node-postgres/任何客户端连接到内存中的postgres。
您可以参考此答案以了解更多详细信息(Using in-memory PostgreSQL)
mnemlml82#
for my approach I'm using docker-container with clear postgres server, which is getting up before all the tests.
then I run all migrations and seeds, then I run all the tests, then I kill that container. All that stuff is done automatically.
But I'm using it in mocha/chai, and using globalSetup and globalTeardown hooks for that. Don't know if it is possible in Jest