From 1254a80f1aa2cc126a77f07bef159ec7ea5680be Mon Sep 17 00:00:00 2001 From: Anna Henningsen Date: Thu, 4 Dec 2025 20:33:44 +0100 Subject: [PATCH 1/2] chore(cli-repl): add debugging info to async-repl tests The AsyncRepl tests have been flaky for a few runs on the waterfall now, this should help try to figure out why specifically that is the case. --- packages/cli-repl/src/async-repl.spec.ts | 35 +++++++++++++++++------- 1 file changed, 25 insertions(+), 10 deletions(-) diff --git a/packages/cli-repl/src/async-repl.spec.ts b/packages/cli-repl/src/async-repl.spec.ts index 1abf6b480..20f4075e5 100644 --- a/packages/cli-repl/src/async-repl.spec.ts +++ b/packages/cli-repl/src/async-repl.spec.ts @@ -43,22 +43,37 @@ function createDefaultAsyncRepl(extraOpts: Partial = {}): { async function expectInStream( stream: Readable, - substring: string + substring: string, + timeoutMs: number | null = 5000 ): Promise { let content = ''; - let found = false; - for await (const chunk of stream) { - content += chunk; - if (content.includes(substring)) { - found = true; - break; - } - } - expect(found).to.be.true; + let ended = false; + await Promise.race([ + (async () => { + for await (const chunk of stream) { + content += chunk; + if (content.includes(substring)) { + break; + } + } + ended = true; + })(), + ...(timeoutMs + ? [ + delay(timeoutMs).then(() => { + throw new Error( + `Timeout waiting for substring: ${substring}, found so far: ${content} (ended = ${ended})` + ); + }), + ] + : []), + ]); + expect(content).to.include(substring); } describe('AsyncRepl', function () { before(function () { + this.timeout(10000); // nyc adds its own SIGINT listener that annoys use here. process.removeAllListeners('SIGINT'); }); From e47418c813b16fcfdb49c1d7a7cdd1238315661c Mon Sep 17 00:00:00 2001 From: Anna Henningsen Date: Fri, 5 Dec 2025 00:17:37 +0100 Subject: [PATCH 2/2] fixup: no need for extra unhandled rejections --- packages/cli-repl/src/async-repl.spec.ts | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) diff --git a/packages/cli-repl/src/async-repl.spec.ts b/packages/cli-repl/src/async-repl.spec.ts index 20f4075e5..608dc31bd 100644 --- a/packages/cli-repl/src/async-repl.spec.ts +++ b/packages/cli-repl/src/async-repl.spec.ts @@ -48,7 +48,7 @@ async function expectInStream( ): Promise { let content = ''; let ended = false; - await Promise.race([ + const result = await Promise.race([ (async () => { for await (const chunk of stream) { content += chunk; @@ -57,17 +57,15 @@ async function expectInStream( } } ended = true; + return 'normal-completion' as const; })(), - ...(timeoutMs - ? [ - delay(timeoutMs).then(() => { - throw new Error( - `Timeout waiting for substring: ${substring}, found so far: ${content} (ended = ${ended})` - ); - }), - ] - : []), + ...(timeoutMs ? [delay(timeoutMs).then(() => 'timeout' as const)] : []), ]); + if (result === 'timeout') { + throw new Error( + `Timeout waiting for substring: ${substring}, found so far: ${content} (ended = ${ended})` + ); + } expect(content).to.include(substring); }