@@ -384,6 +384,18 @@ function validateExpectations(commandEvents, spec, savedSessionData) {
384384
385385 const actualCommand = actual . command ;
386386 const expectedCommand = expected . command ;
387+ if ( expectedCommand . sort ) {
388+ // TODO: This is a workaround that works because all sorts in the specs
389+ // are objects with one key; ideally we'd want to adjust the spec definitions
390+ // to indicate whether order matters for any given key and set general
391+ // expectations accordingly (see NODE-3235)
392+ expect ( Object . keys ( expectedCommand . sort ) ) . to . have . lengthOf ( 1 ) ;
393+ expect ( actualCommand . sort ) . to . be . instanceOf ( Map ) ;
394+ expect ( actualCommand . sort . size ) . to . equal ( 1 ) ;
395+ const expectedKey = Object . keys ( expectedCommand . sort ) [ 0 ] ;
396+ expect ( actualCommand . sort ) . to . have . all . keys ( expectedKey ) ;
397+ actualCommand . sort = { [ expectedKey ] : actualCommand . sort . get ( expectedKey ) } ;
398+ }
387399
388400 expect ( actualCommand )
389401 . withSessionData ( savedSessionData )
@@ -392,18 +404,23 @@ function validateExpectations(commandEvents, spec, savedSessionData) {
392404}
393405
394406function normalizeCommandShapes ( commands ) {
395- return commands . map ( command =>
396- JSON . parse (
407+ return commands . map ( def => {
408+ const output = JSON . parse (
397409 EJSON . stringify (
398410 {
399- command : command . command ,
400- commandName : command . command_name ? command . command_name : command . commandName ,
401- databaseName : command . database_name ? command . database_name : command . databaseName
411+ command : def . command ,
412+ commandName : def . command_name ? def . command_name : def . commandName ,
413+ databaseName : def . database_name ? def . database_name : def . databaseName
402414 } ,
403415 { relaxed : true }
404416 )
405- )
406- ) ;
417+ ) ;
418+ // TODO: this is a workaround to preserve sort Map type until NODE-3235 is completed
419+ if ( def . command . sort ) {
420+ output . command . sort = def . command . sort ;
421+ }
422+ return output ;
423+ } ) ;
407424}
408425
409426function extractCrudResult ( result , operation ) {
0 commit comments