Skip to content

Commit 1254a80

Browse files
committed
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.
1 parent 76e35ca commit 1254a80

File tree

1 file changed

+25
-10
lines changed

1 file changed

+25
-10
lines changed

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

Lines changed: 25 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -43,22 +43,37 @@ 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-
}
56-
}
57-
expect(found).to.be.true;
50+
let ended = false;
51+
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+
})(),
61+
...(timeoutMs
62+
? [
63+
delay(timeoutMs).then(() => {
64+
throw new Error(
65+
`Timeout waiting for substring: ${substring}, found so far: ${content} (ended = ${ended})`
66+
);
67+
}),
68+
]
69+
: []),
70+
]);
71+
expect(content).to.include(substring);
5872
}
5973

6074
describe('AsyncRepl', function () {
6175
before(function () {
76+
this.timeout(10000);
6277
// nyc adds its own SIGINT listener that annoys use here.
6378
process.removeAllListeners('SIGINT');
6479
});

0 commit comments

Comments
 (0)