@@ -22,6 +22,16 @@ const saveDiff = (diff, diffPath) => new Promise((resolve, reject) => {
22
22
diff . image . write ( diffPath , cb ) ;
23
23
} ) ;
24
24
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
+
25
35
const compareImage = async ( capturedImage , globalConfig , testConfig ) => {
26
36
const prefixedLogger = logger . prefix ( testConfig . testName ) ;
27
37
const snapshotsDir = globalConfig . imageSnapshotPathProvided
@@ -33,6 +43,11 @@ const compareImage = async (capturedImage, globalConfig, testConfig) => {
33
43
const diffDir = getDiffDir ( snapshotsDir ) ;
34
44
const diffPath = getDiffPath ( diffDir , testConfig ) ;
35
45
46
+ const currentImageDir = getCurrentImageDir ( snapshotsDir ) ;
47
+ const currentImagePath = getCurrentImagePath ( currentImageDir , testConfig ) ;
48
+
49
+ cleanUpImages ( [ diffPath , currentImagePath ] ) ;
50
+
36
51
if ( fs . existsSync ( snapshotPath ) && ! testConfig . isUpdate ) {
37
52
let snapshotImage ;
38
53
try {
@@ -60,8 +75,6 @@ const compareImage = async (capturedImage, globalConfig, testConfig) => {
60
75
} ;
61
76
}
62
77
if ( globalConfig . saveCurrentImage ) {
63
- const currentImageDir = getCurrentImageDir ( snapshotsDir ) ;
64
- const currentImagePath = getCurrentImagePath ( currentImageDir , testConfig ) ;
65
78
try {
66
79
if ( ! fs . existsSync ( currentImageDir ) ) {
67
80
fs . mkdirSync ( currentImageDir ) ;
0 commit comments