3

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 Answers 2

1

I think in sequelize that ":memory:" storage would be available only for sqlite like in memory databases. It isn't possible to run postgresql in memory so you can't connect to in memory postgres from node-postgres/any client.

You can refer this answer for more details (Using in-memory PostgreSQL)

Sign up to request clarification or add additional context in comments.

2 Comments

Thank you. Would it be considered a bad practice to create a local database , separated from the actual database, just to run tests?
That's the way to do it I think. You can have different test database for running tests.
0

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.