@@ -55,26 +55,12 @@ class LeakChecker {
55
55
56
56
setupClientLeakChecker ( ) {
57
57
const leakChecker = this ;
58
- MongoClient . prototype . connect = function ( ... args ) {
58
+ MongoClient . prototype . connect = async function ( ) {
59
59
leakChecker . clients . add ( this ) ;
60
60
this [ LeakChecker . kConnectCount ] ??= 0 ;
61
-
62
- const lastArg = args [ args . length - 1 ] ;
63
- const lastArgIsCallback = typeof lastArg === 'function' ;
64
- if ( lastArgIsCallback ) {
65
- const argsWithoutCallback = args . slice ( 0 , args . length - 1 ) ;
66
- return LeakChecker . originalConnect . call ( this , ...argsWithoutCallback , ( error , client ) => {
67
- if ( error == null ) {
68
- this [ LeakChecker . kConnectCount ] += 1 ; // only increment on successful connects
69
- }
70
- return lastArg ( error , client ) ;
71
- } ) ;
72
- } else {
73
- return LeakChecker . originalConnect . call ( this , ...args ) . then ( client => {
74
- this [ LeakChecker . kConnectCount ] += 1 ; // only increment on successful connects
75
- return client ;
76
- } ) ;
77
- }
61
+ await LeakChecker . originalConnect . call ( this ) ;
62
+ this [ LeakChecker . kConnectCount ] += 1 ; // only increment on successful connects
63
+ return this ;
78
64
} ;
79
65
80
66
MongoClient . prototype . close = function ( ...args ) {
@@ -178,4 +164,4 @@ const socketLeakCheckAfterEach: Mocha.AsyncFunc = async function socketLeakCheck
178
164
const beforeAll = TRACE_SOCKETS ? [ socketLeakCheckBeforeAll ] : [ ] ;
179
165
const beforeEach = [ leakCheckerBeforeEach ] ;
180
166
const afterEach = [ leakCheckerAfterEach , ...( TRACE_SOCKETS ? [ socketLeakCheckAfterEach ] : [ ] ) ] ;
181
- module . exports = { mochaHooks : { beforeAll, beforeEach, afterEach } } ;
167
+ export const mochaHooks = { beforeAll, beforeEach, afterEach } ;
0 commit comments