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.
This commit is contained in:
kikootwo
2026-01-16 13:52:00 -05:00
parent 3a9ae4a439
commit dac9183797
+8 -8
View File
@@ -144,8 +144,8 @@ describe('E-book sidecar', () => {
return { return {
data: { data: {
pipe: (dest: EventEmitter) => { pipe: (dest: EventEmitter) => {
// Emit synchronously to avoid race condition with download timeout // Use microtask to emit before timers run (avoids race with download timeout)
setImmediate(() => dest.emit('finish')); queueMicrotask(() => dest.emit('finish'));
return dest; return dest;
}, },
}, },
@@ -193,8 +193,8 @@ describe('E-book sidecar', () => {
return { return {
data: { data: {
pipe: (dest: EventEmitter) => { pipe: (dest: EventEmitter) => {
// Emit synchronously to avoid race condition with download timeout // Use microtask to emit before timers run (avoids race with download timeout)
setImmediate(() => dest.emit('finish')); queueMicrotask(() => dest.emit('finish'));
return dest; return dest;
}, },
}, },
@@ -337,8 +337,8 @@ describe('E-book sidecar', () => {
return { return {
data: { data: {
pipe: (dest: EventEmitter) => { pipe: (dest: EventEmitter) => {
// Emit synchronously to avoid race condition with download timeout // Use microtask to emit before timers run (avoids race with download timeout)
setImmediate(() => dest.emit('finish')); queueMicrotask(() => dest.emit('finish'));
return dest; return dest;
}, },
}, },
@@ -622,8 +622,8 @@ describe('E-book sidecar', () => {
return { return {
data: { data: {
pipe: (dest: EventEmitter) => { pipe: (dest: EventEmitter) => {
// Emit synchronously to avoid race condition with download timeout // Use microtask to emit before timers run (avoids race with download timeout)
setImmediate(() => dest.emit('finish')); queueMicrotask(() => dest.emit('finish'));
return dest; return dest;
}, },
}, },