From 248a30b40b2957d70b304bf0d08b048183a56508 Mon Sep 17 00:00:00 2001 From: DietrichGebert Date: Sun, 21 Jun 2026 01:29:09 +0200 Subject: [PATCH] test: simplify hooks temp-dir cleanup to a one-line exit handler (#221) #213 guarded cleanup with a flag + named function + process.once. But fs.rmSync with force:true already no-ops on a missing path, so the guard and the explicit end-of-file call are unnecessary. Collapse to a single process.on('exit') handler. Refs #204 Co-authored-by: Claude Opus 4.8 --- tests/hooks.test.js | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) diff --git a/tests/hooks.test.js b/tests/hooks.test.js index 59df610..22580e8 100644 --- a/tests/hooks.test.js +++ b/tests/hooks.test.js @@ -21,13 +21,8 @@ function run(script, env, input = '') { delete process.env.CLAUDE_CONFIG_DIR; const temp = fs.mkdtempSync(path.join(os.tmpdir(), 'ponytail-hooks-')); -let cleanedTemp = false; -function cleanupTemp() { - if (cleanedTemp) return; - cleanedTemp = true; - fs.rmSync(temp, { recursive: true, force: true }); -} -process.once('exit', cleanupTemp); +// Runs on normal exit and on assertion-throw exit; force makes it idempotent. +process.on('exit', () => fs.rmSync(temp, { recursive: true, force: true })); const home = path.join(temp, 'home'); const pluginData = path.join(temp, 'plugin-data'); @@ -163,5 +158,4 @@ assert.equal( output = JSON.parse(result.stdout); assert.deepEqual(output, {}); -cleanupTemp(); console.log('hook compatibility checks passed');