From 3148fad1a1cc9bbdd02c90911c98b4ee6746e24b Mon Sep 17 00:00:00 2001 From: Michael Glass Date: Mon, 31 Aug 2026 16:38:19 +0200 Subject: [PATCH] Test drain directly drain() is public on SerialBatches but was only exercised through shutdown. Cover it on its own: it waits for in-flight work and leaves the queue open, so a shutdown can drain before the watchers flush and still have that work accepted, and it returns immediately when nothing is running. Co-Authored-By: Claude Opus 5 Claude-Session: https://claude.ai/code/session_01Lcj4iQ3fBxMwAu2rf4zLbC --- .../src/utils/serial-batches.test.ts | 33 +++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/packages/@tailwindcss-cli/src/utils/serial-batches.test.ts b/packages/@tailwindcss-cli/src/utils/serial-batches.test.ts index a37455bf8..c7adb77b9 100644 --- a/packages/@tailwindcss-cli/src/utils/serial-batches.test.ts +++ b/packages/@tailwindcss-cli/src/utils/serial-batches.test.ts @@ -153,3 +153,36 @@ it('reports a rejected initial barrier once and settles', async () => { expect(calls).toEqual([]) expect(errors).toEqual([new Error('initial build failed')]) }) + +it('drains in-flight work but stays open for more', async () => { + let release!: () => void + let canFinish = new Promise((resolve) => (release = resolve)) + let calls: string[][] = [] + let queue = serializeBatches(async (batch) => { + calls.push(batch) + if (calls.length === 1) await canFinish + }) + + void queue.push(['first']) + await Promise.resolve() + + let drained = queue.drain() + release() + await drained + expect(calls).toEqual([['first']]) + + // Draining must not close the queue — a shutdown drains before the watchers + // have flushed what they collected, and that work still has to be accepted. + await queue.push(['after-drain']) + expect(calls).toEqual([['first'], ['after-drain']]) +}) + +it('drain returns immediately when nothing is in flight', async () => { + let calls: string[][] = [] + let queue = serializeBatches(async (batch) => { + calls.push(batch) + }) + + await queue.drain() + expect(calls).toEqual([]) +})