File tree Expand file tree Collapse file tree 1 file changed +25
-10
lines changed Expand file tree Collapse file tree 1 file changed +25
-10
lines changed Original file line number Diff line number Diff line change @@ -43,22 +43,37 @@ 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- }
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
6074describe ( '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 } ) ;
You can’t perform that action at this time.
0 commit comments