Skip to content

Commit

Permalink
fix: fixed tests
Browse files Browse the repository at this point in the history
  • Loading branch information
titanism committed Jul 11, 2024
1 parent b5c426f commit ce71897
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 19 deletions.
5 changes: 4 additions & 1 deletion .xo-config.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
module.exports = {
prettier: true,
space: true,
extends: ['xo-lass']
extends: ['xo-lass'],
rules: {
'import/order': 'off'
}
};
10 changes: 5 additions & 5 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
const process = require('node:process');

const mergeOptions = require('merge-options');
const mongoose = require('mongoose');
const { boolean } = require('boolean');
Expand All @@ -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
);
Expand Down Expand Up @@ -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]);
}

Expand Down
20 changes: 10 additions & 10 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
6 changes: 3 additions & 3 deletions test/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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);
Expand Down

0 comments on commit ce71897

Please sign in to comment.