@@ -16,6 +16,10 @@ const BREAK_MESSAGE = new RegExp('(?:' + [
1616 'exception' , 'other' , 'promiseRejection' ,
1717] . join ( '|' ) + ') in' , 'i' ) ;
1818
19+ function isPreBreak ( output ) {
20+ return / B r e a k o n s t a r t / . test ( output ) && / 1 \( f u n c t i o n \( e x p o r t s / . test ( output ) ;
21+ }
22+
1923function startCLI ( args , flags = [ ] ) {
2024 const child = spawn ( process . execPath , [ ...flags , CLI , ...args ] ) ;
2125 let isFirstStdoutChunk = true ;
@@ -101,13 +105,26 @@ function startCLI(args, flags = []) {
101105 waitForInitialBreak ( timeout = 2000 ) {
102106 return this . waitFor ( / b r e a k (?: o n s t a r t ) ? i n / i, timeout )
103107 . then ( ( ) => {
104- if ( / B r e a k o n s t a r t / . test ( this . output ) ) {
108+ if ( isPreBreak ( this . output ) ) {
109+ console . log ( { output : this . output } ) ;
105110 return this . command ( 'next' , false )
106111 . then ( ( ) => this . waitFor ( / b r e a k i n / , timeout ) ) ;
107112 }
108113 } ) ;
109114 } ,
110115
116+ get breakInfo ( ) {
117+ const output = this . output ;
118+ const breakMatch =
119+ output . match ( / b r e a k (?: o n s t a r t ) ? i n ( [ ^ \n ] + ) : ( \d + ) \n / i) ;
120+
121+ if ( breakMatch === null ) {
122+ throw new Error (
123+ `Could not find breakpoint info in ${ JSON . stringify ( output ) } ` ) ;
124+ }
125+ return { filename : breakMatch [ 1 ] , line : + breakMatch [ 2 ] } ;
126+ } ,
127+
111128 ctrlC ( ) {
112129 return this . command ( '.interrupt' ) ;
113130 } ,
@@ -127,19 +144,24 @@ function startCLI(args, flags = []) {
127144 . map ( ( match ) => + match [ 1 ] ) ;
128145 } ,
129146
130- command ( input , flush = true ) {
147+ writeLine ( input , flush = true ) {
131148 if ( flush ) {
132149 this . flushOutput ( ) ;
133150 }
151+ if ( process . env . VERBOSE === '1' ) {
152+ process . stderr . write ( `< ${ input } \n` ) ;
153+ }
134154 child . stdin . write ( input ) ;
135155 child . stdin . write ( '\n' ) ;
156+ } ,
157+
158+ command ( input , flush = true ) {
159+ this . writeLine ( input , flush ) ;
136160 return this . waitForPrompt ( ) ;
137161 } ,
138162
139163 stepCommand ( input ) {
140- this . flushOutput ( ) ;
141- child . stdin . write ( input ) ;
142- child . stdin . write ( '\n' ) ;
164+ this . writeLine ( input , true ) ;
143165 return this
144166 . waitFor ( BREAK_MESSAGE )
145167 . then ( ( ) => this . waitForPrompt ( ) ) ;
0 commit comments