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

Commit

Permalink
Enable all compiler options (#321)
Browse files Browse the repository at this point in the history
  • Loading branch information
DominicKramer committed Aug 1, 2017
1 parent 29ba46b commit 40365fb
Show file tree
Hide file tree
Showing 20 changed files with 486 additions and 310 deletions.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
"@types/mocha": "^2.2.41",
"@types/nock": "^8.2.1",
"@types/node": "^7.0.18",
"@types/request": "^2.0.0",
"@types/semver": "^5.3.32",
"@types/source-map": "^0.5.0",
"changelog-maker": "^2.2.2",
Expand Down
30 changes: 19 additions & 11 deletions system-test/test-controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,9 @@ describe('Controller', function() {
// TODO: Only 1 parameter is expected. Fix this.
(assert as any).ifError(err, 'should be able to register successfully');
assert.ok(body);
assert.ok(body.debuggee);
assert.ok(body.debuggee.id);
// TODO: Handle the case when body is undefined
assert.ok((body as any).debuggee);
assert.ok((body as any).debuggee.id);
done();
});
});
Expand All @@ -66,15 +67,18 @@ describe('Controller', function() {
// TODO: Determine if statusMessage should be made optional.
statusMessage: null
});
controller.register(debuggee, function(err, body) {
// TODO: Determine if the body parameter should be used.
controller.register(debuggee, function(err, _body) {
// TODO: Only 1 parameter is expected. Fix this.
(assert as any).ifError(err, 'should be able to register successfully');

controller.listBreakpoints(debuggee, function(err, response, body) {
// TODO: Determine if the response parameter should be used.
controller.listBreakpoints(debuggee, function(err, _response, body) {
// TODO: Only 1 parameter is expected. Fix this.
(assert as any).ifError(err, 'should successfully list breakpoints');
assert.ok(body);
assert.ok(body.nextWaitToken);
// TODO: Handle the case when body is undefined
assert.ok((body as any).nextWaitToken);
done();
});
});
Expand All @@ -91,24 +95,28 @@ describe('Controller', function() {
// TODO: Determine if statusMessage should be made optional.
statusMessage: null
});
controller.register(debuggee, function(err, body) {
// TODO: Determine if the body parameter should be used.
controller.register(debuggee, function(err, _body) {
// TODO: Only 1 parameter is expected. Fix this.
(assert as any).ifError(err, 'should be able to register successfully');

// First list should set the wait token
controller.listBreakpoints(debuggee, function(err, response, body) {
// TODO: Determine if the response parameter should be used.
controller.listBreakpoints(debuggee, function(err, _response, body) {
// TODO: Only 1 parameter is expected. Fix this.
(assert as any).ifError(err, 'should successfully list breakpoints');
assert.ok(body);
assert.ok(body.nextWaitToken);
// TODO: Handle the case when body is undefined
assert.ok((body as any).nextWaitToken);
// Second list should block until the wait timeout
controller.listBreakpoints(debuggee, function(err, response, body) {
// TODO: Determine if the response parameter should be used.
controller.listBreakpoints(debuggee, function(err, _response, body) {
// TODO: Only 1 parameter is expected. Fix this.
(assert as any).ifError(err, 'should successfully list breakpoints');
assert.ok(body);
assert.ok(body.nextWaitToken);
assert.ok((body as any).nextWaitToken);
// waitExpired will only be set if successOnTimeout was given correctly
assert.ok(body.waitExpired);
assert.ok((body as any).waitExpired);
done();
});
});
Expand Down
92 changes: 57 additions & 35 deletions system-test/test-e2e.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,16 @@
* limitations under the License.
*/

import * as apiTypes from '../src/types/api-types';

import * as assert from 'assert';
import * as util from 'util';
import * as _ from 'lodash'; // for _.find. Can't use ES6 yet.
import * as cp from 'child_process';
import * as semver from 'semver';
const promisifyAll = require('@google-cloud/common').util.promisifyAll;
import {Debug} from '../src/debug';
import {Debuggee} from '../src/debuggee';
import {Debugger} from '../test/debugger';

const CLUSTER_WORKERS = 3;
Expand All @@ -29,18 +32,24 @@ const CLUSTER_WORKERS = 3;
const FILENAME = 'build/test/fixtures/fib.js';

const delay = function(delayTimeMS: number): Promise<void> {
return new Promise(function(resolve, reject) {
// TODO: Determine if the reject parameter should be used.
return new Promise(function(resolve, _reject) {
setTimeout(resolve, delayTimeMS);
});
};

interface Child {
transcript: string;
process?: cp.ChildProcess;
}

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

let debuggeeId: string;
let projectId: string;
let children = [];
let debuggeeId: string|null;
let projectId: string|null;
let children: Child[] = [];

before(function() {
promisifyAll(Debugger);
Expand All @@ -53,7 +62,8 @@ describe('@google-cloud/debug end-to-end behavior', function () {
let numChildrenReady = 0;

// Process a status message sent from a child process.
const handler = function(c) {
// TODO: Determine if this type signature is correct
const handler = function(c: { error: Error|null, debuggeeId: string, projectId: string}) {
console.log(c);
if (c.error) {
reject(new Error('A child reported the following error: ' + c.error));
Expand All @@ -80,8 +90,8 @@ describe('@google-cloud/debug end-to-end behavior', function () {
// Handle stdout/stderr output from a child process. More specifically,
// write the child process's output to a transcript.
// Each child has its own transcript.
const stdoutHandler = function(index) {
return function(chunk) {
const stdoutHandler = function(index: number) {
return function(chunk: string) {
children[index].transcript += chunk;
};
};
Expand Down Expand Up @@ -111,12 +121,13 @@ describe('@google-cloud/debug end-to-end behavior', function () {
// Create a promise for each child that resolves when that child exits.
const childExitPromises = children.map(function (child) {
console.log(child.transcript);
child.process.kill();
// TODO: Handle the case when child.process is undefined
(child.process as any).kill();
return new Promise(function(resolve, reject) {
const timeout = setTimeout(function() {
reject(new Error('A child process failed to exit.'));
}, 3000);
child.process.on('exit', function() {
(child.process as any).on('exit', function() {
clearTimeout(timeout);
resolve();
});
Expand All @@ -134,39 +145,41 @@ describe('@google-cloud/debug end-to-end behavior', function () {
this.timeout(90 * 1000);
// Kick off promise chain by getting a list of debuggees
// TODO: Determine how to properly specify the signature of listDebuggees
return (api as any).listDebuggees(projectId).then(function(results) {
// TODO: Determine if this is the correct signature for `then`
return (api as any).listDebuggees(projectId).then(function(results: { [index: number]: Debuggee[] }) {
// Check that the debuggee created in this test is among the list of
// debuggees, then list its breakpoints
const debuggees = results[0];

const debuggees: Debuggee[] = results[0];

console.log('-- List of debuggees\n',
util.inspect(debuggees, { depth: null}));
assert.ok(debuggees, 'should get a valid ListDebuggees response');
// TODO: Fix this cast to any.
const result = _.find(debuggees, function(d: any) {
const result = _.find(debuggees, function(d: Debuggee) {
return d.id === debuggeeId;
});
assert.ok(result, 'should find the debuggee we just registered');
// TODO: Determine how to properly specify the signature of listDebuggees
return (api as any).listBreakpoints(debuggeeId);
}).then(function(results) {
// TODO: Determine if this type signature is correct.
}).then(function(results: { [index: number]: apiTypes.Breakpoint[]}) {
// Delete every breakpoint

const breakpoints = results[0];
const breakpoints: apiTypes.Breakpoint[] = results[0];

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

const promises = breakpoints.map(function(breakpoint) {
const promises = breakpoints.map(function(breakpoint: apiTypes.Breakpoint) {
// TODO: Determine how to properly specify the signature of listDebuggees
return (api as any).deleteBreakpoint(debuggeeId, breakpoint.id);
});

return Promise.all(promises);
}).then(function(results) {
// TODO: Determine if this type signature is correct
}).then(function(results: apiTypes.Breakpoint[]) {
// Set a breakpoint at which the debugger should write to a log

results.map(function(result) {
results.map(function(result: apiTypes.Breakpoint) {
assert.equal(result, '');
});
console.log('-- deleted');
Expand All @@ -181,7 +194,8 @@ describe('@google-cloud/debug end-to-end behavior', function () {
expressions: ['o'],
log_message_format: 'o is: $0'
});
}).then(function(results) {
// TODO: Determine if this type signature is correct.
}).then(function(results: apiTypes.Breakpoint[]) {
// Check that the breakpoint was set, and then wait for the log to be
// written to

Expand All @@ -190,14 +204,18 @@ describe('@google-cloud/debug end-to-end behavior', function () {
assert.ok(breakpoint, 'should have set a breakpoint');
assert.ok(breakpoint.id, 'breakpoint should have an id');
assert.ok(breakpoint.location, 'breakpoint should have a location');
assert.strictEqual(breakpoint.location.path, FILENAME);
// TODO: Handle the case when breakpoint.location is undefined
assert.strictEqual((breakpoint.location as any).path, FILENAME);

console.log('-- waiting before checking if the log was written');
return Promise.all([breakpoint, delay(10 * 1000)]);
}).then(function(results) {
// TODO: Determine if the results parameter should be used.
}).then(function(_results: apiTypes.Breakpoint[]) {

// Check the contents of the log, but keep the original breakpoint.

const breakpoint = results[0];
// TODO: This is never used. Determine if it should be used.
//const breakpoint = results[0];

children.forEach(function(child, index) {
assert(child.transcript.indexOf('o is: {"a":[1,"hi",true]}') !== -1,
Expand All @@ -216,7 +234,7 @@ describe('@google-cloud/debug end-to-end behavior', function () {
expressions: ['process'], // Process for large variable
condition: 'n === 10'
});
}).then(function(results) {
}).then(function(results: apiTypes.Breakpoint[]) {
// Check that the breakpoint was set, and then wait for the breakpoint to
// be hit

Expand All @@ -226,19 +244,20 @@ describe('@google-cloud/debug end-to-end behavior', function () {
assert.ok(breakpoint, 'should have set a breakpoint');
assert.ok(breakpoint.id, 'breakpoint should have an id');
assert.ok(breakpoint.location, 'breakpoint should have a location');
assert.strictEqual(breakpoint.location.path, FILENAME);
// TODO: Handle the case when breakpoint.location is undefined
assert.strictEqual((breakpoint.location as any).path, FILENAME);

console.log('-- waiting before checking if breakpoint was hit');
return Promise.all([breakpoint, delay(10 * 1000)]);
}).then(function(results) {
}).then(function(results: apiTypes.Breakpoint[]) {
// Get the breakpoint

const breakpoint = results[0];

console.log('-- now checking if the breakpoint was hit');
// TODO: Determine how to properly specify the signature of listDebuggees
return (api as any).getBreakpoint(debuggeeId, breakpoint.id);
}).then(function(results) {
}).then(function(results: apiTypes.Breakpoint[]) {
// Check that the breakpoint was hit and contains the correct information,
// which ends the test

Expand All @@ -260,7 +279,8 @@ describe('@google-cloud/debug end-to-end behavior', function () {
arg = _.find(top.arguments, {name: 'n'});
}
assert.ok(arg, 'should find the n argument');
assert.strictEqual(arg.value, '10');
// TODO: Handle the case when arg is undefined
assert.strictEqual((arg as any).value, '10');
console.log('-- checking log point was hit again');
children.forEach(function(child) {
const count = (child.transcript
Expand Down Expand Up @@ -291,7 +311,8 @@ describe('@google-cloud/debug end-to-end behavior', function () {
this.timeout(15 * 1000);
// Kick off promise chain by getting a list of debuggees
// TODO: Determine how to properly specify the signature of listDebuggees
return (api as any).listDebuggees(projectId).then(function(results) {
// TODO: Determine if this is the correct signature for then
return (api as any).listDebuggees(projectId).then(function(results: { [index: number]: Debuggee[] }) {
// Check that the debuggee created in this test is among the list of
// debuggees, then list its breakpoints

Expand All @@ -308,10 +329,10 @@ describe('@google-cloud/debug end-to-end behavior', function () {

// TODO: Determine how to properly specify the signature of listDebuggees
return (api as any).listBreakpoints(debuggeeId);
}).then(function(results) {
}).then(function(results: { [index: number]: apiTypes.Breakpoint[] }) {
// Delete every breakpoint

const breakpoints = results[0];
const breakpoints: apiTypes.Breakpoint[] = results[0];

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

Expand All @@ -321,7 +342,7 @@ describe('@google-cloud/debug end-to-end behavior', function () {
});

return Promise.all(promises);
}).then(function(results) {
}).then(function(results: Promise<void>[]) {
// Set a breakpoint at which the debugger should write to a log

results.map(function(result) {
Expand All @@ -339,19 +360,20 @@ describe('@google-cloud/debug end-to-end behavior', function () {
expressions: ['o'],
log_message_format: 'o is: $0'
});
}).then(function(results) {
}).then(function(results: apiTypes.Breakpoint[]) {
// Check that the breakpoint was set, and then wait for the log to be
// written to
const breakpoint = results[0];

assert.ok(breakpoint, 'should have set a breakpoint');
assert.ok(breakpoint.id, 'breakpoint should have an id');
assert.ok(breakpoint.location, 'breakpoint should have a location');
assert.strictEqual(breakpoint.location.path, FILENAME);
// TODO: Handle the case when breakpoint.location is undefined
assert.strictEqual((breakpoint.location as any).path, FILENAME);

console.log('-- waiting before checking if the log was written');
return Promise.all([breakpoint, delay(10 * 1000)]);
}).then(function(results) {
}).then(function(results: apiTypes.Breakpoint[]) {
// Check that the contents of the log is correct

const breakpoint = results[0];
Expand Down
2 changes: 1 addition & 1 deletion test/auth-request.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import * as http from 'http';

// TODO: Make the type of `options` more precise
export default function(options: any, callback: (err: Error, body: any, response: http.ServerResponse) => void) {
request(options, function(err, response, body) {
request(options, function(err: Error, response: http.ServerResponse, body: any) {
callback(err, body, response);
});
};
1 change: 0 additions & 1 deletion test/debugger.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ const qs: { parse: (qs: any, sep?: string, eq?: string,
options?: { maxKeys?: number }) => any,
stringify: (obj: object|string|boolean|number, sep?: string,
eq?: string, name?: string) => string} = require('querystring');
import * as util from 'util';

/** @const {string} Cloud Debug API endpoint */
const API = 'https://clouddebugger.googleapis.com/v2/debugger';
Expand Down
2 changes: 1 addition & 1 deletion test/misc/bench.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ const fib = require('./bench-code.js');
const logger = new Logger(config.logLevel);
assert.ok(v8debugapi.init(logger, config));

function bench(message, f) {
function bench(message: any, f: any) {
let t = process.hrtime();
f();
t = process.hrtime(t);
Expand Down
Loading

0 comments on commit 40365fb

Please sign in to comment.