@@ -173,22 +173,46 @@ module Playback {
173
173
}
174
174
175
175
function findResultByPath < T > ( wrapper : { resolvePath ( s : string ) : string } , logArray : { path : string ; result ?: T } [ ] , expectedPath : string , defaultValue ?: T ) : T {
176
- var results = logArray . filter ( e => pathsAreEquivalent ( e . path , expectedPath , wrapper ) ) ;
177
- if ( results . length === 0 ) {
178
- if ( defaultValue === undefined ) {
179
- throw new Error ( 'No matching result in log array for path: ' + expectedPath ) ;
180
- } else {
181
- return defaultValue ;
176
+ var normalizedName = Harness . Path . switchToForwardSlashes ( expectedPath ) . toLowerCase ( ) ;
177
+ // Try to find the result through normal filename
178
+ for ( var i = 0 ; i < logArray . length ; i ++ ) {
179
+ if ( Harness . Path . switchToForwardSlashes ( logArray [ i ] . path ) . toLowerCase ( ) === normalizedName ) {
180
+ return logArray [ i ] . result ;
182
181
}
183
182
}
184
- return results [ 0 ] . result ;
183
+ // Fallback, try to resolve the target paths as well
184
+ if ( replayLog . pathsResolved . length > 0 ) {
185
+ var normalizedResolvedName = wrapper . resolvePath ( expectedPath ) . toLowerCase ( ) ;
186
+ for ( var i = 0 ; i < logArray . length ; i ++ ) {
187
+ if ( wrapper . resolvePath ( logArray [ i ] . path ) . toLowerCase ( ) === normalizedResolvedName ) {
188
+ return logArray [ i ] . result ;
189
+ }
190
+ }
191
+ }
192
+ // If we got here, we didn't find a match
193
+ if ( defaultValue === undefined ) {
194
+ throw new Error ( 'No matching result in log array for path: ' + expectedPath ) ;
195
+ } else {
196
+ return defaultValue ;
197
+ }
185
198
}
186
199
200
+ var pathEquivCache : any = { } ;
187
201
function pathsAreEquivalent ( left : string , right : string , wrapper : { resolvePath ( s : string ) : string } ) {
202
+ var key = left + '-~~-' + right ;
188
203
function areSame ( a : string , b : string ) {
189
204
return Harness . Path . switchToForwardSlashes ( a ) . toLowerCase ( ) === Harness . Path . switchToForwardSlashes ( b ) . toLowerCase ( ) ;
190
205
}
191
- return areSame ( left , right ) || areSame ( wrapper . resolvePath ( left ) , right ) || areSame ( left , wrapper . resolvePath ( right ) ) || areSame ( wrapper . resolvePath ( left ) , wrapper . resolvePath ( right ) ) ;
206
+ function check ( ) {
207
+ if ( Harness . Path . getFileName ( left ) . toLowerCase ( ) === Harness . Path . getFileName ( right ) . toLowerCase ( ) ) {
208
+ return areSame ( left , right ) || areSame ( wrapper . resolvePath ( left ) , right ) || areSame ( left , wrapper . resolvePath ( right ) ) || areSame ( wrapper . resolvePath ( left ) , wrapper . resolvePath ( right ) ) ;
209
+ }
210
+ }
211
+ if ( pathEquivCache . hasOwnProperty ( key ) ) {
212
+ return pathEquivCache [ key ] ;
213
+ } else {
214
+ return pathEquivCache [ key ] = check ( ) ;
215
+ }
192
216
}
193
217
194
218
function noOpReplay ( name : string ) {
0 commit comments