{"repo":"shelfio/jest-mongodb","free":true,"listed":false,"github":"https://github.com/shelfio/jest-mongodb","clone":"git clone https://github.com/shelfio/jest-mongodb.git","description":"Jest preset for MongoDB in-memory server","language":"TypeScript","stars":602,"topics":["mongodb","jest","nodejs","tests","jest-preset","jest-environment","npm-package"],"license":"MIT","category":"databases-storage","readme_excerpt":"jest-mongodb Jest preset to run MongoDB memory server Usage 0. Install Make sure mongodb is installed in the project as well, as it's required as a peer dependency. 1. Create jest.config.js If you have a custom jest.config.js make sure you remove testEnvironment property, otherwise it will conflict with the preset. 2. Create jest-mongodb-config.js See mongodb-memory-server To use the same database for all tests pass the config like this: To use separate database for each jest worker pass the useSharedDBForAllJestWorkers: false (doesn't create process.env variable when using this option): To use dynamic database name you must pass empty object for instance field: To use another uri environment variable name you must set mongoURLEnvName field: To use mongo as a replica set you must add the replSet config object and set count and storageEngine fields: 3. Configure MongoDB client Library sets the process.env.MONGO URL for your convenience, but using of global. MONGO URI is preferable as it works with useSharedDBForAllJestWorkers: false 4. PROFIT! Write tests Cache MongoDB binary in CI by putting this folder to the list of cached paths: ./node modules/.cache/mongodb-memory-server/mongodb-binaries You can enable debug logs by setting environment variable DEBUG=jest-mongodb: 5. Clean collections before each test (optional) See this issue for discussion 6. Jest watch mode gotcha This package creates the file globalConfig.json in the project root, when using jest --watch flag, changes","default_branch":null,"files":null,"tree":[],"storefront":"/r/shelfio","claimed":false,"request_supported":{"post":"https://gitbuyer.com/r/shelfio/jest-mongodb/request-supported","requests":0},"note":"indexed from public GitHub; nothing is for sale on this page. Clone it from GitHub. Paid listings live at /search."}