jest-mongodb icon indicating copy to clipboard operation
jest-mongodb copied to clipboard

Improvements Suggestions

Open timofei-iatsenko opened this issue 1 year ago • 0 comments

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":

  1. Passing env parameters from Environment. Currently in jest-mongodb when 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;
  1. 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.

timofei-iatsenko avatar Jan 12 '24 09:01 timofei-iatsenko