shelfio / jest-mongodb

Jest preset for MongoDB in-memory server
MIT License
587 stars 83 forks source link

update to use config file location for finding jest mongodb config #436

Closed ajwootto closed 8 months ago

ajwootto commented 10 months ago

For the same usecase as specified in my other PR: https://github.com/shelfio/jest-mongodb/pull/389

In our monorepo there's currently a problem where executing tests from the root directory via Nx means that the preset does not look in the correct (project directory) location for the jest-mongodb-config.js file.

This updates the helpers that determine that file's location to get the cwd from Jest's globalConfig rather than reading it from process.cwd(). Since it needs to Jest config to do this, I moved the instantiation of the MongoMemoryServer class to be inside the environment class's constructor.

I also added a devDependency on jest-environment-node because Typescript was complaining about not having type definitions for it (since its listed as a peerDependency)