@@ -8,7 +8,7 @@ import { ReadPreference } from '../../../src/read_preference';
8
8
import { TopologyType } from '../../../src/sdam/common' ;
9
9
import { ns } from '../../../src/utils' ;
10
10
import { ejson } from '../utils' ;
11
- import { CmapEvent , CommandEvent , EntitiesMap } from './entities' ;
11
+ import { CmapEvent , CommandEvent , EntitiesMap , UnifiedMongoClient } from './entities' ;
12
12
import { matchesEvents } from './match' ;
13
13
import { executeOperationAndCheck } from './operations' ;
14
14
import * as uni from './schema' ;
@@ -198,13 +198,12 @@ async function runUnifiedTest(
198
198
}
199
199
}
200
200
201
- const clientCommandEvents = new Map < string , CommandEvent [ ] > ( ) ;
202
- const clientCmapEvents = new Map < string , CmapEvent [ ] > ( ) ;
201
+ const clientList = new Map < string , UnifiedMongoClient > ( ) ;
203
202
// If any event listeners were enabled on any client entities,
204
203
// the test runner MUST now disable those event listeners.
205
204
for ( const [ id , client ] of entities . mapOf ( 'client' ) ) {
206
- clientCommandEvents . set ( id , client . stopCapturingCommandEvents ( ) ) ;
207
- clientCmapEvents . set ( id , client . stopCapturingCmapEvents ( ) ) ;
205
+ client . stopCapturingEvents ( ) ;
206
+ clientList . set ( id , client ) ;
208
207
}
209
208
210
209
if ( test . expectEvents ) {
@@ -213,11 +212,13 @@ async function runUnifiedTest(
213
212
const eventType = expectedEventsForClient . eventType ;
214
213
// If no event type is provided it defaults to 'command', so just
215
214
// check for 'cmap' here for now.
216
- const actualEvents =
217
- eventType === 'cmap' ? clientCmapEvents . get ( clientId ) : clientCommandEvents . get ( clientId ) ;
218
-
219
- expect ( actualEvents , `No client entity found with id ${ clientId } ` ) . to . exist ;
220
- matchesEvents ( expectedEventsForClient , actualEvents ! , entities ) ;
215
+ const testClient = clientList . get ( clientId ) ;
216
+ expect ( testClient , `No client entity found with id ${ clientId } ` ) . to . exist ;
217
+ matchesEvents (
218
+ expectedEventsForClient ,
219
+ testClient ! . getCapturedEvents ( eventType ?? 'command' ) ,
220
+ entities
221
+ ) ;
221
222
}
222
223
}
223
224
0 commit comments