Skip to content

Turn any idea, plan, or codebase into a beautiful interactive diagram. An agent skill for Claude Code, Codex, and more.

test: wait for Chrome before WebM cleanup (#26)

tt-a1i6707ddeadb90
diff --git a/archify/test/webm-artifact.smoke.mjs b/archify/test/webm-artifact.smoke.mjs
index 178dec83..417b359a 100644
--- a/archify/test/webm-artifact.smoke.mjs
+++ b/archify/test/webm-artifact.smoke.mjs
@@ -1,5 +1,6 @@
import assert from 'node:assert/strict';
import { execFileSync, spawn } from 'node:child_process';
+import { once } from 'node:events';
import fs from 'node:fs';
import net from 'node:net';
import os from 'node:os';
@@ -58,6 +59,14 @@ function delay(ms) {
return new Promise((resolve) => setTimeout(resolve, ms));
}
+async function waitForExit(child, timeoutMs) {
+ if (child.exitCode !== null || child.signalCode !== null) return true;
+ return Promise.race([
+ once(child, 'exit').then(() => true),
+ delay(timeoutMs).then(() => false),
+ ]);
+}
+
async function withTimeout(promise, ms, label) {
let timer;
try {
@@ -220,9 +229,9 @@ try {
if (cdp && targetId) await withTimeout(cdp.send('Target.closeTarget', { targetId }), 500, 'target close').catch(() => {});
if (cdp) cdp.socket.close();
chromeProcess.kill('SIGTERM');
- await Promise.race([
- new Promise((resolve) => chromeProcess.once('exit', resolve)),
- delay(1000).then(() => chromeProcess.kill('SIGKILL')),
- ]);
- fs.rmSync(tmp, { recursive: true, force: true });
+ if (!(await waitForExit(chromeProcess, 1000))) {
+ chromeProcess.kill('SIGKILL');
+ await waitForExit(chromeProcess, 1000);
+ }
+ fs.rmSync(tmp, { recursive: true, force: true, maxRetries: 5, retryDelay: 100 });
}