@@ -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+
2535const 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