Skip to content

Commit

Permalink
Fix issue with cleanig up leftover images from previous run (NimaSoro…
Browse files Browse the repository at this point in the history
  • Loading branch information
NimaSoroush authored Oct 7, 2018
1 parent afcc430 commit 84489a3
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 4 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## [1.5.1] - 2018-10-07
### Fixed
- Fix issue with cleanig up leftover images from previous runs

## [1.5.0] - 2018-08-30
### Added
- Making Differencify compatible with differencify-jest-reporter
Expand Down
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "differencify",
"version": "1.5.0",
"version": "1.5.1",
"description": "Perceptual diffing tool",
"main": "dist/index.js",
"scripts": {
Expand Down
17 changes: 15 additions & 2 deletions src/compareImage.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,16 @@ const saveDiff = (diff, diffPath) => new Promise((resolve, reject) => {
diff.image.write(diffPath, cb);
});

const cleanUpImages = (images) => {
images.forEach((image) => {
try {
fs.unlinkSync(image);
} catch (e) {
// ignore error as left over image may not exist
}
});
};

const compareImage = async (capturedImage, globalConfig, testConfig) => {
const prefixedLogger = logger.prefix(testConfig.testName);
const snapshotsDir = globalConfig.imageSnapshotPathProvided
Expand All @@ -33,6 +43,11 @@ const compareImage = async (capturedImage, globalConfig, testConfig) => {
const diffDir = getDiffDir(snapshotsDir);
const diffPath = getDiffPath(diffDir, testConfig);

const currentImageDir = getCurrentImageDir(snapshotsDir);
const currentImagePath = getCurrentImagePath(currentImageDir, testConfig);

cleanUpImages([diffPath, currentImagePath]);

if (fs.existsSync(snapshotPath) && !testConfig.isUpdate) {
let snapshotImage;
try {
Expand Down Expand Up @@ -60,8 +75,6 @@ const compareImage = async (capturedImage, globalConfig, testConfig) => {
};
}
if (globalConfig.saveCurrentImage) {
const currentImageDir = getCurrentImageDir(snapshotsDir);
const currentImagePath = getCurrentImagePath(currentImageDir, testConfig);
try {
if (!fs.existsSync(currentImageDir)) {
fs.mkdirSync(currentImageDir);
Expand Down

0 comments on commit 84489a3

Please sign in to comment.