fix: test in mac (#14712)

#### PR Dependency Tree


* **PR #14712** 👈

This tree was auto-generated by
[Charcoal](https://github.com/danerwilliams/charcoal)

<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->

## Summary by CodeRabbit

* **Chores**
* Enhanced Electron test environment cleanup with improved termination
signal handling and child process resource management.

<!-- end of auto-generated comment: release notes by coderabbit.ai -->
This commit is contained in:
DarkSky
2026-03-24 09:59:10 +08:00
committed by GitHub
parent 9b56a05159
commit 166372cc3e
+18 -5
View File
@@ -194,25 +194,38 @@ const cleanupElectronApp = async (electronApp: ElectronApplication) => {
const closeWithTimeout = async () => {
const closeEvent = waitForAppClose();
const processExit = waitForProcessExit();
const pid = child.pid;
void electronApp.close().catch(() => {});
const controller = new AbortController();
const killAfterTimeout = setTimeout(10_000, undefined, {
signal: controller.signal,
})
.then(() => {
.then(async () => {
if (child.exitCode !== null || child.signalCode !== null) return;
if (pid !== undefined) {
await treeKillAsync(pid, 'SIGKILL').catch(() => {
killProcess();
});
return;
}
killProcess();
})
.catch(error => {
if (error instanceof Error && error.name === 'AbortError') {
return;
}
if (error instanceof Error && error.name === 'AbortError') return;
throw error;
});
try {
await Promise.all([electronApp.close().catch(() => {}), closeEvent]);
await Promise.race([closeEvent, processExit, killAfterTimeout]);
} finally {
controller.abort();
await killAfterTimeout;
await Promise.race([closeEvent, processExit, setTimeout(5_000)]).catch(
() => {}
);
releaseChildProcessHandles(child);
}
};