@@ -34,7 +34,7 @@ const PATH_VARIABLES = {
34
34
const WINDOWS_LIKE_DRIVE_REGEX = / ^ [ A - Z ] : $ / ;
35
35
const METADATA_KEY = "FRSOURCE_CPVRD_V" ;
36
36
37
- var version = "3.1.0 " ;
37
+ var version = "3.1.1 " ;
38
38
39
39
function isHighSurrogate ( codePoint ) {
40
40
return codePoint >= 0xd800 && codePoint <= 0xdbff ;
@@ -140,6 +140,13 @@ var sanitizeFilename = function (input, options) {
140
140
} ;
141
141
142
142
const nameCacheCounter = { } ;
143
+ const lastRetryNameCacheCounter = { } ;
144
+ let lastRetryNumber = 0 ;
145
+
146
+ const resetMap = map => {
147
+ for ( const key in map ) delete map [ key ] ;
148
+ } ;
149
+
143
150
const generateScreenshotPath = ( {
144
151
titleFromOptions,
145
152
imagesPath,
@@ -164,14 +171,18 @@ const generateScreenshotPath = ({
164
171
165
172
if ( typeof nameCacheCounter [ screenshotPath ] === "undefined" ) {
166
173
nameCacheCounter [ screenshotPath ] = - 1 ;
167
- } // it's a retry of the same image , so let's decrease the counter
174
+ } // it's a retry of last test , so let's reset the counter to value before last retry
168
175
169
176
170
- if ( currentRetryNumber > 0 ) {
171
- -- nameCacheCounter [ screenshotPath ] ;
177
+ if ( currentRetryNumber > lastRetryNumber ) {
178
+ // +1 because we index screenshots starting at 0
179
+ for ( const _screenshotPath in lastRetryNameCacheCounter ) nameCacheCounter [ _screenshotPath ] -= lastRetryNameCacheCounter [ _screenshotPath ] + 1 ;
172
180
}
173
181
174
- return path . join ( IMAGE_SNAPSHOT_PREFIX , `${ screenshotPath } #${ ++ nameCacheCounter [ screenshotPath ] } ${ FILE_SUFFIX . actual } .png` ) ;
182
+ resetMap ( lastRetryNameCacheCounter ) ;
183
+ lastRetryNumber = currentRetryNumber ;
184
+ lastRetryNameCacheCounter [ screenshotPath ] = ++ nameCacheCounter [ screenshotPath ] ;
185
+ return path . join ( IMAGE_SNAPSHOT_PREFIX , `${ screenshotPath } #${ nameCacheCounter [ screenshotPath ] } ${ FILE_SUFFIX . actual } .png` ) ;
175
186
} ;
176
187
const screenshotPathRegex = new RegExp ( `^([\\s\\S]+?) #([0-9]+)(?:(?:\\${ FILE_SUFFIX . diff } )|(?:\\${ FILE_SUFFIX . actual } ))?\\.(?:png|PNG)$` ) ;
177
188
const wasScreenshotUsed = imagePath => {
@@ -187,7 +198,9 @@ const wasScreenshotUsed = imagePath => {
187
198
return screenshotPath in nameCacheCounter && num <= nameCacheCounter [ screenshotPath ] ;
188
199
} ;
189
200
const resetScreenshotNameCache = ( ) => {
190
- Object . keys ( nameCacheCounter ) . forEach ( k => delete nameCacheCounter [ k ] ) ;
201
+ lastRetryNumber = 0 ;
202
+ resetMap ( nameCacheCounter ) ;
203
+ resetMap ( lastRetryNameCacheCounter ) ;
191
204
} ;
192
205
193
206
const addPNGMetadata = png => addMetadata ( png , METADATA_KEY , version
0 commit comments