From dac918379791add082e0a24d8dcd6c570fd48d92 Mon Sep 17 00:00:00 2001 From: kikootwo Date: Fri, 16 Jan 2026 13:52:00 -0500 Subject: [PATCH] Replace setImmediate with queueMicrotask in tests Updated ebook-scraper tests to use queueMicrotask instead of setImmediate for emitting 'finish' events. This change ensures microtasks run before timers, reducing race conditions with download timeouts. --- tests/services/ebook-scraper.test.ts | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/tests/services/ebook-scraper.test.ts b/tests/services/ebook-scraper.test.ts index 34733aa..ea73524 100644 --- a/tests/services/ebook-scraper.test.ts +++ b/tests/services/ebook-scraper.test.ts @@ -144,8 +144,8 @@ describe('E-book sidecar', () => { return { data: { pipe: (dest: EventEmitter) => { - // Emit synchronously to avoid race condition with download timeout - setImmediate(() => dest.emit('finish')); + // Use microtask to emit before timers run (avoids race with download timeout) + queueMicrotask(() => dest.emit('finish')); return dest; }, }, @@ -193,8 +193,8 @@ describe('E-book sidecar', () => { return { data: { pipe: (dest: EventEmitter) => { - // Emit synchronously to avoid race condition with download timeout - setImmediate(() => dest.emit('finish')); + // Use microtask to emit before timers run (avoids race with download timeout) + queueMicrotask(() => dest.emit('finish')); return dest; }, }, @@ -337,8 +337,8 @@ describe('E-book sidecar', () => { return { data: { pipe: (dest: EventEmitter) => { - // Emit synchronously to avoid race condition with download timeout - setImmediate(() => dest.emit('finish')); + // Use microtask to emit before timers run (avoids race with download timeout) + queueMicrotask(() => dest.emit('finish')); return dest; }, }, @@ -622,8 +622,8 @@ describe('E-book sidecar', () => { return { data: { pipe: (dest: EventEmitter) => { - // Emit synchronously to avoid race condition with download timeout - setImmediate(() => dest.emit('finish')); + // Use microtask to emit before timers run (avoids race with download timeout) + queueMicrotask(() => dest.emit('finish')); return dest; }, },