@@ -13,13 +13,11 @@ async function compareImages({ imageBuffer, snapshotPath, diffPath, threshold =
1313 ensureDirSync ( path . dirname ( snapshotPath ) ) ;
1414 ensureDirSync ( path . dirname ( diffPath ) ) ;
1515
16- // If no snapshot exists, save one and return
1716 if ( ! fs . existsSync ( snapshotPath ) ) {
1817 fs . writeFileSync ( snapshotPath , imageBuffer ) ;
1918 return { equal : true , created : true } ;
2019 }
21-
22- // Write current image to temp file for diffing
20+
2321 const tempPath = path . join ( os . tmpdir ( ) , `current-${ Date . now ( ) } .png` ) ;
2422 fs . writeFileSync ( tempPath , imageBuffer ) ;
2523
@@ -34,8 +32,18 @@ async function compareImages({ imageBuffer, snapshotPath, diffPath, threshold =
3432 diff : diffPath ,
3533 highlightColor : '#ff00ff'
3634 } , ( diffErr ) => {
37- fs . unlinkSync ( tempPath ) ; // Clean up temp file
38- if ( diffErr ) return reject ( diffErr ) ;
35+ fs . unlinkSync ( tempPath ) ;
36+
37+ if ( diffErr ) {
38+ console . error ( 'Error creating diff:' , diffErr ) ;
39+ return reject ( diffErr ) ;
40+ }
41+
42+ if ( ! fs . existsSync ( diffPath ) ) {
43+ console . error ( 'Diff file was not created at:' , diffPath ) ;
44+ return reject ( new Error ( 'Diff file not created' ) ) ;
45+ }
46+
3947 resolve ( { equal : false , created : false } ) ;
4048 } ) ;
4149 } else {
0 commit comments