From 5beb137b88d144e08be6b6e75007c903b2ce55c3 Mon Sep 17 00:00:00 2001 From: Daniel Diaz <39510674+IslandRhythms@users.noreply.github.com> Date: Thu, 18 May 2023 13:40:15 -0400 Subject: [PATCH 1/6] fix: debug no longer omits last arg on func --- lib/drivers/node-mongodb-native/collection.js | 8 +++++++- test/index.test.js | 13 +++++++++++++ 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/lib/drivers/node-mongodb-native/collection.js b/lib/drivers/node-mongodb-native/collection.js index 6f5a97037d5..fc9235f6f48 100644 --- a/lib/drivers/node-mongodb-native/collection.js +++ b/lib/drivers/node-mongodb-native/collection.js @@ -208,8 +208,14 @@ function iter(i) { if (debug) { if (typeof debug === 'function') { + let range = ''; + if (typeof args[args.length - 1] == 'function') { + range = args.slice(0, args.length - 1); + } else { + range = args.slice(0, args.length); + } debug.apply(_this, - [_this.name, i].concat(args.slice(0, args.length - 1))); + [_this.name, i].concat(range)); } else if (debug instanceof stream.Writable) { this.$printToStream(_this.name, i, args, debug); } else { diff --git a/test/index.test.js b/test/index.test.js index 6e4aae99926..d90aab98123 100644 --- a/test/index.test.js +++ b/test/index.test.js @@ -90,6 +90,19 @@ describe('mongoose module:', function() { await mongoose.disconnect(); }); + it('should collect the args correctly gh-13364', async function() { + const util = require('util'); + const mongoose = new Mongoose(); + const conn = await mongoose.connect(start.uri); + let actual = ''; + mongoose.set('debug', (collectionName, methodName, ...methodArgs) => { + actual = `${collectionName}.${methodName}(${util.inspect(methodArgs).slice(2, -2)})`; + }); + const user = conn.connection.collection('User'); + await user.findOne({ key: 'value' }); + assert.equal(`User.findOne({ key: 'value' })`, actual); + }); + it('{g,s}etting options', function() { const mongoose = new Mongoose(); From 34fd7937f0d3069e1859b12580b21d17c8c2b743 Mon Sep 17 00:00:00 2001 From: Daniel Diaz <39510674+IslandRhythms@users.noreply.github.com> Date: Thu, 18 May 2023 13:40:57 -0400 Subject: [PATCH 2/6] lint fix --- test/index.test.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/index.test.js b/test/index.test.js index d90aab98123..0976aab3479 100644 --- a/test/index.test.js +++ b/test/index.test.js @@ -100,7 +100,7 @@ describe('mongoose module:', function() { }); const user = conn.connection.collection('User'); await user.findOne({ key: 'value' }); - assert.equal(`User.findOne({ key: 'value' })`, actual); + assert.equal('User.findOne({ key: \'value\' })', actual); }); it('{g,s}etting options', function() { From f6d25f9329ac3e2d0c7dae61881b5da2f69b1678 Mon Sep 17 00:00:00 2001 From: Daniel Diaz <39510674+IslandRhythms@users.noreply.github.com> Date: Thu, 18 May 2023 13:50:13 -0400 Subject: [PATCH 3/6] fix: test gh-13065 --- test/query.test.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/test/query.test.js b/test/query.test.js index 4f991ff25af..cef17261ea7 100644 --- a/test/query.test.js +++ b/test/query.test.js @@ -3984,7 +3984,8 @@ describe('Query', function() { let lastOptions = {}; m.set('debug', function(_coll, _method, ...args) { - lastOptions = args[args.length - 1]; + lastOptions = args[args.length - 2]; + console.log('what is lastOptions', lastOptions) }); const connDebug = m.createConnection(start.uri); From b7b2e42f64a80f60463b6d6cc58cfd3d37c4b528 Mon Sep 17 00:00:00 2001 From: Daniel Diaz <39510674+IslandRhythms@users.noreply.github.com> Date: Thu, 18 May 2023 13:50:39 -0400 Subject: [PATCH 4/6] remove console log --- test/query.test.js | 1 - 1 file changed, 1 deletion(-) diff --git a/test/query.test.js b/test/query.test.js index cef17261ea7..760af5abce8 100644 --- a/test/query.test.js +++ b/test/query.test.js @@ -3985,7 +3985,6 @@ describe('Query', function() { let lastOptions = {}; m.set('debug', function(_coll, _method, ...args) { lastOptions = args[args.length - 2]; - console.log('what is lastOptions', lastOptions) }); const connDebug = m.createConnection(start.uri); From 621d825a2d95c3954a703b8a206b651740e78196 Mon Sep 17 00:00:00 2001 From: Daniel Diaz <39510674+IslandRhythms@users.noreply.github.com> Date: Thu, 18 May 2023 13:52:00 -0400 Subject: [PATCH 5/6] fix: test gh-13052 --- test/docs/debug.test.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/docs/debug.test.js b/test/docs/debug.test.js index db3e4b7523b..3cb82fab4ec 100644 --- a/test/docs/debug.test.js +++ b/test/docs/debug.test.js @@ -105,7 +105,7 @@ describe('debug: shell', function() { await Test.create({ name: 'foo' }); assert.equal(args.length, 1); assert.equal(args[0][1], 'insertOne'); - assert.strictEqual(args[0][3], undefined); + assert.strictEqual(args[0][4], undefined); await m.disconnect(); }); From 05eca748672c72a237881dbce00bba9a4e7f4089 Mon Sep 17 00:00:00 2001 From: Valeri Karpov Date: Thu, 18 May 2023 18:10:05 -0400 Subject: [PATCH 6/6] Update collection.js --- lib/drivers/node-mongodb-native/collection.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/drivers/node-mongodb-native/collection.js b/lib/drivers/node-mongodb-native/collection.js index fc9235f6f48..2fb6804c3f4 100644 --- a/lib/drivers/node-mongodb-native/collection.js +++ b/lib/drivers/node-mongodb-native/collection.js @@ -208,14 +208,14 @@ function iter(i) { if (debug) { if (typeof debug === 'function') { - let range = ''; + let argsToAdd = null; if (typeof args[args.length - 1] == 'function') { - range = args.slice(0, args.length - 1); + argsToAdd = args.slice(0, args.length - 1); } else { - range = args.slice(0, args.length); + argsToAdd = args; } debug.apply(_this, - [_this.name, i].concat(range)); + [_this.name, i].concat(argsToAdd)); } else if (debug instanceof stream.Writable) { this.$printToStream(_this.name, i, args, debug); } else {