From c362547a718bef230e24fd16cfd9f40448055efe Mon Sep 17 00:00:00 2001 From: "detail-app[bot]" Date: Fri, 4 Sep 2026 03:05:38 +0000 Subject: [PATCH] test: synchronize split-write test via stdin instead of timer --- apps/dokploy/__test__/utils/spawnAsync.test.ts | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/apps/dokploy/__test__/utils/spawnAsync.test.ts b/apps/dokploy/__test__/utils/spawnAsync.test.ts index 3919d136d..afd9aa110 100644 --- a/apps/dokploy/__test__/utils/spawnAsync.test.ts +++ b/apps/dokploy/__test__/utils/spawnAsync.test.ts @@ -26,10 +26,14 @@ const hasReplacement = (s: string) => s.includes(REPLACEMENT); describe("spawnAsync streaming UTF-8 decoding", () => { it("decodes a multi-byte sequence split across two data events", async () => { + // The child writes the first byte, then waits for stdin to close before + // writing the remaining bytes. This ensures the two writes arrive as + // separate data events without relying on a fixed-duration timer. const file = writeScript( "split", `process.stdout.write(Buffer.from([0xe2])); - setTimeout(() => process.stdout.write(Buffer.from([0x94, 0x80])), 50);`, + process.stdin.resume(); + process.stdin.once("end", () => process.stdout.write(Buffer.from([0x94, 0x80])));`, ); let streamed = ""; const chunkByteSizes: number[] = []; @@ -38,6 +42,10 @@ describe("spawnAsync streaming UTF-8 decoding", () => { }); result.child.stdout?.on("data", (b: Buffer) => { chunkByteSizes.push(b.length); + // After the first byte arrives, signal the child to send the rest. + if (chunkByteSizes.length === 1) { + result.child.stdin?.end(); + } }); const captured = await result; expect(chunkByteSizes.length).toBeGreaterThanOrEqual(2);