Skip to content

Commit 4958dff

Browse files
authored
chore(cli-repl): add debugging info to async-repl tests (#2611)
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.
1 parent 76e35ca commit 4958dff

File tree

1 file changed

+22
-9
lines changed

1 file changed

+22
-9
lines changed

packages/cli-repl/src/async-repl.spec.ts

Lines changed: 22 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -43,22 +43,35 @@ function createDefaultAsyncRepl(extraOpts: Partial<AsyncREPLOptions> = {}): {
4343

4444
async function expectInStream(
4545
stream: Readable,
46-
substring: string
46+
substring: string,
47+
timeoutMs: number | null = 5000
4748
): Promise<void> {
4849
let content = '';
49-
let found = false;
50-
for await (const chunk of stream) {
51-
content += chunk;
52-
if (content.includes(substring)) {
53-
found = true;
54-
break;
55-
}
50+
let ended = false;
51+
const result = await Promise.race([
52+
(async () => {
53+
for await (const chunk of stream) {
54+
content += chunk;
55+
if (content.includes(substring)) {
56+
break;
57+
}
58+
}
59+
ended = true;
60+
return 'normal-completion' as const;
61+
})(),
62+
...(timeoutMs ? [delay(timeoutMs).then(() => 'timeout' as const)] : []),
63+
]);
64+
if (result === 'timeout') {
65+
throw new Error(
66+
`Timeout waiting for substring: ${substring}, found so far: ${content} (ended = ${ended})`
67+
);
5668
}
57-
expect(found).to.be.true;
69+
expect(content).to.include(substring);
5870
}
5971

6072
describe('AsyncRepl', function () {
6173
before(function () {
74+
this.timeout(10000);
6275
// nyc adds its own SIGINT listener that annoys use here.
6376
process.removeAllListeners('SIGINT');
6477
});

0 commit comments

Comments
 (0)