diff --git a/.xo-config.js b/.xo-config.js index f35c15b..de8fa08 100644 --- a/.xo-config.js +++ b/.xo-config.js @@ -1,5 +1,8 @@ module.exports = { prettier: true, space: true, - extends: ['xo-lass'] + extends: ['xo-lass'], + rules: { + 'import/order': 'off' + } }; diff --git a/index.js b/index.js index cb80cb9..8973665 100644 --- a/index.js +++ b/index.js @@ -1,5 +1,4 @@ const process = require('node:process'); - const mergeOptions = require('merge-options'); const mongoose = require('mongoose'); const { boolean } = require('boolean'); @@ -23,14 +22,15 @@ class Mongoose { bindEvents: true, mongo: { options: { - serverSelectionTimeoutMS: 30000, // default is 30s - heartbeatFrequencyMS: 10000 // default is 10s + serverSelectionTimeoutMS: + process.env.NODE_ENV === 'test' ? 9000 : 30000, // default is 30s + heartbeatFrequencyMS: process.env.NODE_ENV === 'test' ? 3000 : 10000 // default is 10s } }, debug: boolean(process.env.MONGOOSE_DEBUG), strict: true, strictQuery: false, - maxTimeMS: 30000 // default 30s timeout for a query to complete + maxTimeMS: process.env.NODE_ENV === 'test' ? 10000 : 30000 // default 30s timeout for a query to complete }, config ); @@ -69,7 +69,7 @@ class Mongoose { ]; for (const prop of options) { - if (typeof this.config[prop] !== 'undefined') + if (this.config[prop] !== undefined) mongoose.set(prop, this.config[prop]); } diff --git a/package.json b/package.json index d833fc7..c9cfa4a 100644 --- a/package.json +++ b/package.json @@ -21,22 +21,22 @@ "merge-options": "^3.0.4" }, "devDependencies": { - "@commitlint/cli": "^17.4.2", - "@commitlint/config-conventional": "^17.4.2", - "ava": "^5.1.1", + "@commitlint/cli": "^19.3.0", + "@commitlint/config-conventional": "^19.2.2", + "ava": "5", "cross-env": "^7.0.3", - "delay": "^5.0.0", + "delay": "5.0.0", "eslint-config-xo-lass": "^2.0.1", "fixpack": "^4.0.0", - "husky": "^8.0.3", - "lint-staged": "^13.1.0", - "mongodb-memory-server": "^8.11.4", + "husky": "^9.0.11", + "lint-staged": "^15.2.7", + "mongodb-memory-server": "^9.4.0", "mongoose": "^6.9.0", - "nyc": "^15.1.0", - "remark-cli": "^11.0.0", + "nyc": "^17.0.0", + "remark-cli": "11.0.0", "remark-preset-github": "^4.0.4", "signale": "^1.4.0", - "xo": "^0.53.1" + "xo": "^0.58.0" }, "engines": { "node": ">=14" diff --git a/test/test.js b/test/test.js index 3552a6c..b30db4e 100644 --- a/test/test.js +++ b/test/test.js @@ -70,7 +70,7 @@ test('creates, stops, and retries connection with mongodb-memory-server', async if (process.platform === 'darwin') { test('reconnects with mongodb', async (t) => { t.timeout(Number.MAX_VALUE); - await exec('brew services start mongodb-community@4.4'); + await exec('brew services start mongodb-community'); await delay(3000); const m = new Mongoose({ logger, @@ -83,12 +83,12 @@ if (process.platform === 'darwin') { await delay(1000); t.is(conn.readyState, 1); const MyModel = conn.model('Test', new Schema({ name: String })); - await exec('brew services stop mongodb-community@4.4'); + await exec('brew services stop mongodb-community'); await delay(1000); t.is(conn.readyState, 0); const err = await t.throwsAsync(() => MyModel.findOne()); t.is(err.name, 'MongooseServerSelectionError'); - await exec('brew services start mongodb-community@4.4'); + await exec('brew services start mongodb-community'); await delay(5000); await t.notThrowsAsync(() => MyModel.findOne()); t.is(conn.readyState, 1);