@@ -8,6 +8,12 @@ import {
8
8
import sanitize from "sanitize-filename" ;
9
9
10
10
const nameCacheCounter : Record < string , number > = { } ;
11
+ const lastRetryNameCacheCounter : Record < string , number > = { } ;
12
+ let lastRetryNumber = 0 ;
13
+
14
+ const resetMap = ( map : Record < string , unknown > ) => {
15
+ for ( const key in map ) delete map [ key ] ;
16
+ } ;
11
17
12
18
export const generateScreenshotPath = ( {
13
19
titleFromOptions,
@@ -43,15 +49,24 @@ export const generateScreenshotPath = ({
43
49
nameCacheCounter [ screenshotPath ] = - 1 ;
44
50
}
45
51
46
- // it's a retry of the same image, so let's decrease the counter
47
- if ( currentRetryNumber > 0 ) {
48
- -- nameCacheCounter [ screenshotPath ] ;
52
+ // it's a retry of last test, so let's reset the counter to value before last retry
53
+ if ( currentRetryNumber > lastRetryNumber ) {
54
+ // +1 because we index screenshots starting at 0
55
+ for ( const screenshotPath in lastRetryNameCacheCounter )
56
+ nameCacheCounter [ screenshotPath ] -=
57
+ lastRetryNameCacheCounter [ screenshotPath ] + 1 ;
49
58
}
59
+
60
+ resetMap ( lastRetryNameCacheCounter ) ;
61
+
62
+ lastRetryNumber = currentRetryNumber ;
63
+ lastRetryNameCacheCounter [ screenshotPath ] = ++ nameCacheCounter [
64
+ screenshotPath
65
+ ] ;
66
+
50
67
return path . join (
51
68
IMAGE_SNAPSHOT_PREFIX ,
52
- `${ screenshotPath } #${ ++ nameCacheCounter [ screenshotPath ] } ${
53
- FILE_SUFFIX . actual
54
- } .png`
69
+ `${ screenshotPath } #${ nameCacheCounter [ screenshotPath ] } ${ FILE_SUFFIX . actual } .png`
55
70
) ;
56
71
} ;
57
72
@@ -71,5 +86,7 @@ export const wasScreenshotUsed = (imagePath: string) => {
71
86
} ;
72
87
73
88
export const resetScreenshotNameCache = ( ) => {
74
- Object . keys ( nameCacheCounter ) . forEach ( ( k ) => delete nameCacheCounter [ k ] ) ;
89
+ lastRetryNumber = 0 ;
90
+ resetMap ( nameCacheCounter ) ;
91
+ resetMap ( lastRetryNameCacheCounter ) ;
75
92
} ;
0 commit comments