Skip to content
This repository was archived by the owner on Apr 3, 2024. It is now read-only.

Commit 29ba46b

Browse files
Add type annotations (#320)
1 parent 3bf2276 commit 29ba46b

16 files changed

+317
-225
lines changed

system-test/test-e2e.ts

Lines changed: 28 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -28,18 +28,18 @@ const CLUSTER_WORKERS = 3;
2828
// TODO: Determine if this path should contain 'build'
2929
const FILENAME = 'build/test/fixtures/fib.js';
3030

31-
const delay = function(delayTimeMS) {
31+
const delay = function(delayTimeMS: number): Promise<void> {
3232
return new Promise(function(resolve, reject) {
3333
setTimeout(resolve, delayTimeMS);
3434
});
3535
};
3636

3737
// This test could take up to 70 seconds.
3838
describe('@google-cloud/debug end-to-end behavior', function () {
39-
let api;
39+
let api: Debugger;
4040

41-
let debuggeeId;
42-
let projectId;
41+
let debuggeeId: string;
42+
let projectId: string;
4343
let children = [];
4444

4545
before(function() {
@@ -133,7 +133,8 @@ describe('@google-cloud/debug end-to-end behavior', function () {
133133
it('should set breakpoints correctly', function() {
134134
this.timeout(90 * 1000);
135135
// Kick off promise chain by getting a list of debuggees
136-
return api.listDebuggees(projectId).then(function(results) {
136+
// TODO: Determine how to properly specify the signature of listDebuggees
137+
return (api as any).listDebuggees(projectId).then(function(results) {
137138
// Check that the debuggee created in this test is among the list of
138139
// debuggees, then list its breakpoints
139140

@@ -147,7 +148,8 @@ describe('@google-cloud/debug end-to-end behavior', function () {
147148
return d.id === debuggeeId;
148149
});
149150
assert.ok(result, 'should find the debuggee we just registered');
150-
return api.listBreakpoints(debuggeeId);
151+
// TODO: Determine how to properly specify the signature of listDebuggees
152+
return (api as any).listBreakpoints(debuggeeId);
151153
}).then(function(results) {
152154
// Delete every breakpoint
153155

@@ -156,7 +158,8 @@ describe('@google-cloud/debug end-to-end behavior', function () {
156158
console.log('-- List of breakpoints\n', breakpoints);
157159

158160
const promises = breakpoints.map(function(breakpoint) {
159-
return api.deleteBreakpoint(debuggeeId, breakpoint.id);
161+
// TODO: Determine how to properly specify the signature of listDebuggees
162+
return (api as any).deleteBreakpoint(debuggeeId, breakpoint.id);
160163
});
161164

162165
return Promise.all(promises);
@@ -169,7 +172,8 @@ describe('@google-cloud/debug end-to-end behavior', function () {
169172
console.log('-- deleted');
170173

171174
console.log('-- setting a logpoint');
172-
return api.setBreakpoint(debuggeeId, {
175+
// TODO: Determine how to properly specify the signature of listDebuggees
176+
return (api as any).setBreakpoint(debuggeeId, {
173177
id: 'breakpoint-1',
174178
location: {path: FILENAME, line: 5},
175179
condition: 'n === 10',
@@ -205,7 +209,8 @@ describe('@google-cloud/debug end-to-end behavior', function () {
205209
// Set another breakpoint at the same location
206210

207211
console.log('-- setting a breakpoint');
208-
return api.setBreakpoint(debuggeeId, {
212+
// TODO: Determine how to properly specify the signature of listDebuggees
213+
return (api as any).setBreakpoint(debuggeeId, {
209214
id: 'breakpoint-2',
210215
location: {path: FILENAME, line: 5},
211216
expressions: ['process'], // Process for large variable
@@ -231,7 +236,8 @@ describe('@google-cloud/debug end-to-end behavior', function () {
231236
const breakpoint = results[0];
232237

233238
console.log('-- now checking if the breakpoint was hit');
234-
return api.getBreakpoint(debuggeeId, breakpoint.id);
239+
// TODO: Determine how to properly specify the signature of listDebuggees
240+
return (api as any).getBreakpoint(debuggeeId, breakpoint.id);
235241
}).then(function(results) {
236242
// Check that the breakpoint was hit and contains the correct information,
237243
// which ends the test
@@ -262,7 +268,8 @@ describe('@google-cloud/debug end-to-end behavior', function () {
262268
assert.ok(count > 4);
263269
});
264270

265-
return api.deleteBreakpoint(debuggeeId, breakpoint.id);
271+
// TODO: Determine how to properly specify the signature of listDebuggees
272+
return (api as any).deleteBreakpoint(debuggeeId, breakpoint.id);
266273
}).then(function() {
267274
// wait for 60 seconds
268275
console.log('-- waiting for 60 seconds');
@@ -283,7 +290,8 @@ describe('@google-cloud/debug end-to-end behavior', function () {
283290
it('should throttle logs correctly', function() {
284291
this.timeout(15 * 1000);
285292
// Kick off promise chain by getting a list of debuggees
286-
return api.listDebuggees(projectId).then(function(results) {
293+
// TODO: Determine how to properly specify the signature of listDebuggees
294+
return (api as any).listDebuggees(projectId).then(function(results) {
287295
// Check that the debuggee created in this test is among the list of
288296
// debuggees, then list its breakpoints
289297

@@ -298,7 +306,8 @@ describe('@google-cloud/debug end-to-end behavior', function () {
298306
});
299307
assert.ok(result, 'should find the debuggee we just registered');
300308

301-
return api.listBreakpoints(debuggeeId);
309+
// TODO: Determine how to properly specify the signature of listDebuggees
310+
return (api as any).listBreakpoints(debuggeeId);
302311
}).then(function(results) {
303312
// Delete every breakpoint
304313

@@ -307,7 +316,8 @@ describe('@google-cloud/debug end-to-end behavior', function () {
307316
console.log('-- List of breakpoints\n', breakpoints);
308317

309318
const promises = breakpoints.map(function(breakpoint) {
310-
return api.deleteBreakpoint(debuggeeId, breakpoint.id);
319+
// TODO: Determine how to properly specify the signature of listDebuggees
320+
return (api as any).deleteBreakpoint(debuggeeId, breakpoint.id);
311321
});
312322

313323
return Promise.all(promises);
@@ -320,7 +330,8 @@ describe('@google-cloud/debug end-to-end behavior', function () {
320330
console.log('-- deleted');
321331

322332
console.log('-- setting a logpoint');
323-
return api.setBreakpoint(debuggeeId, {
333+
// TODO: Determine how to properly specify the signature of listDebuggees
334+
return (api as any).setBreakpoint(debuggeeId, {
324335
id: 'breakpoint-3',
325336
location: {path: FILENAME, line: 5},
326337
condition: 'n === 10',
@@ -358,7 +369,8 @@ describe('@google-cloud/debug end-to-end behavior', function () {
358369
assert(logCount > 2, 'log count is not greater than 2: ' + logCount);
359370
});
360371

361-
return api.deleteBreakpoint(debuggeeId, breakpoint.id);
372+
// TODO: Determine how to properly specify the signature of listDebuggees
373+
return (api as any).deleteBreakpoint(debuggeeId, breakpoint.id);
362374
}).then(function() {
363375
console.log('-- test passed');
364376
return Promise.resolve();

test/auth-request.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,10 @@
1616
'use strict';
1717

1818
import * as request from 'request';
19+
import * as http from 'http';
1920

20-
export default function(options, callback) {
21+
// TODO: Make the type of `options` more precise
22+
export default function(options: any, callback: (err: Error, body: any, response: http.ServerResponse) => void) {
2123
request(options, function(err, response, body) {
2224
callback(err, body, response);
2325
});

test/debugger.ts

Lines changed: 21 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,9 @@
1919
*/
2020

2121
import * as commonTypes from '../src/types/common-types';
22+
import * as apiTypes from '../src/types/api-types';
23+
import {Debug} from '../src/debug';
24+
import {Debuggee} from '../src/debuggee';
2225

2326
const pjson = require('../../package.json');
2427
export const common: commonTypes.Common = require('@google-cloud/common');
@@ -33,13 +36,13 @@ import * as util from 'util';
3336
const API = 'https://clouddebugger.googleapis.com/v2/debugger';
3437

3538
export class Debugger extends common.ServiceObject {
36-
private nextWaitToken_;
37-
private clientVersion_;
39+
private nextWaitToken_: string|null;
40+
private clientVersion_: string;
3841

3942
/**
4043
* @constructor
4144
*/
42-
constructor(debug) {
45+
constructor(debug: Debug) {
4346
super({
4447
parent: debug,
4548
baseUrl: '/debugger'
@@ -62,7 +65,7 @@ export class Debugger extends common.ServiceObject {
6265
* called with a list of Debuggee objects as a parameter, or an Error object
6366
* if an error occurred in obtaining it.
6467
*/
65-
listDebuggees(projectId, includeInactive, callback) {
68+
listDebuggees(projectId: string, includeInactive: boolean, callback: (err: Error|null, debuggees?: Debuggee[]) => void) {
6669
if (typeof(includeInactive) === 'function') {
6770
callback = includeInactive;
6871
includeInactive = false;
@@ -114,10 +117,16 @@ export class Debugger extends common.ServiceObject {
114117
* called with a list of Breakpoint objects as a parameter, or an Error
115118
* object if an error occurred in obtaining it.
116119
*/
117-
listBreakpoints(debuggeeId, options, callback) {
120+
listBreakpoints(debuggeeId: string, options: {
121+
includeAllUsers: boolean;
122+
includeInactive: boolean;
123+
stripResults: boolean;
124+
actions: string
125+
}, callback: (err: Error|null, breakpoints?: apiTypes.Breakpoint[]) => void) {
118126
if (typeof(options) === 'function') {
119127
callback = options;
120-
options = {};
128+
// TODO: Determine how to remove this cast.
129+
options = {} as any;
121130
}
122131

123132
// TODO: Remove this cast as `any`
@@ -127,8 +136,9 @@ export class Debugger extends common.ServiceObject {
127136
includeInactive: !!options.includeInactive,
128137
stripResults: !!options.stripResults
129138
};
130-
if (options.action) {
131-
query.action = { value: options.action };
139+
// TODO: Determine how to remove this cast.
140+
if ((options as any).action) {
141+
query.action = { value: (options as any).action };
132142
}
133143
if (this.nextWaitToken_) {
134144
query.waitToken = this.nextWaitToken_;
@@ -166,7 +176,7 @@ export class Debugger extends common.ServiceObject {
166176
* called with information about the given breakpoint, or an Error object
167177
* if an error occurred in obtaining its information.
168178
*/
169-
getBreakpoint(debuggeeId, breakpointId, callback) {
179+
getBreakpoint(debuggeeId: string, breakpointId: string, callback: (err: Error|null, bp?: apiTypes.Breakpoint) => void) {
170180
const query = {
171181
clientVersion: this.clientVersion_
172182
};
@@ -202,7 +212,7 @@ export class Debugger extends common.ServiceObject {
202212
* that the Breakpoint object here will differ from the input object in
203213
* that its id field will be set.
204214
*/
205-
setBreakpoint(debuggeeId, breakpoint, callback) {
215+
setBreakpoint(debuggeeId: string, breakpoint: apiTypes.Breakpoint, callback: (err: Error|null, bp?: apiTypes.Breakpoint) => void) {
206216
const query = {
207217
clientVersion: this.clientVersion_
208218
};
@@ -240,7 +250,7 @@ export class Debugger extends common.ServiceObject {
240250
* deleting a breakpoint. If no error occurred, the first argument will be
241251
* set to null.
242252
*/
243-
deleteBreakpoint(debuggeeId, breakpointId, callback) {
253+
deleteBreakpoint(debuggeeId: string, breakpointId: string, callback: (err: Error|null) => void) {
244254
const query = {
245255
clientVersion: this.clientVersion_
246256
};

test/nocks.ts

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,12 @@
1717
import * as nock from 'nock';
1818

1919
// In the future _=>true.
20-
function accept() {
20+
function accept(): true {
2121
return true;
2222
}
2323

24-
export function oauth2(validator) {
24+
// TODO: Determine if the type of `validator` is correct.
25+
export function oauth2(validator?: (body: any) => boolean): nock.Scope {
2526
validator = validator || accept;
2627
return nock('https://accounts.google.com')
2728
.post('/o/oauth2/token', validator)
@@ -33,15 +34,16 @@ export function oauth2(validator) {
3334
});
3435
}
3536

36-
export function register(validator) {
37+
// TODO: Determine if the type of `validator` is correct.
38+
export function register(validator?: (body: any) => boolean): nock.Scope {
3739
validator = validator || accept;
3840
return nock('https://clouddebugger.googleapis.com')
3941
.post('/v2/controller/debuggees/register', validator)
4042
.once()
4143
.reply(200);
4244
}
4345

44-
export function projectId(reply) {
46+
export function projectId(reply: string): nock.Scope {
4547
return nock('http://metadata.google.internal')
4648
.get('/computeMetadata/v1/project/project-id')
4749
.once()

0 commit comments

Comments
 (0)