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

Commit 7952610

Browse files
Update tests to use let or const instead of var (#317)
1 parent df2c565 commit 7952610

19 files changed

+507
-503
lines changed

system-test/test-controller.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,8 @@ describe('Controller', function() {
3838
this.timeout(60 * 1000);
3939

4040
it('should register successfully', function(done) {
41-
var controller = new Controller(debug);
42-
var debuggee =
41+
const controller = new Controller(debug);
42+
const debuggee =
4343
new Debuggee({
4444
project: process.env.GCLOUD_PROJECT,
4545
uniquifier: 'test-uid-' + Date.now(),
@@ -59,8 +59,8 @@ describe('Controller', function() {
5959
});
6060

6161
it('should list breakpoints', function(done) {
62-
var controller = new Controller(debug);
63-
var debuggee =
62+
const controller = new Controller(debug);
63+
const debuggee =
6464
new Debuggee({
6565
project: process.env.GCLOUD_PROJECT,
6666
uniquifier: 'test-uid-' + Date.now(),
@@ -84,8 +84,8 @@ describe('Controller', function() {
8484

8585
it('should pass success on timeout', function(done) {
8686
this.timeout(100000);
87-
var controller = new Controller(debug);
88-
var debuggee =
87+
const controller = new Controller(debug);
88+
const debuggee =
8989
new Debuggee({
9090
project: process.env.GCLOUD_PROJECT,
9191
uniquifier: 'test-uid-' + Date.now(),

system-test/test-e2e.ts

Lines changed: 32 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -22,26 +22,26 @@ import * as cp from 'child_process';
2222
import * as semver from 'semver';
2323
const promisifyAll = require('@google-cloud/common').util.promisifyAll;
2424
import {Debug} from '../src/debug';
25-
var Debugger = require('../test/debugger.js');
25+
const Debugger = require('../test/debugger.js');
2626

27-
var CLUSTER_WORKERS = 3;
27+
const CLUSTER_WORKERS = 3;
2828

2929
// TODO: Determine if this path should contain 'build'
30-
var FILENAME = 'build/test/fixtures/fib.js';
30+
const FILENAME = 'build/test/fixtures/fib.js';
3131

32-
var delay = function(delayTimeMS) {
32+
const delay = function(delayTimeMS) {
3333
return new Promise(function(resolve, reject) {
3434
setTimeout(resolve, delayTimeMS);
3535
});
3636
};
3737

3838
// This test could take up to 70 seconds.
3939
describe('@google-cloud/debug end-to-end behavior', function () {
40-
var api;
40+
let api;
4141

42-
var debuggeeId;
43-
var projectId;
44-
var children = [];
42+
let debuggeeId;
43+
let projectId;
44+
let children = [];
4545

4646
before(function() {
4747
promisifyAll(Debugger);
@@ -51,10 +51,10 @@ describe('@google-cloud/debug end-to-end behavior', function () {
5151
beforeEach(function() {
5252
this.timeout(10 * 1000);
5353
return new Promise(function(resolve, reject) {
54-
var numChildrenReady = 0;
54+
let numChildrenReady = 0;
5555

5656
// Process a status message sent from a child process.
57-
var handler = function(c) {
57+
const handler = function(c) {
5858
console.log(c);
5959
if (c.error) {
6060
reject(new Error('A child reported the following error: ' + c.error));
@@ -81,16 +81,16 @@ describe('@google-cloud/debug end-to-end behavior', function () {
8181
// Handle stdout/stderr output from a child process. More specifically,
8282
// write the child process's output to a transcript.
8383
// Each child has its own transcript.
84-
var stdoutHandler = function(index) {
84+
const stdoutHandler = function(index) {
8585
return function(chunk) {
8686
children[index].transcript += chunk;
8787
};
8888
};
8989

90-
for (var i = 0; i < CLUSTER_WORKERS; i++) {
90+
for (let i = 0; i < CLUSTER_WORKERS; i++) {
9191
// TODO: Determine how to have this not of type `any`.
9292
// Fork child processes that sned messages to this process with IPC.
93-
var child: any = { transcript: '' };
93+
const child: any = { transcript: '' };
9494
// TODO: Fix this cast to any.
9595
child.process = cp.fork(FILENAME, {
9696
execArgv: [],
@@ -110,11 +110,11 @@ describe('@google-cloud/debug end-to-end behavior', function () {
110110
afterEach(function() {
111111
this.timeout(5 * 1000);
112112
// Create a promise for each child that resolves when that child exits.
113-
var childExitPromises = children.map(function (child) {
113+
const childExitPromises = children.map(function (child) {
114114
console.log(child.transcript);
115115
child.process.kill();
116116
return new Promise(function(resolve, reject) {
117-
var timeout = setTimeout(function() {
117+
const timeout = setTimeout(function() {
118118
reject(new Error('A child process failed to exit.'));
119119
}, 3000);
120120
child.process.on('exit', function() {
@@ -138,25 +138,25 @@ describe('@google-cloud/debug end-to-end behavior', function () {
138138
// Check that the debuggee created in this test is among the list of
139139
// debuggees, then list its breakpoints
140140

141-
var debuggees = results[0];
141+
const debuggees = results[0];
142142

143143
console.log('-- List of debuggees\n',
144144
util.inspect(debuggees, { depth: null}));
145145
assert.ok(debuggees, 'should get a valid ListDebuggees response');
146146
// TODO: Fix this cast to any.
147-
var result = _.find(debuggees, function(d: any) {
147+
const result = _.find(debuggees, function(d: any) {
148148
return d.id === debuggeeId;
149149
});
150150
assert.ok(result, 'should find the debuggee we just registered');
151151
return api.listBreakpoints(debuggeeId);
152152
}).then(function(results) {
153153
// Delete every breakpoint
154154

155-
var breakpoints = results[0];
155+
const breakpoints = results[0];
156156

157157
console.log('-- List of breakpoints\n', breakpoints);
158158

159-
var promises = breakpoints.map(function(breakpoint) {
159+
const promises = breakpoints.map(function(breakpoint) {
160160
return api.deleteBreakpoint(debuggeeId, breakpoint.id);
161161
});
162162

@@ -182,7 +182,7 @@ describe('@google-cloud/debug end-to-end behavior', function () {
182182
// Check that the breakpoint was set, and then wait for the log to be
183183
// written to
184184

185-
var breakpoint = results[0];
185+
const breakpoint = results[0];
186186

187187
assert.ok(breakpoint, 'should have set a breakpoint');
188188
assert.ok(breakpoint.id, 'breakpoint should have an id');
@@ -194,7 +194,7 @@ describe('@google-cloud/debug end-to-end behavior', function () {
194194
}).then(function(results) {
195195
// Check the contents of the log, but keep the original breakpoint.
196196

197-
var breakpoint = results[0];
197+
const breakpoint = results[0];
198198

199199
children.forEach(function(child, index) {
200200
assert(child.transcript.indexOf('o is: {"a":[1,"hi",true]}') !== -1,
@@ -216,7 +216,7 @@ describe('@google-cloud/debug end-to-end behavior', function () {
216216
// Check that the breakpoint was set, and then wait for the breakpoint to
217217
// be hit
218218

219-
var breakpoint = results[0];
219+
const breakpoint = results[0];
220220

221221
console.log('-- resolution of setBreakpoint', breakpoint);
222222
assert.ok(breakpoint, 'should have set a breakpoint');
@@ -229,22 +229,22 @@ describe('@google-cloud/debug end-to-end behavior', function () {
229229
}).then(function(results) {
230230
// Get the breakpoint
231231

232-
var breakpoint = results[0];
232+
const breakpoint = results[0];
233233

234234
console.log('-- now checking if the breakpoint was hit');
235235
return api.getBreakpoint(debuggeeId, breakpoint.id);
236236
}).then(function(results) {
237237
// Check that the breakpoint was hit and contains the correct information,
238238
// which ends the test
239239

240-
var breakpoint = results[0];
240+
const breakpoint = results[0];
241241

242-
var arg;
242+
let arg;
243243
console.log('-- results of get breakpoint\n', breakpoint);
244244
assert.ok(breakpoint, 'should have a breakpoint in the response');
245245
assert.ok(breakpoint.isFinalState, 'breakpoint should have been hit');
246246
assert.ok(Array.isArray(breakpoint.stackFrames), 'should have stack ');
247-
var top = breakpoint.stackFrames[0];
247+
const top = breakpoint.stackFrames[0];
248248
assert.ok(top, 'should have a top entry');
249249
assert.ok(top.function, 'frame should have a function property');
250250
assert.strictEqual(top.function, 'fib');
@@ -288,13 +288,13 @@ describe('@google-cloud/debug end-to-end behavior', function () {
288288
// Check that the debuggee created in this test is among the list of
289289
// debuggees, then list its breakpoints
290290

291-
var debuggees = results[0];
291+
const debuggees = results[0];
292292

293293
console.log('-- List of debuggees\n',
294294
util.inspect(debuggees, { depth: null}));
295295
assert.ok(debuggees, 'should get a valid ListDebuggees response');
296296
// TODO: Fix this cast to any.
297-
var result = _.find(debuggees, function(d: any) {
297+
const result = _.find(debuggees, function(d: any) {
298298
return d.id === debuggeeId;
299299
});
300300
assert.ok(result, 'should find the debuggee we just registered');
@@ -303,11 +303,11 @@ describe('@google-cloud/debug end-to-end behavior', function () {
303303
}).then(function(results) {
304304
// Delete every breakpoint
305305

306-
var breakpoints = results[0];
306+
const breakpoints = results[0];
307307

308308
console.log('-- List of breakpoints\n', breakpoints);
309309

310-
var promises = breakpoints.map(function(breakpoint) {
310+
const promises = breakpoints.map(function(breakpoint) {
311311
return api.deleteBreakpoint(debuggeeId, breakpoint.id);
312312
});
313313

@@ -332,7 +332,7 @@ describe('@google-cloud/debug end-to-end behavior', function () {
332332
}).then(function(results) {
333333
// Check that the breakpoint was set, and then wait for the log to be
334334
// written to
335-
var breakpoint = results[0];
335+
const breakpoint = results[0];
336336

337337
assert.ok(breakpoint, 'should have set a breakpoint');
338338
assert.ok(breakpoint.id, 'breakpoint should have an id');
@@ -344,7 +344,7 @@ describe('@google-cloud/debug end-to-end behavior', function () {
344344
}).then(function(results) {
345345
// Check that the contents of the log is correct
346346

347-
var breakpoint = results[0];
347+
const breakpoint = results[0];
348348

349349
// If no throttling occurs, we expect ~20 logs since we are logging
350350
// 2x per second over a 10 second period.

test/debugger.ts

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222

2323
import * as commonTypes from '../src/types/common-types';
2424

25-
var pjson = require('../../package.json');
25+
const pjson = require('../../package.json');
2626
const common: commonTypes.Common = require('@google-cloud/common');
2727
// TODO: Verify these types are correct.
2828
const qs: { parse: (qs: any, sep?: string, eq?: string,
@@ -32,7 +32,7 @@ const qs: { parse: (qs: any, sep?: string, eq?: string,
3232
import * as util from 'util';
3333

3434
/** @const {string} Cloud Debug API endpoint */
35-
var API = 'https://clouddebugger.googleapis.com/v2/debugger';
35+
const API = 'https://clouddebugger.googleapis.com/v2/debugger';
3636

3737
/**
3838
* @constructor
@@ -68,13 +68,13 @@ Debugger.prototype.listDebuggees = function(projectId, includeInactive, callback
6868
includeInactive = false;
6969
}
7070

71-
var query = {
71+
const query = {
7272
clientVersion: this.clientVersion_,
7373
includeInactive: includeInactive,
7474
project: projectId
7575
};
7676

77-
var uri = API + '/debuggees?' + qs.stringify(query);
77+
const uri = API + '/debuggees?' + qs.stringify(query);
7878
this.request({uri: uri, json: true}, function(err, body, response) {
7979
if (err) {
8080
callback(err);
@@ -121,7 +121,7 @@ Debugger.prototype.listBreakpoints = function(debuggeeId, options, callback) {
121121
}
122122

123123
// TODO: Remove this cast as `any`
124-
var query: any = {
124+
const query: any = {
125125
clientVersion: this.clientVersion_,
126126
includeAllUsers: !!options.includeAllUsers,
127127
includeInactive: !!options.includeInactive,
@@ -134,7 +134,7 @@ Debugger.prototype.listBreakpoints = function(debuggeeId, options, callback) {
134134
query.waitToken = this.nextWaitToken_;
135135
}
136136

137-
var uri = API + '/debuggees/' + encodeURIComponent(debuggeeId) +
137+
const uri = API + '/debuggees/' + encodeURIComponent(debuggeeId) +
138138
'/breakpoints?' + qs.stringify(query);
139139
this.request({uri: uri, json: true}, function(err, body, response) {
140140
if (err) {
@@ -167,11 +167,11 @@ Debugger.prototype.listBreakpoints = function(debuggeeId, options, callback) {
167167
* if an error occurred in obtaining its information.
168168
*/
169169
Debugger.prototype.getBreakpoint = function(debuggeeId, breakpointId, callback) {
170-
var query = {
170+
const query = {
171171
clientVersion: this.clientVersion_
172172
};
173173

174-
var uri = API + '/debuggees/' + encodeURIComponent(debuggeeId) +
174+
const uri = API + '/debuggees/' + encodeURIComponent(debuggeeId) +
175175
'/breakpoints/' + encodeURIComponent(breakpointId) +
176176
'?' + qs.stringify(query);
177177
this.request({uri: uri, json: true}, function(err, body, response) {
@@ -203,10 +203,10 @@ Debugger.prototype.getBreakpoint = function(debuggeeId, breakpointId, callback)
203203
* that its id field will be set.
204204
*/
205205
Debugger.prototype.setBreakpoint = function(debuggeeId, breakpoint, callback) {
206-
var query = {
206+
const query = {
207207
clientVersion: this.clientVersion_
208208
};
209-
var options = {
209+
const options = {
210210
uri: API + '/debuggees/' + encodeURIComponent(debuggeeId) +
211211
'/breakpoints/set?' + qs.stringify(query),
212212
method: 'POST',
@@ -241,10 +241,10 @@ Debugger.prototype.setBreakpoint = function(debuggeeId, breakpoint, callback) {
241241
* set to null.
242242
*/
243243
Debugger.prototype.deleteBreakpoint = function(debuggeeId, breakpointId, callback) {
244-
var query = {
244+
const query = {
245245
clientVersion: this.clientVersion_
246246
};
247-
var options = {
247+
const options = {
248248
uri: API + '/debuggees/' + encodeURIComponent(debuggeeId) +
249249
'/breakpoints/' + encodeURIComponent(breakpointId) + '?' +
250250
qs.stringify(query),

test/misc/bench.ts

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

1717

18-
var v8debugapi = require('../src/v8debugapi.js');
19-
var Logger = require('../src/logger.js');
20-
var config = require('../config.js').default;
18+
const v8debugapi = require('../src/v8debugapi.js');
19+
const Logger = require('../src/logger.js');
20+
const config = require('../config.js').default;
2121
import * as assert from 'assert';
22-
var pretty = require('pretty-hrtime');
23-
//var util = require('util');
24-
var fib = require('./bench-code.js');
22+
const pretty = require('pretty-hrtime');
23+
//const util = require('util');
24+
const fib = require('./bench-code.js');
2525

26-
var logger = new Logger(config.logLevel);
26+
const logger = new Logger(config.logLevel);
2727
assert.ok(v8debugapi.init(logger, config));
2828

2929
function bench(message, f) {
30-
var t = process.hrtime();
30+
let t = process.hrtime();
3131
f();
3232
t = process.hrtime(t);
3333
console.log(message + ': ' + pretty(t));
3434
}
3535

3636
bench('100x set', function() {
37-
for (var i = 0; i < 100; i++) {
38-
var bp = {
37+
for (let i = 0; i < 100; i++) {
38+
const bp = {
3939
id: 'fake-breakpoint',
4040
location: { path: __filename, line: 4}
4141
};
@@ -45,8 +45,8 @@ bench('100x set', function() {
4545
});
4646

4747
bench('100x set + validate', function() {
48-
for (var i = 0; i < 100; i++) {
49-
var bp = {
48+
for (let i = 0; i < 100; i++) {
49+
const bp = {
5050
id: 'breakpoint1',
5151
location: {path: __filename, line: 4},
5252
condition: 'x === 1, 2, {f: 2}, process.env, (this ? this : this)'
@@ -60,7 +60,7 @@ bench('fib(29)', function() {fib(29);});
6060

6161
// FIXME: the following test isn't really working because of a V8 bug.
6262
(function() {
63-
var bp = {
63+
const bp = {
6464
id: 'breakpoint1',
6565
location: {path: __filename, line: 4},
6666
condition: 'n > 50000'

0 commit comments

Comments
 (0)