1414 * limitations under the License.
1515 */
1616
17+ import * as apiTypes from '../src/types/api-types' ;
18+
1719import * as assert from 'assert' ;
1820import * as util from 'util' ;
1921import * as _ from 'lodash' ; // for _.find. Can't use ES6 yet.
2022import * as cp from 'child_process' ;
2123import * as semver from 'semver' ;
2224const promisifyAll = require ( '@google-cloud/common' ) . util . promisifyAll ;
2325import { Debug } from '../src/debug' ;
26+ import { Debuggee } from '../src/debuggee' ;
2427import { Debugger } from '../test/debugger' ;
2528
2629const CLUSTER_WORKERS = 3 ;
@@ -29,18 +32,24 @@ const CLUSTER_WORKERS = 3;
2932const FILENAME = 'build/test/fixtures/fib.js' ;
3033
3134const delay = function ( delayTimeMS : number ) : Promise < void > {
32- return new Promise ( function ( resolve , reject ) {
35+ // TODO: Determine if the reject parameter should be used.
36+ return new Promise ( function ( resolve , _reject ) {
3337 setTimeout ( resolve , delayTimeMS ) ;
3438 } ) ;
3539} ;
3640
41+ interface Child {
42+ transcript : string ;
43+ process ?: cp . ChildProcess ;
44+ }
45+
3746// This test could take up to 70 seconds.
3847describe ( '@google-cloud/debug end-to-end behavior' , function ( ) {
3948 let api : Debugger ;
4049
41- let debuggeeId : string ;
42- let projectId : string ;
43- let children = [ ] ;
50+ let debuggeeId : string | null ;
51+ let projectId : string | null ;
52+ let children : Child [ ] = [ ] ;
4453
4554 before ( function ( ) {
4655 promisifyAll ( Debugger ) ;
@@ -53,7 +62,8 @@ describe('@google-cloud/debug end-to-end behavior', function () {
5362 let numChildrenReady = 0 ;
5463
5564 // Process a status message sent from a child process.
56- const handler = function ( c ) {
65+ // TODO: Determine if this type signature is correct
66+ const handler = function ( c : { error : Error | null , debuggeeId : string , projectId : string } ) {
5767 console . log ( c ) ;
5868 if ( c . error ) {
5969 reject ( new Error ( 'A child reported the following error: ' + c . error ) ) ;
@@ -80,8 +90,8 @@ describe('@google-cloud/debug end-to-end behavior', function () {
8090 // Handle stdout/stderr output from a child process. More specifically,
8191 // write the child process's output to a transcript.
8292 // Each child has its own transcript.
83- const stdoutHandler = function ( index ) {
84- return function ( chunk ) {
93+ const stdoutHandler = function ( index : number ) {
94+ return function ( chunk : string ) {
8595 children [ index ] . transcript += chunk ;
8696 } ;
8797 } ;
@@ -111,12 +121,13 @@ describe('@google-cloud/debug end-to-end behavior', function () {
111121 // Create a promise for each child that resolves when that child exits.
112122 const childExitPromises = children . map ( function ( child ) {
113123 console . log ( child . transcript ) ;
114- child . process . kill ( ) ;
124+ // TODO: Handle the case when child.process is undefined
125+ ( child . process as any ) . kill ( ) ;
115126 return new Promise ( function ( resolve , reject ) {
116127 const timeout = setTimeout ( function ( ) {
117128 reject ( new Error ( 'A child process failed to exit.' ) ) ;
118129 } , 3000 ) ;
119- child . process . on ( 'exit' , function ( ) {
130+ ( child . process as any ) . on ( 'exit' , function ( ) {
120131 clearTimeout ( timeout ) ;
121132 resolve ( ) ;
122133 } ) ;
@@ -134,39 +145,41 @@ describe('@google-cloud/debug end-to-end behavior', function () {
134145 this . timeout ( 90 * 1000 ) ;
135146 // Kick off promise chain by getting a list of debuggees
136147 // TODO: Determine how to properly specify the signature of listDebuggees
137- return ( api as any ) . listDebuggees ( projectId ) . then ( function ( results ) {
148+ // TODO: Determine if this is the correct signature for `then`
149+ return ( api as any ) . listDebuggees ( projectId ) . then ( function ( results : { [ index : number ] : Debuggee [ ] } ) {
138150 // Check that the debuggee created in this test is among the list of
139151 // debuggees, then list its breakpoints
140-
141- const debuggees = results [ 0 ] ;
152+
153+ const debuggees : Debuggee [ ] = results [ 0 ] ;
142154
143155 console . log ( '-- List of debuggees\n' ,
144156 util . inspect ( debuggees , { depth : null } ) ) ;
145157 assert . ok ( debuggees , 'should get a valid ListDebuggees response' ) ;
146- // TODO: Fix this cast to any.
147- const result = _ . find ( debuggees , function ( d : any ) {
158+ const result = _ . find ( debuggees , function ( d : Debuggee ) {
148159 return d . id === debuggeeId ;
149160 } ) ;
150161 assert . ok ( result , 'should find the debuggee we just registered' ) ;
151162 // TODO: Determine how to properly specify the signature of listDebuggees
152163 return ( api as any ) . listBreakpoints ( debuggeeId ) ;
153- } ) . then ( function ( results ) {
164+ // TODO: Determine if this type signature is correct.
165+ } ) . then ( function ( results : { [ index : number ] : apiTypes . Breakpoint [ ] } ) {
154166 // Delete every breakpoint
155167
156- const breakpoints = results [ 0 ] ;
168+ const breakpoints : apiTypes . Breakpoint [ ] = results [ 0 ] ;
157169
158170 console . log ( '-- List of breakpoints\n' , breakpoints ) ;
159171
160- const promises = breakpoints . map ( function ( breakpoint ) {
172+ const promises = breakpoints . map ( function ( breakpoint : apiTypes . Breakpoint ) {
161173 // TODO: Determine how to properly specify the signature of listDebuggees
162174 return ( api as any ) . deleteBreakpoint ( debuggeeId , breakpoint . id ) ;
163175 } ) ;
164176
165177 return Promise . all ( promises ) ;
166- } ) . then ( function ( results ) {
178+ // TODO: Determine if this type signature is correct
179+ } ) . then ( function ( results : apiTypes . Breakpoint [ ] ) {
167180 // Set a breakpoint at which the debugger should write to a log
168181
169- results . map ( function ( result ) {
182+ results . map ( function ( result : apiTypes . Breakpoint ) {
170183 assert . equal ( result , '' ) ;
171184 } ) ;
172185 console . log ( '-- deleted' ) ;
@@ -181,7 +194,8 @@ describe('@google-cloud/debug end-to-end behavior', function () {
181194 expressions : [ 'o' ] ,
182195 log_message_format : 'o is: $0'
183196 } ) ;
184- } ) . then ( function ( results ) {
197+ // TODO: Determine if this type signature is correct.
198+ } ) . then ( function ( results : apiTypes . Breakpoint [ ] ) {
185199 // Check that the breakpoint was set, and then wait for the log to be
186200 // written to
187201
@@ -190,14 +204,18 @@ describe('@google-cloud/debug end-to-end behavior', function () {
190204 assert . ok ( breakpoint , 'should have set a breakpoint' ) ;
191205 assert . ok ( breakpoint . id , 'breakpoint should have an id' ) ;
192206 assert . ok ( breakpoint . location , 'breakpoint should have a location' ) ;
193- assert . strictEqual ( breakpoint . location . path , FILENAME ) ;
207+ // TODO: Handle the case when breakpoint.location is undefined
208+ assert . strictEqual ( ( breakpoint . location as any ) . path , FILENAME ) ;
194209
195210 console . log ( '-- waiting before checking if the log was written' ) ;
196211 return Promise . all ( [ breakpoint , delay ( 10 * 1000 ) ] ) ;
197- } ) . then ( function ( results ) {
212+ // TODO: Determine if the results parameter should be used.
213+ } ) . then ( function ( _results : apiTypes . Breakpoint [ ] ) {
214+
198215 // Check the contents of the log, but keep the original breakpoint.
199216
200- const breakpoint = results [ 0 ] ;
217+ // TODO: This is never used. Determine if it should be used.
218+ //const breakpoint = results[0];
201219
202220 children . forEach ( function ( child , index ) {
203221 assert ( child . transcript . indexOf ( 'o is: {"a":[1,"hi",true]}' ) !== - 1 ,
@@ -216,7 +234,7 @@ describe('@google-cloud/debug end-to-end behavior', function () {
216234 expressions : [ 'process' ] , // Process for large variable
217235 condition : 'n === 10'
218236 } ) ;
219- } ) . then ( function ( results ) {
237+ } ) . then ( function ( results : apiTypes . Breakpoint [ ] ) {
220238 // Check that the breakpoint was set, and then wait for the breakpoint to
221239 // be hit
222240
@@ -226,19 +244,20 @@ describe('@google-cloud/debug end-to-end behavior', function () {
226244 assert . ok ( breakpoint , 'should have set a breakpoint' ) ;
227245 assert . ok ( breakpoint . id , 'breakpoint should have an id' ) ;
228246 assert . ok ( breakpoint . location , 'breakpoint should have a location' ) ;
229- assert . strictEqual ( breakpoint . location . path , FILENAME ) ;
247+ // TODO: Handle the case when breakpoint.location is undefined
248+ assert . strictEqual ( ( breakpoint . location as any ) . path , FILENAME ) ;
230249
231250 console . log ( '-- waiting before checking if breakpoint was hit' ) ;
232251 return Promise . all ( [ breakpoint , delay ( 10 * 1000 ) ] ) ;
233- } ) . then ( function ( results ) {
252+ } ) . then ( function ( results : apiTypes . Breakpoint [ ] ) {
234253 // Get the breakpoint
235254
236255 const breakpoint = results [ 0 ] ;
237256
238257 console . log ( '-- now checking if the breakpoint was hit' ) ;
239258 // TODO: Determine how to properly specify the signature of listDebuggees
240259 return ( api as any ) . getBreakpoint ( debuggeeId , breakpoint . id ) ;
241- } ) . then ( function ( results ) {
260+ } ) . then ( function ( results : apiTypes . Breakpoint [ ] ) {
242261 // Check that the breakpoint was hit and contains the correct information,
243262 // which ends the test
244263
@@ -260,7 +279,8 @@ describe('@google-cloud/debug end-to-end behavior', function () {
260279 arg = _ . find ( top . arguments , { name : 'n' } ) ;
261280 }
262281 assert . ok ( arg , 'should find the n argument' ) ;
263- assert . strictEqual ( arg . value , '10' ) ;
282+ // TODO: Handle the case when arg is undefined
283+ assert . strictEqual ( ( arg as any ) . value , '10' ) ;
264284 console . log ( '-- checking log point was hit again' ) ;
265285 children . forEach ( function ( child ) {
266286 const count = ( child . transcript
@@ -291,7 +311,8 @@ describe('@google-cloud/debug end-to-end behavior', function () {
291311 this . timeout ( 15 * 1000 ) ;
292312 // Kick off promise chain by getting a list of debuggees
293313 // TODO: Determine how to properly specify the signature of listDebuggees
294- return ( api as any ) . listDebuggees ( projectId ) . then ( function ( results ) {
314+ // TODO: Determine if this is the correct signature for then
315+ return ( api as any ) . listDebuggees ( projectId ) . then ( function ( results : { [ index : number ] : Debuggee [ ] } ) {
295316 // Check that the debuggee created in this test is among the list of
296317 // debuggees, then list its breakpoints
297318
@@ -308,10 +329,10 @@ describe('@google-cloud/debug end-to-end behavior', function () {
308329
309330 // TODO: Determine how to properly specify the signature of listDebuggees
310331 return ( api as any ) . listBreakpoints ( debuggeeId ) ;
311- } ) . then ( function ( results ) {
332+ } ) . then ( function ( results : { [ index : number ] : apiTypes . Breakpoint [ ] } ) {
312333 // Delete every breakpoint
313334
314- const breakpoints = results [ 0 ] ;
335+ const breakpoints : apiTypes . Breakpoint [ ] = results [ 0 ] ;
315336
316337 console . log ( '-- List of breakpoints\n' , breakpoints ) ;
317338
@@ -321,7 +342,7 @@ describe('@google-cloud/debug end-to-end behavior', function () {
321342 } ) ;
322343
323344 return Promise . all ( promises ) ;
324- } ) . then ( function ( results ) {
345+ } ) . then ( function ( results : Promise < void > [ ] ) {
325346 // Set a breakpoint at which the debugger should write to a log
326347
327348 results . map ( function ( result ) {
@@ -339,19 +360,20 @@ describe('@google-cloud/debug end-to-end behavior', function () {
339360 expressions : [ 'o' ] ,
340361 log_message_format : 'o is: $0'
341362 } ) ;
342- } ) . then ( function ( results ) {
363+ } ) . then ( function ( results : apiTypes . Breakpoint [ ] ) {
343364 // Check that the breakpoint was set, and then wait for the log to be
344365 // written to
345366 const breakpoint = results [ 0 ] ;
346367
347368 assert . ok ( breakpoint , 'should have set a breakpoint' ) ;
348369 assert . ok ( breakpoint . id , 'breakpoint should have an id' ) ;
349370 assert . ok ( breakpoint . location , 'breakpoint should have a location' ) ;
350- assert . strictEqual ( breakpoint . location . path , FILENAME ) ;
371+ // TODO: Handle the case when breakpoint.location is undefined
372+ assert . strictEqual ( ( breakpoint . location as any ) . path , FILENAME ) ;
351373
352374 console . log ( '-- waiting before checking if the log was written' ) ;
353375 return Promise . all ( [ breakpoint , delay ( 10 * 1000 ) ] ) ;
354- } ) . then ( function ( results ) {
376+ } ) . then ( function ( results : apiTypes . Breakpoint [ ] ) {
355377 // Check that the contents of the log is correct
356378
357379 const breakpoint = results [ 0 ] ;
0 commit comments