@@ -71,16 +71,38 @@ test("starting on a random port", async (t) => {
7171 error : t . mock . fn ( ) ,
7272 fatal : t . mock . fn ( ) ,
7373 } ;
74- devTool = new DevTool ( { logger, port : 0 } ) ;
74+ const a = new DevTool ( { logger, port : 4321 } ) ;
75+ const b = new DevTool ( { logger, port : 4321 } ) ;
76+ await a . start ( ) ;
77+ await b . start ( ) ;
78+ await a . stop ( ) ;
79+ await b . stop ( ) ;
80+
81+ assert . match ( logger . trace . mock . calls [ 0 ] . arguments [ 0 ] , / d e v t o o l s e r v e r s t a r t e d o n p o r t " 4 3 2 1 " / ) ;
82+ assert . match ( logger . trace . mock . calls [ 2 ] . arguments [ 0 ] , / d e v t o o l s e r v e r s t a r t e d o n p o r t " / ) ;
83+ assert . notEqual ( logger . trace . mock . calls [ 2 ] . arguments [ 0 ] , "undefined" ) ;
84+ assert . notEqual ( logger . trace . mock . calls [ 2 ] . arguments [ 0 ] , "null" ) ;
85+ assert . notEqual ( logger . trace . mock . calls [ 2 ] . arguments [ 0 ] , "8172" ) ;
86+ assert . equal ( logger . trace . mock . calls . length , 5 ) ;
87+ } ) ;
88+
89+ test ( "assigns a random port if the specified port isn't available" , async ( t ) => {
90+ const logger = {
91+ trace : t . mock . fn ( ) ,
92+ debug : t . mock . fn ( ) ,
93+ info : t . mock . fn ( ) ,
94+ warn : t . mock . fn ( ) ,
95+ error : t . mock . fn ( ) ,
96+ fatal : t . mock . fn ( ) ,
97+ } ;
98+ devTool = new DevTool ( { logger } ) ;
7599 devTool . register ( podlet ) ;
76100
77101 await devTool . start ( ) ;
78102 await devTool . stop ( ) ;
79103
80- assert . match ( logger . trace . mock . calls [ 0 ] . arguments [ 0 ] , / d e v t o o l s e r v e r s t a r t e d o n p o r t " / ) ;
81- assert . notEqual ( logger . trace . mock . calls [ 0 ] . arguments [ 0 ] , "undefined" ) ;
82- assert . notEqual ( logger . trace . mock . calls [ 0 ] . arguments [ 0 ] , "null" ) ;
83- assert . notEqual ( logger . trace . mock . calls [ 0 ] . arguments [ 0 ] , "8172" ) ;
104+ assert . match ( logger . trace . mock . calls [ 0 ] . arguments [ 0 ] , / d e v t o o l s e r v e r s t a r t e d o n p o r t " 8 1 7 2 " \( i n / ) ;
105+ assert . match ( logger . trace . mock . calls [ 1 ] . arguments [ 0 ] , / d e v t o o l s e r v e r s h u t d o w n i n / ) ;
84106 assert . equal ( logger . trace . mock . calls . length , 2 ) ;
85107} ) ;
86108
0 commit comments