Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(paralell): enable parallel tests generating an unique database name per test file, fix #206 #209

Merged
merged 2 commits into from
Jul 9, 2020
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
feat(config): handle dbName and random dbName
sibelius committed Jun 9, 2020
commit 41091f14c7bff1e66663c8e1dcbe628d9d28fbf5
2 changes: 1 addition & 1 deletion environment.js
Original file line number Diff line number Diff line change
@@ -20,7 +20,7 @@ module.exports = class MongoEnvironment extends NodeEnvironment {
const globalConfig = JSON.parse(fs.readFileSync(globalConfigPath, 'utf-8'));

this.global.__MONGO_URI__ = globalConfig.mongoUri;
this.global.__MONGO_DB_NAME__ = uuid.v4();
this.global.__MONGO_DB_NAME__ = globalConfig.mongoDBName || uuid.v4();

await super.setup();
}
3 changes: 0 additions & 3 deletions jest-mongodb-config.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
module.exports = {
mongodbMemoryServerOptions: {
instance: {
dbName: 'jest'
},
binary: {
skipMD5: true
},
5 changes: 2 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -41,9 +41,7 @@
"preset": "./jest-preset.js"
},
"dependencies": {
"cwd": "0.10.0",
"debug": "4.1.1",
"mongodb-memory-server": "6.6.1",
"uuid": "8.1.0"
},
"devDependencies": {
@@ -57,7 +55,8 @@
"prettier": "2.0.5"
},
"peerDependencies": {
"mongodb": "3.x.x"
"mongodb": "3.x.x",
"mongodb-memory-server": "*"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What was the reason of moving this out to peerDependencies? I'm ok with that as long as there is a reason and this is documented in READMe.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

so we can use any version of mongodb-memory-server

},
"engines": {
"node": ">=8"
14 changes: 14 additions & 0 deletions readme.md
Original file line number Diff line number Diff line change
@@ -26,6 +26,20 @@ If you have a custom `jest.config.js` make sure you remove `testEnvironment` pro

See [mongodb-memory-server](https://github.com/nodkz/mongodb-memory-server#available-options)

```js
module.exports = {
mongodbMemoryServerOptions: {
binary: {
version: '4.0.3',
skipMD5: true
},
autoStart: false
}
};
```

To use the same database for all tests pass the config like this:

```js
module.exports = {
mongodbMemoryServerOptions: {
8 changes: 4 additions & 4 deletions setup.js
Original file line number Diff line number Diff line change
@@ -13,8 +13,11 @@ module.exports = async () => {
await mongod.start();
}

const options = getMongodbMemoryOptions();

const mongoConfig = {
mongoUri: await mongod.getConnectionString()
mongoUri: await mongod.getConnectionString(),
mongoDBName: options.instance.dbName
};

// Write global config to disk because all tests run in different contexts.
@@ -33,9 +36,6 @@ function getMongodbMemoryOptions() {
return mongodbMemoryServerOptions;
} catch (e) {
return {
instance: {
dbName: 'jest'
},
binary: {
skipMD5: true
},