Skip to content

Commit e47418c

Browse files
committed
fixup: no need for extra unhandled rejections
1 parent 1254a80 commit e47418c

File tree

1 file changed

+8
-10
lines changed

1 file changed

+8
-10
lines changed

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

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ async function expectInStream(
4848
): Promise<void> {
4949
let content = '';
5050
let ended = false;
51-
await Promise.race([
51+
const result = await Promise.race([
5252
(async () => {
5353
for await (const chunk of stream) {
5454
content += chunk;
@@ -57,17 +57,15 @@ async function expectInStream(
5757
}
5858
}
5959
ended = true;
60+
return 'normal-completion' as const;
6061
})(),
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-
: []),
62+
...(timeoutMs ? [delay(timeoutMs).then(() => 'timeout' as const)] : []),
7063
]);
64+
if (result === 'timeout') {
65+
throw new Error(
66+
`Timeout waiting for substring: ${substring}, found so far: ${content} (ended = ${ended})`
67+
);
68+
}
7169
expect(content).to.include(substring);
7270
}
7371

0 commit comments

Comments
 (0)