@shelf/jest-mongodb
Advanced tools
Comparing version 1.2.5 to 1.3.0
module.exports = { | ||
mongodbMemoryServerOptions: { | ||
binary: { | ||
skipMD5: true | ||
skipMD5: true, | ||
}, | ||
autoStart: false, | ||
instance: {} | ||
} | ||
instance: {}, | ||
}, | ||
mongoURLEnvName: 'MONGO_URL', | ||
}; |
@@ -6,3 +6,3 @@ const {resolve} = require('path'); | ||
globalTeardown: resolve(__dirname, './teardown.js'), | ||
testEnvironment: resolve(__dirname, './environment.js') | ||
testEnvironment: resolve(__dirname, './environment.js'), | ||
}; |
const {MongoClient} = require('mongodb'); | ||
const {mongoURLEnvName} = require('./jest-mongodb-config'); | ||
describe('insert', () => { | ||
const uri = mongoURLEnvName ? process.env[mongoURLEnvName] : process.env.MONGO_URL; | ||
let connection; | ||
@@ -8,5 +10,5 @@ let db; | ||
beforeAll(async () => { | ||
connection = await MongoClient.connect(process.env.MONGO_URL, { | ||
connection = await MongoClient.connect(uri, { | ||
useNewUrlParser: true, | ||
useUnifiedTopology: true | ||
useUnifiedTopology: true, | ||
}); | ||
@@ -29,3 +31,3 @@ db = await connection.db(); | ||
{type: 'Image'}, | ||
{type: 'Document'} | ||
{type: 'Document'}, | ||
]); | ||
@@ -40,5 +42,5 @@ | ||
{_id: 'Image', count: 2}, | ||
{_id: 'Video', count: 1} | ||
{_id: 'Video', count: 1}, | ||
]); | ||
}); | ||
}); |
const {MongoClient} = require('mongodb'); | ||
const {mongoURLEnvName} = require('./jest-mongodb-config'); | ||
describe('insert', () => { | ||
const uri = mongoURLEnvName ? process.env[mongoURLEnvName] : process.env.MONGO_URL; | ||
let connection; | ||
@@ -8,5 +10,5 @@ let db; | ||
beforeAll(async () => { | ||
connection = await MongoClient.connect(process.env.MONGO_URL, { | ||
connection = await MongoClient.connect(uri, { | ||
useNewUrlParser: true, | ||
useUnifiedTopology: true | ||
useUnifiedTopology: true, | ||
}); | ||
@@ -42,5 +44,5 @@ db = await connection.db(); | ||
expect.objectContaining({name: 'Alice'}), | ||
expect.objectContaining({name: 'Bob'}) | ||
expect.objectContaining({name: 'Bob'}), | ||
]); | ||
}); | ||
}); |
{ | ||
"name": "@shelf/jest-mongodb", | ||
"version": "1.2.5", | ||
"version": "1.3.0", | ||
"private": false, | ||
@@ -45,15 +45,15 @@ "description": "Run your tests using Jest & MongoDB in Memory server", | ||
"dependencies": { | ||
"debug": "4.1.1", | ||
"mongodb-memory-server": "6.9.6", | ||
"debug": "4.3.2", | ||
"mongodb-memory-server": "7.0.0", | ||
"uuid": "8.3.2" | ||
}, | ||
"devDependencies": { | ||
"@shelf/eslint-config": "0.27.1", | ||
"@shelf/prettier-config": "0.0.7", | ||
"eslint": "7.24.0", | ||
"@shelf/eslint-config": "1.5.0", | ||
"@shelf/prettier-config": "1.0.0", | ||
"eslint": "7.30.0", | ||
"husky": "4.3.8", | ||
"jest": "26.4.2", | ||
"lint-staged": "10.2.13", | ||
"mongodb": "3.6.2", | ||
"prettier": "2.3.0" | ||
"jest": "27.0.6", | ||
"lint-staged": "11.0.0", | ||
"mongodb": "3.6.9", | ||
"prettier": "2.3.2" | ||
}, | ||
@@ -60,0 +60,0 @@ "peerDependencies": { |
@@ -59,3 +59,3 @@ # jest-mongodb [![CircleCI](https://circleci.com/gh/shelfio/jest-mongodb/tree/master.svg?style=svg)](https://circleci.com/gh/shelfio/jest-mongodb/tree/master) ![](https://img.shields.io/badge/code_style-prettier-ff69b4.svg) [![npm (scoped)](https://img.shields.io/npm/v/@shelf/jest-mongodb.svg)](https://www.npmjs.com/package/@shelf/jest-mongodb) | ||
To use dynamic database name you must pass empty object for instance field | ||
To use dynamic database name you must pass empty object for instance field: | ||
@@ -75,2 +75,18 @@ ```js | ||
To use another uri environment variable name you must set mongoURLEnvName field: | ||
```js | ||
module.exports = { | ||
mongodbMemoryServerOptions: { | ||
binary: { | ||
version: '4.0.3', | ||
skipMD5: true | ||
}, | ||
instance: {}, | ||
autoStart: false | ||
}, | ||
mongoURLEnvName: 'MONGODB_URI' | ||
}; | ||
``` | ||
### 3. Configure MongoDB client | ||
@@ -77,0 +93,0 @@ |
19
setup.js
@@ -17,6 +17,7 @@ const fs = require('fs'); | ||
const options = getMongodbMemoryOptions(); | ||
const mongoURLEnvName = getMongoURLEnvName(); | ||
const mongoConfig = { | ||
mongoUri: await mongod.getUri(), | ||
mongoDBName: options.instance.dbName | ||
mongoDBName: options.instance.dbName, | ||
}; | ||
@@ -30,3 +31,3 @@ | ||
global.__MONGOD__ = mongod; | ||
process.env.MONGO_URL = mongoConfig.mongoUri; | ||
process.env[mongoURLEnvName] = mongoConfig.mongoUri; | ||
}; | ||
@@ -42,8 +43,18 @@ | ||
binary: { | ||
skipMD5: true | ||
skipMD5: true, | ||
}, | ||
autoStart: false, | ||
instance: {} | ||
instance: {}, | ||
}; | ||
} | ||
} | ||
function getMongoURLEnvName() { | ||
try { | ||
const {mongoURLEnvName} = require(resolve(cwd, 'jest-mongodb-config.js')); | ||
return mongoURLEnvName || 'MONGO_URL'; | ||
} catch (e) { | ||
return 'MONGO_URL'; | ||
} | ||
} |
Sorry, the diff of this file is not supported yet
Environment variable access
Supply chain riskPackage accesses environment variables, which may be a sign of credential stuffing or data theft.
Found 1 instance in 1 package
Environment variable access
Supply chain riskPackage accesses environment variables, which may be a sign of credential stuffing or data theft.
Found 1 instance in 1 package
12486
168
173
10
+ Addedasync-mutex@0.3.2(transitive)
+ Addeddebug@4.3.2(transitive)
+ Addedmongodb-memory-server@7.0.0(transitive)
+ Addedmongodb-memory-server-core@7.0.0(transitive)
+ Addedtslib@2.6.3(transitive)
- Removedcross-spawn@7.0.3(transitive)
- Removeddebug@4.1.14.3.5(transitive)
- Removedisexe@2.0.0(transitive)
- Removedlockfile@1.0.4(transitive)
- Removedmongodb-memory-server@6.9.6(transitive)
- Removedmongodb-memory-server-core@6.9.6(transitive)
- Removedms@2.1.3(transitive)
- Removedpath-key@3.1.1(transitive)
- Removedshebang-command@2.0.0(transitive)
- Removedshebang-regex@3.0.0(transitive)
- Removedsignal-exit@3.0.7(transitive)
- Removedwhich@2.0.2(transitive)
Updateddebug@4.3.2
Updatedmongodb-memory-server@7.0.0