@@ -71,12 +71,12 @@ describe("unittests:: sys:: symlinkWatching::", () => {
71
71
}
72
72
73
73
interface EventAndFileName {
74
- event : string ;
74
+ event : "rename" | "change" ;
75
75
// eslint-disable-next-line no-restricted-syntax
76
76
fileName : string | null | undefined ;
77
77
}
78
78
interface ExpectedEventAndFileName {
79
- event : string | readonly string [ ] ; // Its expected event name or any of the event names
79
+ event : "rename" | "change" | readonly [ "rename" , "change" ] ; // Its expected event name or any of the event names
80
80
// eslint-disable-next-line no-restricted-syntax
81
81
fileName : string | null | undefined ;
82
82
}
@@ -126,23 +126,32 @@ describe("unittests:: sys:: symlinkWatching::", () => {
126
126
return deferred . promise ;
127
127
}
128
128
129
+ function compareEventFileName ( a : EventAndFileName [ "fileName" ] , b : EventAndFileName [ "fileName" ] ) {
130
+ return ts . compareStringsCaseSensitive ( a ?? undefined , b ?? undefined ) ;
131
+ }
132
+
133
+ function compareEventAndFileName ( a : EventAndFileName , b : EventAndFileName ) : ts . Comparison {
134
+ return compareEventFileName ( b . fileName , a . fileName ) || // Also longer string to be before shorter string
135
+ ts . compareStringsCaseSensitive ( b . event , a . event ) ; // We want rename to be before change
136
+ }
137
+
129
138
function verifyEventAndFileNames (
130
139
prefix : string ,
131
140
actual : readonly EventAndFileName [ ] ,
132
141
expected : readonly ExpectedEventAndFileName [ ] | undefined ,
133
142
) {
134
143
assert ( actual . length >= ( expected ?. length ?? 0 ) , `${ prefix } :: Expected ${ JSON . stringify ( expected ) } events, got ${ JSON . stringify ( actual ) } ` ) ;
144
+ const sortedActual = ts . sortAndDeduplicate ( actual , compareEventAndFileName ) ;
145
+
135
146
let expectedIndex = 0 ;
136
- for ( const a of actual ) {
147
+ for ( const a of sortedActual ) {
137
148
if ( isExpectedEventAndFileName ( a , expected ! [ expectedIndex ] ) ) {
138
149
expectedIndex ++ ;
139
150
continue ;
140
151
}
141
- // Previous event repeated?
142
- if ( isExpectedEventAndFileName ( a , expected ! [ expectedIndex - 1 ] ) ) continue ;
143
- ts . Debug . fail ( `${ prefix } :: Expected ${ JSON . stringify ( expected ) } events, got ${ JSON . stringify ( actual ) } ` ) ;
152
+ ts . Debug . fail ( `${ prefix } :: Expected ${ JSON . stringify ( expected ) } events, got ${ JSON . stringify ( actual ) } Sorted: ${ JSON . stringify ( sortedActual ) } ` ) ;
144
153
}
145
- assert ( expectedIndex >= ( expected ?. length ?? 0 ) , `${ prefix } :: Should get all events: Expected ${ JSON . stringify ( expected ) } events, got ${ JSON . stringify ( actual ) } ` ) ;
154
+ assert ( expectedIndex >= ( expected ?. length ?? 0 ) , `${ prefix } :: Should get all events: Expected ${ JSON . stringify ( expected ) } events, got ${ JSON . stringify ( actual ) } Sorted: ${ JSON . stringify ( sortedActual ) } ` ) ;
146
155
}
147
156
148
157
function isExpectedEventAndFileName ( actual : EventAndFileName , expected : ExpectedEventAndFileName | undefined ) {
0 commit comments