Skip to content

Commit d45e818

Browse files
committed
serial tests
1 parent 8cbf75c commit d45e818

File tree

2 files changed

+29
-3
lines changed

2 files changed

+29
-3
lines changed

package.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,5 +57,9 @@
5757
"ava": "^6.1.1",
5858
"jest-image-snapshot": "^6.5.1",
5959
"xo": "^0.56.0"
60+
},
61+
"ava": {
62+
"serial": true,
63+
"timeout": "30s"
6064
}
6165
}

test.js

Lines changed: 25 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,21 +10,43 @@ const { configureToMatchImageSnapshot } = jestImageSnapshot;
1010

1111
const __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) */
1426
const 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

Comments
 (0)