@@ -37,9 +37,22 @@ describe("E2E: connect command", () => {
3737 await broker . stop ( ) ;
3838 } ) ;
3939
40+ let stdout = "" ;
41+
42+ async function waitFor ( condition ) {
43+ if ( typeof condition === "string" ) {
44+ condition = [ condition ] ;
45+ }
46+ for ( const cond of condition ) {
47+ await vi . waitFor ( ( ) => stdout . includes ( cond ) || Promise . reject ( new Error ( ) ) , {
48+ timeout : 5000
49+ } ) ;
50+ }
51+ stdout = "" ;
52+ }
53+
4054 it ( "should connect to the broker" , async ( ) => {
4155 const rs = new Stream . Readable ( { read ( ) { } } ) ;
42- let stdout = "" ;
4356 new Promise ( async ( ) => {
4457 for await ( const line of execa ( {
4558 input : rs
@@ -49,55 +62,29 @@ describe("E2E: connect command", () => {
4962 }
5063 } ) ;
5164
52- await vi . waitFor (
53- ( ) =>
54- stdout . includes ( "ServiceBroker with 1 service(s) started successfully" ) ||
55- Promise . reject ( new Error ( ) ) ,
56- { timeout : 5000 }
57- ) ;
58- stdout = "" ;
65+ await waitFor ( "ServiceBroker with 1 service(s) started successfully" ) ;
5966
6067 rs . push ( "nodes\n" ) ;
61- await vi . waitFor ( ( ) => stdout . includes ( "cli-client (*)" ) || Promise . reject ( new Error ( ) ) , {
62- timeout : 5000
63- } ) ;
64- await vi . waitFor ( ( ) => stdout . includes ( "cli-server" ) || Promise . reject ( new Error ( ) ) , {
65- timeout : 5000
66- } ) ;
67- stdout = "" ;
68+ await waitFor ( [ "cli-client (*)" , "cli-server" ] ) ;
6869
6970 rs . push ( "call greeter.welcome --name Icebob\n" ) ;
70- await vi . waitFor ( ( ) => stdout . includes ( "Hello Icebob!" ) || Promise . reject ( new Error ( ) ) , {
71- timeout : 5000
72- } ) ;
73- stdout = "" ;
71+ await waitFor ( "Hello Icebob!" ) ;
7472
7573 // Test the custom commands
7674 rs . push ( "hello\n" ) ;
77- await vi . waitFor ( ( ) => stdout . includes ( "Hello!" ) || Promise . reject ( new Error ( ) ) , {
78- timeout : 5000
79- } ) ;
80- stdout = "" ;
75+ await waitFor ( "Hello!" ) ;
8176
8277 // Test the custom commands
8378 rs . push ( "hi\n" ) ;
84- await vi . waitFor ( ( ) => stdout . includes ( "Hi!" ) || Promise . reject ( new Error ( ) ) , {
85- timeout : 5000
86- } ) ;
87- stdout = "" ;
79+ await waitFor ( "Hi!" ) ;
8880
8981 // Test the custom commands
9082 rs . push ( "bye\n" ) ;
91- await vi . waitFor ( ( ) => stdout . includes ( "Bye!" ) || Promise . reject ( new Error ( ) ) , {
92- timeout : 5000
93- } ) ;
94- stdout = "" ;
83+ await waitFor ( "Bye!" ) ;
9584
9685 rs . push ( "q\n" ) ;
9786 rs . push ( null ) ;
98- await vi . waitFor ( ( ) => stdout . includes ( "Good bye." ) || Promise . reject ( new Error ( ) ) , {
99- timeout : 5000
100- } ) ;
87+ await waitFor ( "Good bye." ) ;
10188
10289 expect ( true ) . toBe ( true ) ;
10390 } ) ;
0 commit comments