Skip to content

Commit bfbf138

Browse files
committedOct 26, 2022
fix: reset name cache after tests run
Signed-off-by: Jakub Freisler <[email protected]>
1 parent 912313c commit bfbf138

File tree

3 files changed

+11
-2
lines changed

3 files changed

+11
-2
lines changed
 

‎README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ Or, if you would like to make a screenshot of whole document:
137137
cy.matchImage();
138138
```
139139

140-
`matchImage` command will do a screenshot and compare it with image from a previous run. In case of regression the test will fail and you'll get a "Compare images" button to see what's a root of a problem.
140+
`matchImage` command will do a screenshot and compare it with image from a previous run. In case of regression the test will fail and you'll get a "See comparison" button to see what's a root of a problem.
141141

142142
## Example
143143

‎src/screenshotPath.utils.ts

+4
Original file line numberDiff line numberDiff line change
@@ -62,3 +62,7 @@ export const wasScreenshotUsed = (imagePath: string) => {
6262
num <= nameCacheCounter[screenshotPath]
6363
);
6464
};
65+
66+
export const resetScreenshotNameCache = () => {
67+
Object.keys(nameCacheCounter).forEach((k) => delete nameCacheCounter[k]);
68+
};

‎src/task.hook.ts

+6-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,10 @@ import {
1111
isImageCurrentVersion,
1212
writePNG,
1313
} from "./image.utils";
14-
import { generateScreenshotPath } from "./screenshotPath.utils";
14+
import {
15+
generateScreenshotPath,
16+
resetScreenshotNameCache,
17+
} from "./screenshotPath.utils";
1518
import type { CompareImagesTaskReturn } from "./types";
1619

1720
export type CompareImagesCfg = {
@@ -46,6 +49,8 @@ export const cleanupImagesTask = (config: Cypress.PluginConfigOptions) => {
4649
cleanupUnused(config.projectRoot);
4750
}
4851

52+
resetScreenshotNameCache();
53+
4954
return null;
5055
};
5156

0 commit comments

Comments
 (0)
Please sign in to comment.