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

Commit a21c83d

Browse files
Update test files to use the .ts extension (#315)
1 parent 232e494 commit a21c83d

33 files changed

+352
-272
lines changed

package.json

+1
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
"@types/estree": "0.0.35",
2828
"@types/extend": "^2.0.30",
2929
"@types/lodash": "^4.14.66",
30+
"@types/mocha": "^2.2.41",
3031
"@types/node": "^7.0.18",
3132
"@types/semver": "^5.3.31",
3233
"@types/source-map": "^0.5.0",

src/debuggee.ts

+3-1
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,9 @@ export class Debuggee {
7979
return new Debuggee(properties);
8080
}
8181

82-
properties = properties || {};
82+
// TODO: Determine if `statusMessage` should be optional or be required
83+
// and be explicitly set to `null`.
84+
properties = properties || { statusMessage: null };
8385

8486
if (!_.isString(properties.project)) {
8587
throw new Error('properties.project must be a string');
File renamed without changes.

system-test/test-e2e.js renamed to system-test/test-e2e.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -88,8 +88,9 @@ describe('@google-cloud/debug end-to-end behavior', function () {
8888
};
8989

9090
for (var i = 0; i < CLUSTER_WORKERS; i++) {
91+
// TODO: Determine how to have this not of type `any`.
9192
// Fork child processes that sned messages to this process with IPC.
92-
var child = { transcript: '' };
93+
var child: any = { transcript: '' };
9394
child.process = cp.fork(FILENAME, {
9495
execArgv: [],
9596
env: process.env,
File renamed without changes.

test/debugger.js renamed to test/debugger.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,8 @@ Debugger.prototype.listBreakpoints = function(debuggeeId, options, callback) {
114114
options = {};
115115
}
116116

117-
var query = {
117+
// TODO: Remove this cast as `any`
118+
var query: any = {
118119
clientVersion: this.clientVersion_,
119120
includeAllUsers: !!options.includeAllUsers,
120121
includeInactive: !!options.includeInactive,

test/misc/bench-code.js

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
/*1* KEEP THIS CODE AT THE TOP TO AVOID LINE NUMBER CHANGES */
2+
/*2*/'use strict';
3+
/*3*/function fib(n) {
4+
/*4*/ return n < 2 ? n : fib(n-2) + fib(n-1);
5+
/*5*/}
6+
/*6*/module.exports = fib;

test/misc/bench.js renamed to test/misc/bench.ts

+2-7
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,3 @@
1-
/*1* KEEP THIS CODE AT THE TOP TO AVOID LINE NUMBER CHANGES */
2-
/*2*/'use strict';
3-
/*3*/function fib(n) {
4-
/*4*/ return n < 2 ? n : fib(n-2) + fib(n-1);
5-
/*5*/}
6-
71
/**
82
* Copyright 2015 Google Inc. All Rights Reserved.
93
*
@@ -24,9 +18,10 @@
2418
var v8debugapi = require('../src/v8debugapi.js');
2519
var Logger = require('../src/logger.js');
2620
var config = require('../config.js').default;
27-
var assert = require('assert');
21+
import * as assert from 'assert';
2822
var pretty = require('pretty-hrtime');
2923
//var util = require('util');
24+
var fib = require('./bench-code.js');
3025

3126
var logger = new Logger(config.logLevel);
3227
assert.ok(v8debugapi.init(logger, config));

test/misc/test-leak.js renamed to test/misc/test-leak.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
var v8debugapi = require('../src/v8debugapi.js');
44
var Logger = require('../src/logger.js');
55
var config = require('../config.js').default;
6-
var assert = require('assert');
6+
import * as assert from 'assert';
77
var util = require('util');
88
var logger = new Logger(config.logLevel);
99

test/nocks.js renamed to test/nocks.ts

+4-11
Original file line numberDiff line numberDiff line change
@@ -13,16 +13,15 @@
1313
* See the License for the specific language governing permissions and
1414
* limitations under the License.
1515
*/
16-
'use strict';
1716

18-
var nock = require('nock');
17+
var nock = require('nock');
1918

2019
// In the future _=>true.
2120
function accept() {
2221
return true;
2322
}
2423

25-
function nockOAuth2(validator) {
24+
export function oauth2(validator) {
2625
validator = validator || accept;
2726
return nock('https://accounts.google.com')
2827
.post('/o/oauth2/token', validator)
@@ -34,23 +33,17 @@ function nockOAuth2(validator) {
3433
});
3534
}
3635

37-
function nockRegister(validator) {
36+
export function register(validator) {
3837
validator = validator || accept;
3938
return nock('https://clouddebugger.googleapis.com')
4039
.post('/v2/controller/debuggees/register', validator)
4140
.once()
4241
.reply(200);
4342
}
4443

45-
function nockProjectId(reply) {
44+
export function projectId(reply) {
4645
return nock('http://metadata.google.internal')
4746
.get('/computeMetadata/v1/project/project-id')
4847
.once()
4948
.reply(200, reply);
5049
}
51-
52-
module.exports = {
53-
oauth2: nockOAuth2,
54-
projectId: nockProjectId,
55-
register: nockRegister
56-
};

test/test-controller.js renamed to test/test-controller.ts

+5-4
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,8 @@
1313
* See the License for the specific language governing permissions and
1414
* limitations under the License.
1515
*/
16-
'use strict';
1716

18-
var assert = require('assert');
17+
import * as assert from 'assert';
1918
var nock = require('nock');
2019
var request = require('./auth-request.js');
2120
var Debuggee = require('../src/debuggee.js').Debuggee;
@@ -72,7 +71,8 @@ describe('Controller API', function() {
7271
});
7372
var controller = new Controller(fakeDebug);
7473
controller.register(debuggee, function(err, result) {
75-
assert.ifError(err, 'not expecting an error');
74+
// TODO: Fix this incorrect method signature.
75+
(assert as any).ifError(err, 'not expecting an error');
7676
assert.equal(result.debuggee.id, 'fake-debuggee');
7777
assert.ok(result.debuggee.isDisabled);
7878
scope.done();
@@ -161,7 +161,8 @@ describe('Controller API', function() {
161161
var debuggee = { id: 'fake-debuggee' };
162162
var controller = new Controller(fakeDebug);
163163
controller.listBreakpoints(debuggee, function(err, response, result) {
164-
assert.ifError(err, 'not expecting an error');
164+
// TODO: Fix this incorrect method signature.
165+
(assert as any).ifError(err, 'not expecting an error');
165166
assert(response.body.waitExpired, 'should have expired set');
166167
scope.done();
167168
done();
File renamed without changes.

test/test-debuggee.js renamed to test/test-debuggee.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
*/
1616
'use strict';
1717

18-
var assert = require('assert');
18+
import * as assert from 'assert';
1919
var Debuggee = require('../src/debuggee.js').Debuggee;
2020

2121
describe('Debuggee', function() {

test/test-debuglet.js renamed to test/test-debuglet.ts

+13-5
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@
1616
'use strict';
1717

1818
var _ = require('lodash');
19-
var assert = require('assert');
2019
var path = require('path');
20+
import * as assert from 'assert';
2121
var DEFAULT_CONFIG = require('../src/agent/config.js').default;
2222
DEFAULT_CONFIG.allowExpressions = true;
2323
DEFAULT_CONFIG.workingDirectory = path.join(__dirname, '..');
@@ -191,7 +191,8 @@ describe('Debuglet', function() {
191191

192192
it('should not query metadata if local config.projectId is set', (done) => {
193193
Debuglet.getProjectIdFromMetadata = () => {
194-
assert.fail();
194+
// TODO: Fix this invalid method signature.
195+
(assert as any).fail();
195196
};
196197
Debuglet.getProjectId({ projectId: 'from-config' }).then((projectId) => {
197198
assert.strictEqual(projectId, 'from-config');
@@ -205,7 +206,8 @@ describe('Debuglet', function() {
205206
process.env.GCLOUD_PROJECT = 'from-env-var';
206207

207208
Debuglet.getProjectIdFromMetadata = () => {
208-
assert.fail();
209+
// TODO: Fix this invalid method signature.
210+
(assert as any).fail();
209211
};
210212
Debuglet.getProjectId({}).then((projectId) => {
211213
assert.strictEqual(projectId, 'from-env-var');
@@ -284,7 +286,10 @@ describe('Debuglet', function() {
284286
Debuglet.getProjectId = savedGetProjectId;
285287
done();
286288
});
287-
debuglet.once('started', function() { assert.fail(); });
289+
debuglet.once('started', function() {
290+
// TODO: Fix this invalid method signature.
291+
(assert as any).fail();
292+
});
288293
debuglet.start();
289294
});
290295

@@ -297,7 +302,10 @@ describe('Debuglet', function() {
297302
var debug = require('../src/debug.js').Debug();
298303
var debuglet = new Debuglet(debug, defaultConfig);
299304

300-
debuglet.once('started', function() { assert.fail(); });
305+
debuglet.once('started', function() {
306+
// TODO: Fix this invalid method signature.
307+
(assert as any).fail();
308+
});
301309
debuglet.once('initError', function() {
302310
Debuglet.getProjectId = savedGetProjectId;
303311
done();
+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
/*1* KEEP THIS CODE AT THE TOP TO AVOID LINE NUMBER CHANGES */
2+
/*2*/'use strict';
3+
/*3*/function foo(a) {
4+
/*4*/ process.nextTick(function() {
5+
/*5*/ a = 0;
6+
/*6*/ });
7+
/*7*/}
8+
/*8*/module.exports = foo;

test/test-duplicate-expressions.js renamed to test/test-duplicate-expressions.ts

+9-13
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,3 @@
1-
/*1* KEEP THIS CODE AT THE TOP TO AVOID LINE NUMBER CHANGES */
2-
/*2*/'use strict';
3-
/*3*/function foo(a) {
4-
/*4*/ process.nextTick(function() {
5-
/*5*/ a = 0;
6-
/*6*/ });
7-
/*7*/}
81
/**
92
* Copyright 2015 Google Inc. All Rights Reserved.
103
*
@@ -23,18 +16,20 @@
2316

2417
var breakpointInFoo = {
2518
id: 'fake-id-123',
26-
location: { path: 'test-duplicate-expressions.js', line: 4 }
19+
location: { path: 'test-duplicate-expressions-code.js', line: 4 }
2720
};
2821

29-
var assert = require('assert');
22+
import * as assert from 'assert';
3023
var extend = require('extend');
3124
var v8debugapi = require('../src/agent/v8debugapi.js');
3225
var common = require('@google-cloud/common');
3326
var defaultConfig = require('../src/agent/config.js').default;
3427
var SourceMapper = require('../src/agent/sourcemapper.js');
3528
var scanner = require('../src/agent/scanner.js');
29+
var foo = require('./test-duplicate-expressions-code.js');
3630

37-
function stateIsClean(api) {
31+
// TODO: Determine why this must be named `stateIsClean1`.
32+
function stateIsClean1(api) {
3833
assert.equal(api.numBreakpoints_(), 0,
3934
'there should be no breakpoints active');
4035
assert.equal(api.numListeners_(), 0,
@@ -65,18 +60,19 @@ describe(__filename, function() {
6560
});
6661
});
6762
} else {
68-
assert(stateIsClean(api));
63+
assert(stateIsClean1(api));
6964
done();
7065
}
7166
});
72-
afterEach(function() { assert(stateIsClean(api)); });
67+
afterEach(function() { assert(stateIsClean1(api)); });
7368

7469
it('should not duplicate expressions', function(done) {
7570
api.set(breakpointInFoo, function(err) {
7671
assert.ifError(err);
7772
api.wait(breakpointInFoo, function(err) {
7873
assert.ifError(err);
79-
var frames = breakpointInFoo.stackFrames[0];
74+
// TODO: Determine how to remove this cast to any.
75+
var frames = (breakpointInFoo as any).stackFrames[0];
8076
var exprs = frames.arguments.concat(frames.locals);
8177
var varTableIndicesSeen = [];
8278
exprs.forEach(function(expr) {
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
/*1* KEEP THIS CODE AT THE TOP TO AVOID LINE NUMBER CHANGES */ /* jshint shadow:true */
2+
/*2*/'use strict';
3+
/*3*/function foo(a) {
4+
/*4*/ var a = 10;
5+
/*5*/ a += 1;
6+
/*6*/ return (function (b) {
7+
/*7*/ var a = true;
8+
/*8*/ return a;
9+
/*9*/ }());
10+
/*10*/}
11+
/*11*/module.exports = foo;

0 commit comments

Comments
 (0)