TypeScript-Node-Starter
TypeScript-Node-Starter copied to clipboard
[Feature request] Add unit / local test suite that uses in-memory MongoDB
I think currently all tests depend on an actual MongoDB instance to run - this is great for end-to-end tests which make sure everything is fine.
However I wonder if we could also add a local test suite which would test the app in a similar way but connecting to an in-memory mongoDB instead. (e.g. this mongodb-memory-server seems to be quite promising according to the official instructions in Jest)
The pros are:
- in our tests we would not have to worry about the DB external dependency
- we do not have to maintain the database state manually as the data will be gone once the in memory db is torn down
- the projects and the tests become more standalone
The cons are (maybe):
- the test setup is exactly the same as in Production
- the tests would depend on the in-memory DB library
Or please let me know if there is any reason I had missed. :-) And thanks so much for the great work of this starter repo. 👍
For example, I had created a toy project that is bootstrapped with this repo and I followed the jest instruction so that the tests would use in-memory DB instead unless the process.env.USE_REAL_DB_IN_TESTS is set to a truthy value,
And here is the jest config used
TL;DR: please see the title :-)