@@ -38,6 +38,7 @@ import {
38
38
} from '../../mongodb' ;
39
39
import { ejson } from '../utils' ;
40
40
import { type CmapEvent , type CommandEvent , type EntitiesMap , type SdamEvent } from './entities' ;
41
+ import { trace } from './runner' ;
41
42
import {
42
43
type ExpectedCmapEvent ,
43
44
type ExpectedCommandEvent ,
@@ -606,17 +607,22 @@ function compareEvents(
606
607
} else if ( expectedEvent . topologyDescriptionChangedEvent ) {
607
608
expect ( actualEvent ) . to . be . instanceOf ( TopologyDescriptionChangedEvent ) ;
608
609
const expectedSdamEvent = expectedEvent . topologyDescriptionChangedEvent ;
609
- for ( const property of Object . keys ( expectedSdamEvent ) ) {
610
+ // Only check the previousDescription and newDescription fields
611
+ for ( const property of [ 'previousDescription' , 'newDescription' ] ) {
612
+ if ( expectedSdamEvent [ property ] === undefined ) continue ;
610
613
if ( typeof expectedSdamEvent [ property ] === 'object' ) {
611
- for ( const key of Object . keys ( expectedSdamEvent [ property ] ) ) {
612
- expect ( actualEvent [ property ] [ key ] ) . to . equal ( expectedSdamEvent [ property ] [ key ] ) ;
613
- }
614
+ expect ( actualEvent [ property ] ) . to . have . property ( 'type' ) ;
615
+ expect ( actualEvent [ property ] . type ) . to . equal ( expectedSdamEvent [ property ] . type ) ;
614
616
} else {
615
- expect ( actualEvent [ property ] ) . to . equal ( expectedSdamEvent [ property ] ) ;
617
+ expect . fail (
618
+ `Incorrect format of ${ property } field.Expected an object with key 'type' with string value, got ${ inspect (
619
+ expectedSdamEvent [ property ]
620
+ ) } `
621
+ ) ;
616
622
}
617
623
}
618
624
} else {
619
- expect . fail ( `Encountered unexpected event - ${ inspect ( actualEvent ) } ` ) ;
625
+ expect . fail ( `Encountered unexpected event - ${ inspect ( actualEvent ) } ` ) ;
620
626
}
621
627
}
622
628
}
@@ -719,7 +725,7 @@ export function expectErrorCheck(
719
725
expected : ExpectedError ,
720
726
entities : EntitiesMap
721
727
) : void {
722
- const expectMessage = `\n\nOriginal Error Stack:\n${ error . stack } \n\n` ;
728
+ const expectMessage = `\n\nOriginal Error Stack: \n${ error . stack } \n\n` ;
723
729
724
730
if ( ! isMongoCryptError ( error ) ) {
725
731
expect ( error , expectMessage ) . to . be . instanceOf ( MongoError ) ;
@@ -750,7 +756,7 @@ export function expectErrorCheck(
750
756
for ( const errorLabel of expected . errorLabelsContain ) {
751
757
expect (
752
758
mongoError . hasErrorLabel ( errorLabel ) ,
753
- `Error was supposed to have label ${ errorLabel } , has [${ mongoError . errorLabels } ] -- ${ expectMessage } `
759
+ `Error was supposed to have label ${ errorLabel } , has[${ mongoError . errorLabels } ]-- ${ expectMessage } `
754
760
) . to . be . true ;
755
761
}
756
762
}
@@ -760,7 +766,7 @@ export function expectErrorCheck(
760
766
for ( const errorLabel of expected . errorLabelsOmit ) {
761
767
expect (
762
768
mongoError . hasErrorLabel ( errorLabel ) ,
763
- `Error was not supposed to have label ${ errorLabel } , has [${ mongoError . errorLabels } ] -- ${ expectMessage } `
769
+ `Error was not supposed to have label ${ errorLabel } , has[${ mongoError . errorLabels } ]-- ${ expectMessage } `
764
770
) . to . be . false ;
765
771
}
766
772
}
0 commit comments