File tree Expand file tree Collapse file tree 1 file changed +22
-9
lines changed
Expand file tree Collapse file tree 1 file changed +22
-9
lines changed Original file line number Diff line number Diff line change @@ -43,22 +43,35 @@ function createDefaultAsyncRepl(extraOpts: Partial<AsyncREPLOptions> = {}): {
4343
4444async 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
6072describe ( '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 } ) ;
You can’t perform that action at this time.
0 commit comments