Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 22 additions & 9 deletions packages/cli-repl/src/async-repl.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,22 +43,35 @@ function createDefaultAsyncRepl(extraOpts: Partial<AsyncREPLOptions> = {}): {

async function expectInStream(
stream: Readable,
substring: string
substring: string,
timeoutMs: number | null = 5000
): Promise<void> {
let content = '';
let found = false;
for await (const chunk of stream) {
content += chunk;
if (content.includes(substring)) {
found = true;
break;
}
let ended = false;
const result = await Promise.race([
(async () => {
for await (const chunk of stream) {
content += chunk;
if (content.includes(substring)) {
break;
}
}
ended = true;
return 'normal-completion' as const;
})(),
...(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(found).to.be.true;
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');
});
Expand Down
Loading