Skip to content

Commit 19971df

Browse files
chore(release): 1.1.1 [skip ci]
## [1.1.1](v1.1.0...v1.1.1) (2022-11-04) ### Bug Fixes * new image prefix starts at -1 ([FRSOURCE#172](https://github.com/braze-inc/cypress-plugin-visual-regression-diff/issues/172)) ([8279208](8279208))
1 parent c0cc2ad commit 19971df

File tree

4 files changed

+40
-14
lines changed

4 files changed

+40
-14
lines changed

dist/plugins.js

Lines changed: 19 additions & 6 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/plugins.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/plugins.mjs

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ const PATH_VARIABLES = {
3434
const WINDOWS_LIKE_DRIVE_REGEX = /^[A-Z]:$/;
3535
const METADATA_KEY = "FRSOURCE_CPVRD_V";
3636

37-
var version = "3.1.0";
37+
var version = "3.1.1";
3838

3939
function isHighSurrogate(codePoint) {
4040
return codePoint >= 0xd800 && codePoint <= 0xdbff;
@@ -140,6 +140,13 @@ var sanitizeFilename = function (input, options) {
140140
};
141141

142142
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+
143150
const generateScreenshotPath = ({
144151
titleFromOptions,
145152
imagesPath,
@@ -164,14 +171,18 @@ const generateScreenshotPath = ({
164171

165172
if (typeof nameCacheCounter[screenshotPath] === "undefined") {
166173
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
168175

169176

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;
172180
}
173181

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`);
175186
};
176187
const screenshotPathRegex = new RegExp(`^([\\s\\S]+?) #([0-9]+)(?:(?:\\${FILE_SUFFIX.diff})|(?:\\${FILE_SUFFIX.actual}))?\\.(?:png|PNG)$`);
177188
const wasScreenshotUsed = imagePath => {
@@ -187,7 +198,9 @@ const wasScreenshotUsed = imagePath => {
187198
return screenshotPath in nameCacheCounter && num <= nameCacheCounter[screenshotPath];
188199
};
189200
const resetScreenshotNameCache = () => {
190-
Object.keys(nameCacheCounter).forEach(k => delete nameCacheCounter[k]);
201+
lastRetryNumber = 0;
202+
resetMap(nameCacheCounter);
203+
resetMap(lastRetryNameCacheCounter);
191204
};
192205

193206
const addPNGMetadata = png => addMetadata(png, METADATA_KEY, version

dist/plugins.mjs.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)