@@ -10,21 +10,43 @@ const { configureToMatchImageSnapshot } = jestImageSnapshot;
1010
1111const __dirname = path . dirname ( fileURLToPath ( import . meta. url ) ) ;
1212
13+ // Clean up any leftover mounted Fixture volumes from previous test runs
14+ try {
15+ const volumes = fs . readdirSync ( '/Volumes' ) ;
16+ for ( const volume of volumes ) {
17+ if ( volume . startsWith ( 'Fixture' ) ) {
18+ spawnSync ( 'hdiutil' , [ 'unmount' , '-force' , path . join ( '/Volumes' , volume ) ] , { timeout : 5000 } ) ;
19+ }
20+ }
21+ } catch {
22+ // Ignore cleanup errors
23+ }
24+
1325/** Validate that the icon for the DMG matches the snapshot (with a small tolerance to avoid flakiness) */
1426const assertVolumeIconMatchesSnapshot = ( t , dmgPath ) => {
1527 // Mount the DMG and extract the volume icon
1628 const existingVolumes = new Set ( fs . readdirSync ( '/Volumes' ) ) ;
17- spawnSync ( 'hdiutil' , [ 'mount' , dmgPath ] ) ;
29+ const mountResult = spawnSync ( 'hdiutil' , [ 'mount' , dmgPath ] , { timeout : 10000 } ) ;
30+
31+ if ( mountResult . status !== 0 ) {
32+ throw new Error ( `Failed to mount DMG: ${ mountResult . stderr ?. toString ( ) } ` ) ;
33+ }
34+
1835 const volumes = new Set ( fs . readdirSync ( '/Volumes' ) ) ;
1936 const mountLocation = [ ...volumes ] . find ( x => ! existingVolumes . has ( x ) ) ;
2037 t . truthy ( mountLocation ) ;
2138 const dmgIconPath = path . join ( '/Volumes' , mountLocation , '.VolumeIcon.icns' )
2239 const dirPath = path . dirname ( dmgPath ) ;
2340 const iconPath = path . join ( dirPath , 'VolumeIcon.icns' ) ;
2441 fs . copyFileSync ( dmgIconPath , iconPath ) ;
25- spawnSync ( 'hdiutil' , [ 'unmount' , path . join ( '/Volumes' , mountLocation ) ] ) ;
42+ const unmountResult = spawnSync ( 'hdiutil' , [ 'unmount' , '-force' , path . join ( '/Volumes' , mountLocation ) ] , { timeout : 10000 } ) ;
43+
44+ if ( unmountResult . status !== 0 ) {
45+ throw new Error ( `Failed to unmount ${ mountLocation } : ${ unmountResult . stderr ?. toString ( ) } ` ) ;
46+ }
47+
2648 const pngPath = path . join ( dirPath , 'VolumeIcon.png' ) ;
27- spawnSync ( 'sips' , [ '-s' , 'format' , 'png' , iconPath , '--out' , pngPath ] ) ;
49+ spawnSync ( 'sips' , [ '-s' , 'format' , 'png' , iconPath , '--out' , pngPath ] , { timeout : 10000 } ) ;
2850
2951 // Compare the extracted icon to the snapshot
3052 const image = fs . readFileSync ( pngPath ) ;
0 commit comments