TypeScript-Node-Starter icon indicating copy to clipboard operation
TypeScript-Node-Starter copied to clipboard

[Feature request] Add unit / local test suite that uses in-memory MongoDB

Open htbkoo opened this issue 6 years ago • 2 comments

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:

  1. in our tests we would not have to worry about the DB external dependency
  2. we do not have to maintain the database state manually as the data will be gone once the in memory db is torn down
  3. the projects and the tests become more standalone

The cons are (maybe):

  1. the test setup is exactly the same as in Production
  2. 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. 👍

htbkoo avatar Aug 11 '18 02:08 htbkoo

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

htbkoo avatar Aug 11 '18 02:08 htbkoo

TL;DR: please see the title :-)

htbkoo avatar Aug 11 '18 02:08 htbkoo