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

Commit df2c565

Browse files
Update the tests to use import syntax (#316)
1 parent a21c83d commit df2c565

25 files changed

+357
-214
lines changed

package.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,11 @@
2626
"@types/async": "^2.0.40",
2727
"@types/estree": "0.0.35",
2828
"@types/extend": "^2.0.30",
29-
"@types/lodash": "^4.14.66",
29+
"@types/lodash": "^4.14.69",
3030
"@types/mocha": "^2.2.41",
31+
"@types/nock": "^8.2.1",
3132
"@types/node": "^7.0.18",
32-
"@types/semver": "^5.3.31",
33+
"@types/semver": "^5.3.32",
3334
"@types/source-map": "^0.5.0",
3435
"changelog-maker": "^2.2.2",
3536
"clang-format": "^1.0.53",

src/agent/debuglet.ts

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -108,16 +108,21 @@ const formatBreakpoints = function(
108108
};
109109

110110
export class Debuglet extends EventEmitter {
111-
private config_: DebugAgentConfig;
111+
// TODO: Determine how to update the tests so that this can be private.
112+
config_: DebugAgentConfig;
112113
private debug_: Debug;
113114
private v8debug_: V8DebugApi|null;
114115
private running_: boolean;
115116
private project_: string|null;
116-
private fetcherActive_: boolean;
117-
private logger_: Logger;
117+
// TODO: Determine how to update the tests so that this can be private.
118+
fetcherActive_: boolean;
119+
// TODO: Determine how to update the tests so that this can be private.
120+
logger_: Logger;
118121
private debugletApi_: Controller;
119-
private debuggee_: Debuggee|null;
120-
private activeBreakpointMap_: {[key: string]: Breakpoint};
122+
// TODO: Determine how to update the tests so that this can be private.
123+
debuggee_: Debuggee|null;
124+
// TODO: Determine how to update the tests so that this can be private.
125+
activeBreakpointMap_: {[key: string]: Breakpoint};
121126
private completedBreakpointMap_: {[key: string]: boolean};
122127

123128
/**

src/debuggee.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,15 +36,18 @@ export interface DebuggeeProperties {
3636
}
3737

3838
export class Debuggee {
39-
private project: string;
39+
// TODO: Determine how to update the tests so that this can be private.
40+
project: string;
4041
private uniquifier: string;
4142
private description: string;
4243
private agentVersion?: string;
43-
private labels?: {
44+
// TODO: Determine how to update the tests so that this can be private.
45+
labels?: {
4446
[key: string]: string,
4547
};
4648
private sourceContexts?: Array<{[key: string]: any}>;
47-
private statusMessage?: StatusMessage;
49+
// TODO: Determine how to update the tests so that this can be private.
50+
statusMessage?: StatusMessage;
4851
id: string;
4952
// TODO: This doesn't seem to ever be set but is referenced in the
5053
// debuglet.ts file.

system-test/test-controller.ts

Lines changed: 29 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616

1717
'use strict';
1818

19-
var assert = require('assert');
19+
import * as assert from 'assert';
2020

2121
assert.ok(
2222
process.env.GCLOUD_PROJECT,
@@ -26,9 +26,12 @@ assert.ok(
2626
'Need to have GOOGLE_APPLICATION_CREDENTIALS defined to be able to run ' +
2727
'this test');
2828

29-
var Controller = require('../src/controller.js').Controller;
30-
var Debuggee = require('../src/debuggee.js').Debuggee;
31-
var debug = require('../src/debug.js').Debug();
29+
import {Controller} from '../src/controller';
30+
import {Debuggee} from '../src/debuggee';
31+
import {Debug} from '../src/debug';
32+
// TODO: Determine if Debug should be updated so that its only parameter is
33+
// optional.
34+
const debug = new Debug({});
3235

3336

3437
describe('Controller', function() {
@@ -40,11 +43,14 @@ describe('Controller', function() {
4043
new Debuggee({
4144
project: process.env.GCLOUD_PROJECT,
4245
uniquifier: 'test-uid-' + Date.now(),
43-
description: 'this is a system test'
46+
description: 'this is a system test',
47+
// TODO: Determine if statusMessage should be made optional.
48+
statusMessage: null
4449
});
4550

4651
controller.register(debuggee, function(err, body) {
47-
assert.ifError(err, 'should be able to register successfully');
52+
// TODO: Only 1 parameter is expected. Fix this.
53+
(assert as any).ifError(err, 'should be able to register successfully');
4854
assert.ok(body);
4955
assert.ok(body.debuggee);
5056
assert.ok(body.debuggee.id);
@@ -56,15 +62,19 @@ describe('Controller', function() {
5662
var controller = new Controller(debug);
5763
var debuggee =
5864
new Debuggee({
59-
project: process.env.GCLOUD_PROJECT,
65+
project: process.env.GCLOUD_PROJECT,
6066
uniquifier: 'test-uid-' + Date.now(),
61-
description: 'this is a system test'
67+
description: 'this is a system test',
68+
// TODO: Determine if statusMessage should be made optional.
69+
statusMessage: null
6270
});
6371
controller.register(debuggee, function(err, body) {
64-
assert.ifError(err, 'should be able to register successfully');
72+
// TODO: Only 1 parameter is expected. Fix this.
73+
(assert as any).ifError(err, 'should be able to register successfully');
6574

6675
controller.listBreakpoints(debuggee, function(err, response, body) {
67-
assert.ifError(err, 'should successfully list breakpoints');
76+
// TODO: Only 1 parameter is expected. Fix this.
77+
(assert as any).ifError(err, 'should successfully list breakpoints');
6878
assert.ok(body);
6979
assert.ok(body.nextWaitToken);
7080
done();
@@ -79,19 +89,24 @@ describe('Controller', function() {
7989
new Debuggee({
8090
project: process.env.GCLOUD_PROJECT,
8191
uniquifier: 'test-uid-' + Date.now(),
82-
description: 'this is a system test'
92+
description: 'this is a system test',
93+
// TODO: Determine if statusMessage should be made optional.
94+
statusMessage: null
8395
});
8496
controller.register(debuggee, function(err, body) {
85-
assert.ifError(err, 'should be able to register successfully');
97+
// TODO: Only 1 parameter is expected. Fix this.
98+
(assert as any).ifError(err, 'should be able to register successfully');
8699

87100
// First list should set the wait token
88101
controller.listBreakpoints(debuggee, function(err, response, body) {
89-
assert.ifError(err, 'should successfully list breakpoints');
102+
// TODO: Only 1 parameter is expected. Fix this.
103+
(assert as any).ifError(err, 'should successfully list breakpoints');
90104
assert.ok(body);
91105
assert.ok(body.nextWaitToken);
92106
// Second list should block until the wait timeout
93107
controller.listBreakpoints(debuggee, function(err, response, body) {
94-
assert.ifError(err, 'should successfully list breakpoints');
108+
// TODO: Only 1 parameter is expected. Fix this.
109+
(assert as any).ifError(err, 'should successfully list breakpoints');
95110
assert.ok(body);
96111
assert.ok(body.nextWaitToken);
97112
// waitExpired will only be set if successOnTimeout was given correctly

system-test/test-e2e.ts

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,13 @@
1515
*/
1616

1717
'use strict';
18-
var assert = require('assert');
19-
var util = require('util');
20-
var _ = require('lodash'); // for _.find. Can't use ES6 yet.
21-
var cp = require('child_process');
22-
var semver = require('semver');
23-
var promisifyAll = require('@google-cloud/common').util.promisifyAll;
24-
var Debug = require('../src/debug.js').Debug;
18+
import * as assert from 'assert';
19+
import * as util from 'util';
20+
import * as _ from 'lodash'; // for _.find. Can't use ES6 yet.
21+
import * as cp from 'child_process';
22+
import * as semver from 'semver';
23+
const promisifyAll = require('@google-cloud/common').util.promisifyAll;
24+
import {Debug} from '../src/debug';
2525
var Debugger = require('../test/debugger.js');
2626

2727
var CLUSTER_WORKERS = 3;
@@ -91,11 +91,12 @@ describe('@google-cloud/debug end-to-end behavior', function () {
9191
// TODO: Determine how to have this not of type `any`.
9292
// Fork child processes that sned messages to this process with IPC.
9393
var child: any = { transcript: '' };
94+
// TODO: Fix this cast to any.
9495
child.process = cp.fork(FILENAME, {
9596
execArgv: [],
9697
env: process.env,
9798
silent: true
98-
});
99+
} as any);
99100
child.process.on('message', handler);
100101

101102
children.push(child);
@@ -142,7 +143,8 @@ describe('@google-cloud/debug end-to-end behavior', function () {
142143
console.log('-- List of debuggees\n',
143144
util.inspect(debuggees, { depth: null}));
144145
assert.ok(debuggees, 'should get a valid ListDebuggees response');
145-
var result = _.find(debuggees, function(d) {
146+
// TODO: Fix this cast to any.
147+
var result = _.find(debuggees, function(d: any) {
146148
return d.id === debuggeeId;
147149
});
148150
assert.ok(result, 'should find the debuggee we just registered');
@@ -291,7 +293,8 @@ describe('@google-cloud/debug end-to-end behavior', function () {
291293
console.log('-- List of debuggees\n',
292294
util.inspect(debuggees, { depth: null}));
293295
assert.ok(debuggees, 'should get a valid ListDebuggees response');
294-
var result = _.find(debuggees, function(d) {
296+
// TODO: Fix this cast to any.
297+
var result = _.find(debuggees, function(d: any) {
295298
return d.id === debuggeeId;
296299
});
297300
assert.ok(result, 'should find the debuggee we just registered');

test/auth-request.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,9 @@
1515
*/
1616
'use strict';
1717

18-
var request = require('request');
19-
module.exports = function(options, callback) {
18+
import * as request from 'request';
19+
20+
export default function(options, callback) {
2021
request(options, function(err, response, body) {
2122
callback(err, body, response);
2223
});

test/debugger.ts

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,16 @@
2020
* @module debug/debugger
2121
*/
2222

23-
var pjson = require('../package.json');
24-
var common = require('@google-cloud/common');
25-
var qs = require('querystring');
26-
var util = require('util');
23+
import * as commonTypes from '../src/types/common-types';
24+
25+
var pjson = require('../../package.json');
26+
const common: commonTypes.Common = require('@google-cloud/common');
27+
// TODO: Verify these types are correct.
28+
const qs: { parse: (qs: any, sep?: string, eq?: string,
29+
options?: { maxKeys?: number }) => any,
30+
stringify: (obj: object|string|boolean|number, sep?: string,
31+
eq?: string, name?: string) => string} = require('querystring');
32+
import * as util from 'util';
2733

2834
/** @const {string} Cloud Debug API endpoint */
2935
var API = 'https://clouddebugger.googleapis.com/v2/debugger';

test/misc/test-leak.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ var v8debugapi = require('../src/v8debugapi.js');
44
var Logger = require('../src/logger.js');
55
var config = require('../config.js').default;
66
import * as assert from 'assert';
7-
var util = require('util');
7+
import * as util from 'util';
88
var logger = new Logger(config.logLevel);
99

1010
assert.ok(v8debugapi.init(logger, config));

test/nocks.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
* limitations under the License.
1515
*/
1616

17-
var nock = require('nock');
17+
import * as nock from 'nock';
1818

1919
// In the future _=>true.
2020
function accept() {

0 commit comments

Comments
 (0)