@@ -6,6 +6,7 @@ const BREAK_MESSAGE = new RegExp('(?:' + [
66 'assert' , 'break' , 'break on start' , 'debugCommand' ,
77 'exception' , 'other' , 'promiseRejection' , 'step' ,
88] . join ( '|' ) + ') in' , 'i' ) ;
9+ const NOT_PAUSED_MESSAGE = / r e q u i r e s e x e c u t i o n t o b e p a u s e d / i;
910
1011let TIMEOUT = common . platformTimeout ( 10000 ) ;
1112// Some macOS and Windows machines require more time to receive the outputs from the client.
@@ -56,7 +57,7 @@ function startCLI(args, flags = [], spawnOpts = {}, opts = { randomPort: true })
5657 return output ;
5758 } ,
5859
59- waitFor ( pattern ) {
60+ waitFor ( pattern , offset = 0 , timeout = TIMEOUT ) {
6061 function checkPattern ( str ) {
6162 if ( Array . isArray ( pattern ) ) {
6263 return pattern . every ( ( p ) => p . test ( str ) ) ;
@@ -66,9 +67,10 @@ function startCLI(args, flags = [], spawnOpts = {}, opts = { randomPort: true })
6667
6768 return new Promise ( ( resolve , reject ) => {
6869 function checkOutput ( ) {
69- if ( checkPattern ( getOutput ( ) ) ) {
70+ const output = getOutput ( ) . slice ( offset ) ;
71+ if ( checkPattern ( output ) ) {
7072 tearDown ( ) ;
71- resolve ( ) ;
73+ resolve ( output ) ;
7274 }
7375 }
7476
@@ -89,12 +91,12 @@ function startCLI(args, flags = [], spawnOpts = {}, opts = { randomPort: true })
8991 }
9092
9193 // Capture stack trace here to show where waitFor was called from when it times out.
92- const timeoutErr = new Error ( `Timeout (${ TIMEOUT } ) while waiting for ${ pattern } ` ) ;
94+ const timeoutErr = new Error ( `Timeout (${ timeout } ) while waiting for ${ pattern } ` ) ;
9395 const timer = setTimeout ( ( ) => {
9496 tearDown ( ) ;
9597 timeoutErr . output = this . output ;
9698 reject ( timeoutErr ) ;
97- } , TIMEOUT ) ;
99+ } , timeout ) ;
98100
99101 function tearDown ( ) {
100102 clearTimeout ( timer ) ;
@@ -108,16 +110,44 @@ function startCLI(args, flags = [], spawnOpts = {}, opts = { randomPort: true })
108110 } ) ;
109111 } ,
110112
111- waitForPrompt ( ) {
112- return this . waitFor ( / > \s + $ / ) ;
113+ async waitForPaused ( ) {
114+ const deadline = Date . now ( ) + TIMEOUT ;
115+
116+ function getRemainingTime ( ) {
117+ return deadline - Date . now ( ) ;
118+ }
119+
120+ await this . waitForPrompt ( getRemainingTime ( ) ) ;
121+
122+ while ( getRemainingTime ( ) > 0 ) {
123+ const offset = this . output . length ;
124+ this . writeLine ( 'list()' , false ) ;
125+ const output = await this . waitFor ( / > \s + $ / , offset , getRemainingTime ( ) ) ;
126+
127+ if ( ! NOT_PAUSED_MESSAGE . test ( output ) ) {
128+ return ;
129+ }
130+
131+ await new Promise ( ( resolve ) =>
132+ setTimeout ( resolve , Math . min ( 100 , getRemainingTime ( ) ) ) ) ;
133+ }
134+
135+ const timeoutErr =
136+ new Error ( `Timeout (${ TIMEOUT } ) while waiting for a debugger pause state` ) ;
137+ timeoutErr . output = this . output ;
138+ throw timeoutErr ;
139+ } ,
140+
141+ waitForPrompt ( timeout = TIMEOUT ) {
142+ return this . waitFor ( / > \s + $ / , 0 , timeout ) ;
113143 } ,
114144
115145 async waitForInitialBreak ( ) {
116- await this . waitFor ( / b r e a k (?: o n s t a r t ) ? i n / i ) ;
146+ await this . waitForPaused ( ) ;
117147
118148 if ( isPreBreak ( this . output ) ) {
119149 await this . command ( 'next' , false ) ;
120- return this . waitFor ( / b r e a k i n / ) ;
150+ await this . waitForPaused ( ) ;
121151 }
122152 } ,
123153
0 commit comments