jest-mongodb
jest-mongodb copied to clipboard
Improvements Suggestions
Hi there!
I'm working on similar library jest-firestore wich as based on this one.
While working on that library I found few things which might didn't work previously, but they are possible in current jest versions and could be used to greatly simplify "jest-mongodb":
- Passing env parameters from Environment. Currently in
jest-mongodbwhen you use shared db for all tests it creates a "process.env.MONGO_URL" but when you separate db for each test it sets global.MONGO_URI. Probably that is because authors struggled with passing ENV variables to the tests from environment. But i tested on jest 29 and this works:
// environment.ts
this.global.process.env.MONGO_URI =uri;
- Passing variables from globalSetup to environment. I accidentally discovered that ENV variables created in the globalSetup passed to the environment as well. For "jest-mongodb" it means you can avoid "globalSetup.json" file and pass mongouri to the workers using ENV variables. I don't know in what exact version it was changed, but it works in the jest 29 and tested in jest-firestore package.
Thanks, hope this would be helpful for maintainers.