diff --git a/src/plugins/runtime.test.ts b/src/plugins/runtime.test.ts index e43feb19b32..e3003f15ea7 100644 --- a/src/plugins/runtime.test.ts +++ b/src/plugins/runtime.test.ts @@ -69,12 +69,19 @@ function expectRouteRegistryState(params: { setup: () => void; assert: () => voi } async function waitForCleanupSignal(signal: Promise, label: string): Promise { - await Promise.race([ - signal, - new Promise((_, reject) => { - setTimeout(() => reject(new Error(`Timed out waiting for ${label}`)), 500); - }), - ]); + let timer: NodeJS.Timeout | undefined; + try { + await Promise.race([ + signal, + new Promise((_, reject) => { + timer = setTimeout(() => reject(new Error(`Timed out waiting for ${label}`)), 500); + }), + ]); + } finally { + if (timer) { + clearTimeout(timer); + } + } } describe("plugin runtime route registry", () => {