Skip to content

Commit 84489a3

Browse files
authored
Fix issue with cleanig up leftover images from previous run (#105)
1 parent afcc430 commit 84489a3

File tree

4 files changed

+21
-4
lines changed

4 files changed

+21
-4
lines changed

CHANGELOG.md

+4
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
## [1.5.1] - 2018-10-07
2+
### Fixed
3+
- Fix issue with cleanig up leftover images from previous runs
4+
15
## [1.5.0] - 2018-08-30
26
### Added
37
- Making Differencify compatible with differencify-jest-reporter

package-lock.json

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "differencify",
3-
"version": "1.5.0",
3+
"version": "1.5.1",
44
"description": "Perceptual diffing tool",
55
"main": "dist/index.js",
66
"scripts": {

src/compareImage.js

+15-2
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,16 @@ const saveDiff = (diff, diffPath) => new Promise((resolve, reject) => {
2222
diff.image.write(diffPath, cb);
2323
});
2424

25+
const cleanUpImages = (images) => {
26+
images.forEach((image) => {
27+
try {
28+
fs.unlinkSync(image);
29+
} catch (e) {
30+
// ignore error as left over image may not exist
31+
}
32+
});
33+
};
34+
2535
const compareImage = async (capturedImage, globalConfig, testConfig) => {
2636
const prefixedLogger = logger.prefix(testConfig.testName);
2737
const snapshotsDir = globalConfig.imageSnapshotPathProvided
@@ -33,6 +43,11 @@ const compareImage = async (capturedImage, globalConfig, testConfig) => {
3343
const diffDir = getDiffDir(snapshotsDir);
3444
const diffPath = getDiffPath(diffDir, testConfig);
3545

46+
const currentImageDir = getCurrentImageDir(snapshotsDir);
47+
const currentImagePath = getCurrentImagePath(currentImageDir, testConfig);
48+
49+
cleanUpImages([diffPath, currentImagePath]);
50+
3651
if (fs.existsSync(snapshotPath) && !testConfig.isUpdate) {
3752
let snapshotImage;
3853
try {
@@ -60,8 +75,6 @@ const compareImage = async (capturedImage, globalConfig, testConfig) => {
6075
};
6176
}
6277
if (globalConfig.saveCurrentImage) {
63-
const currentImageDir = getCurrentImageDir(snapshotsDir);
64-
const currentImagePath = getCurrentImagePath(currentImageDir, testConfig);
6578
try {
6679
if (!fs.existsSync(currentImageDir)) {
6780
fs.mkdirSync(currentImageDir);

0 commit comments

Comments
 (0)