Skip to content

Commit 105cb8c

Browse files
authored
chore(deps) Bump mongoose test-version (#7003)
1 parent cbcd395 commit 105cb8c

File tree

5 files changed

+37
-17
lines changed

5 files changed

+37
-17
lines changed

packages/datadog-instrumentations/test/mongoose.spec.js

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,15 @@ describe('mongoose instrumentations', () => {
2525
let Test, dbName, id, mongoose
2626

2727
function connect () {
28-
mongoose.connect(`mongodb://localhost:27017/${dbName}`, {
29-
useNewUrlParser: true,
30-
useUnifiedTopology: true
31-
})
28+
const connectOptions = {}
29+
30+
// useNewUrlParser and useUnifiedTopology are not supported in mongoose >= 5
31+
if (semver.lt(specificVersion, '5.0.0')) {
32+
connectOptions.useNewUrlParser = true
33+
connectOptions.useUnifiedTopology = true
34+
}
35+
36+
mongoose.connect(`mongodb://localhost:27017/${dbName}`, connectOptions)
3237
}
3338

3439
before(() => {

packages/datadog-plugin-mongoose/test/index.spec.js

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -20,14 +20,20 @@ describe('Plugin', () => {
2020
// This needs to be called synchronously right before each test to make
2121
// sure a connection is not already established and the request is added
2222
// to the queue.
23-
function connect () {
23+
function connect (mongooseVersion) {
24+
const connectOptions = {
25+
bufferCommands: false
26+
}
27+
28+
// useNewUrlParser and useUnifiedTopology are not supported in mongoose >= 5
29+
if (semver.lt(mongooseVersion, '5.0.0')) {
30+
connectOptions.useNewUrlParser = true
31+
connectOptions.useUnifiedTopology = true
32+
}
33+
2434
// mongoose.connect('mongodb://username:password@host:port/database?options...');
2535
// actually the first part of the path is the dbName and not the collection
26-
return mongoose.connect(`mongodb://localhost:27017/${dbName}`, {
27-
bufferCommands: false,
28-
useNewUrlParser: true,
29-
useUnifiedTopology: true
30-
})
36+
return mongoose.connect(`mongodb://localhost:27017/${dbName}`, connectOptions)
3137
}
3238

3339
beforeEach(() => {
@@ -39,9 +45,11 @@ describe('Plugin', () => {
3945

4046
mongoose = require(`../../../versions/mongoose@${version}`).get()
4147

48+
const mongooseVersion = require(`../../../versions/mongoose@${version}`).version()
49+
4250
dbName = id().toString()
4351

44-
await connect()
52+
await connect(mongooseVersion)
4553
})
4654

4755
afterEach(async () => {

packages/datadog-plugin-mongoose/test/integration-test/server.mjs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,6 @@ const testSchema = new mongoose.Schema({
66
})
77
const TestModel = mongoose.model('Test', testSchema)
88

9-
await mongoose.connect('mongodb://localhost:27017/test_db', { useNewUrlParser: true, useUnifiedTopology: true })
9+
await mongoose.connect('mongodb://localhost:27017/test_db')
1010
await TestModel.create({ a: 1 })
1111
await mongoose.disconnect()

packages/dd-trace/test/appsec/iast/analyzers/nosql-injection-mongodb-analyzer.mongoose.plugin.spec.js

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,17 @@ describe('nosql injection detection in mongodb - whole feature', () => {
2626
const dbName = id().toString()
2727
mongoose = require(`../../../../../../versions/mongoose@${mongooseVersion}`).get()
2828

29-
await mongoose.connect(`mongodb://localhost:27017/${dbName}`, {
30-
useNewUrlParser: true,
31-
useUnifiedTopology: true
32-
})
29+
const loadedMongooseVersion = require(`../../../../../../versions/mongoose@${mongooseVersion}`).version()
30+
31+
const connectOptions = {}
32+
33+
// useNewUrlParser and useUnifiedTopology are not supported in mongoose >= 5
34+
if (semver.lt(loadedMongooseVersion, '5.0.0')) {
35+
connectOptions.useNewUrlParser = true
36+
connectOptions.useUnifiedTopology = true
37+
}
38+
39+
await mongoose.connect(`mongodb://localhost:27017/${dbName}`, connectOptions)
3340

3441
if (mongoose.models.Test) {
3542
delete mongoose.models?.Test

packages/dd-trace/test/plugins/versions/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@
143143
"moleculer": "0.14.35",
144144
"mongodb": "7.0.0",
145145
"mongodb-core": "3.2.7",
146-
"mongoose": "8.19.3",
146+
"mongoose": "9.0.0",
147147
"mquery": "5.0.0",
148148
"multer": "2.0.2",
149149
"mysql": "2.18.1",

0 commit comments

Comments
 (0)