Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Stricter tsconfig settings #50

Merged
merged 3 commits into from
Oct 28, 2019
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 18 additions & 17 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -61,13 +61,15 @@
"@types/http-server": "^0.10.0",
"@types/js-beautify": "^1.8.1",
"@types/lodash": "^4.14.144",
"@types/long": "^4.0.0",
"@types/minimist": "^1.2.0",
"@types/mkdirp": "^0.5.2",
"@types/mocha": "^5.2.7",
"@types/node": "^12.11.1",
"@types/puppeteer": "^1.20.2",
"@types/request-promise-native": "^1.0.17",
"@types/sinon": "^7.5.0",
"@types/tmp": "^0.1.0",
"@types/ws": "^6.0.1",
"chai": "^4.2.0",
"chai-string": "^1.5.0",
Expand Down
14 changes: 7 additions & 7 deletions src/adapter/threads.ts
Original file line number Diff line number Diff line change
Expand Up @@ -398,7 +398,7 @@ export class Thread implements VariableStoreDelegate {
}

this._pausedDetails = this._createPausedDetails(event);
this._pausedDetails[kPausedEventSymbol] = event;
Copy link
Member

@connor4312 connor4312 Oct 25, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure how much refactoring you wanna do here, but this is a good use case for a WeakMap (and actually most WeakMap polyfills work almost the same way as the code does here--defining a non-enumerable symbol on the key objects 😛 )

(this._pausedDetails as any)[kPausedEventSymbol] = event;
this._pausedVariables = new VariableStore(this._cdp, this);
scheduledPauseOnAsyncCall = undefined;
this._onThreadPaused();
Expand All @@ -425,7 +425,7 @@ export class Thread implements VariableStoreDelegate {

refreshStackTrace() {
if (this._pausedDetails)
this._pausedDetails = this._createPausedDetails(this._pausedDetails[kPausedEventSymbol]);
this._pausedDetails = this._createPausedDetails((this._pausedDetails as any)[kPausedEventSymbol]);
this._onThreadResumed();
this._onThreadPaused();
}
Expand Down Expand Up @@ -771,15 +771,15 @@ export class Thread implements VariableStoreDelegate {
}

scriptsFromSource(source: Source): Set<Script> {
return source[kScriptsSymbol] || new Set();
return (source as any)[kScriptsSymbol] || new Set();
}

_removeAllScripts() {
const scripts = Array.from(this._scripts.values());
this._scripts.clear();
this._scriptSources.clear();
for (const script of scripts) {
const set = script.source[kScriptsSymbol];
const set = (script.source as any)[kScriptsSymbol];
set.delete(script);
if (!set.size)
this._sourceContainer.removeSource(script.source);
Expand Down Expand Up @@ -824,9 +824,9 @@ export class Thread implements VariableStoreDelegate {

const script = { url: event.url, scriptId: event.scriptId, source, hash: event.hash };
this._scripts.set(event.scriptId, script);
if (!source[kScriptsSymbol])
source[kScriptsSymbol] = new Set();
source[kScriptsSymbol].add(script);
if (!(source as any)[kScriptsSymbol])
(source as any)[kScriptsSymbol] = new Set();
(source as any)[kScriptsSymbol].add(script);

if (!this._pauseOnSourceMapBreakpointId && event.sourceMapURL) {
// If we won't pause before executing this script, try to load source map
Expand Down
2 changes: 1 addition & 1 deletion src/common/objUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ export function caseInsensitiveMerge<V>(
return {};
}

const out = {};
const out: any = {};
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
const out: any = {};
const out: { [key: string]: V } = {};

should work

const caseMapping: { [key: string]: string } = Object.create(null); // prototype-free object
for (const obj of objs) {
if (!obj) {
Expand Down
16 changes: 9 additions & 7 deletions src/int-chrome/featureBasedSuits/attach.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,19 +9,20 @@ import { isWindows } from '../testSetup';
import { onUnhandledException } from '../utils/onUnhandledException';
import * as testUtils from '../testUtils';

const waitForOutput = testUtils.promiseDefer();

const testSpec = TestProjectSpec.fromTestPath('featuresTests/attachNoUrl');

let waitForOutput: testUtils.IDeferred<void>;

// TODO: The attach test is currently failing on MAC. We need to investigate it and fix it
((isWindows ? testUsing : testUsing.skip) as any)(
((isWindows ? testUsing : testUsing.skip) as typeof testUsing)(
'Attach without specifying an url parameter',
context =>
LaunchProject.attach(context, testSpec, undefined, {
async context => {
waitForOutput = await testUtils.getDeferred();
return LaunchProject.attach(context, testSpec, undefined, {
registerListeners: client => {
// This test tests 2 different things while attaching:
// 1. We don't get an unhandled error while attaching (due to Runtime.consoleAPICalled being called with a scriptId that hasn't been parsed yet)
onUnhandledException(client, exceptionMessage => waitForOutput.reject(exceptionMessage));
onUnhandledException(client, exceptionMessage => waitForOutput.reject(new Error(exceptionMessage)));

client.on('output', (args: DebugProtocol.OutputEvent) => {
// 2. We eventually see this console.log message, because we attached succesfully to the web-page
Expand All @@ -36,7 +37,8 @@ const testSpec = TestProjectSpec.fromTestPath('featuresTests/attachNoUrl');
}
});
},
}),
});
},
async () => {
await waitForOutput.promise;
},
Expand Down
14 changes: 8 additions & 6 deletions src/int-chrome/featureBasedSuits/invalidJavaScriptCode.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,23 +5,24 @@ import { testUsing } from '../fixtures/testUsing';
import { TestProjectSpec } from '../framework/frameworkTestSupport';
import { LaunchProject } from '../fixtures/launchProject';
import { onUnhandledException, onHandledError } from '../utils/onUnhandledException';
import { promiseDefer, promiseTimeout } from '../testUtils';
import { promiseTimeout, getDeferred, IDeferred } from '../testUtils';
import { IChromeLaunchConfiguration } from '../../configuration';

const waitForTestResult = promiseDefer();
let waitForTestResult: IDeferred<void>;

testUsing(
'No unhandled exceptions when we parse invalid JavaScript code. We get a handled error',
context =>
LaunchProject.launch(
async context => {
waitForTestResult = await getDeferred<void>();
return LaunchProject.launch(
context,
TestProjectSpec.fromTestPath('featuresTests/invalidJavaScriptCode'),
{} as IChromeLaunchConfiguration,
{
registerListeners: client => {
// We fail the test if we get an unhandled exception
onUnhandledException(client, exceptionMessage =>
waitForTestResult.reject(exceptionMessage),
waitForTestResult.reject(new Error(exceptionMessage)),
);
// We expect to get a handled error instead
onHandledError(client, async errorMessage => {
Expand All @@ -34,7 +35,8 @@ testUsing(
});
},
},
),
);
},
async _launchProject => {
await waitForTestResult.promise;
},
Expand Down
2 changes: 1 addition & 1 deletion src/int-chrome/testSetup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ function formLaunchArgs(

const argsWithDefaults = { ...chromeLaunchConfigDefaults, ...launchArgs };
for (let k in argsWithDefaults) {
launchArgs[k] = argsWithDefaults[k];
launchArgs[k] = (argsWithDefaults as any)[k]; // TODO@rob
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TIL multiline suggestions aren't a thing, somehow, but

Object.assign(launchArgs, argsWithDefaults)

should do the trick without casts

}
}

Expand Down
6 changes: 3 additions & 3 deletions src/int-chrome/testSupport/loggingReporter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,20 +20,20 @@ class LoggingReporter extends mocha.reporters.Spec {
}
});

runner.on('test', test => {
runner.on('test', () => {
this.inTest = true;
this.testLogs = [];
});

runner.on('pass', test => {
runner.on('pass', () => {
this.inTest = false;

if (LoggingReporter.alwaysDumpLogs) {
this.dumpLogs();
}
});

runner.on('fail', test => {
runner.on('fail', () => {
this.inTest = false;
this.dumpLogs();

Expand Down
4 changes: 2 additions & 2 deletions src/int-chrome/testSupport/testSetup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ const checkLogTest = (

function runTest(): Promise<any> {
return new Promise((resolve, reject) => {
const optionalCallback = e => {
const optionalCallback = (e: Error) => {
if (e) reject(e);
else resolve();
};
Expand Down Expand Up @@ -76,7 +76,7 @@ export type PatchLaunchArgsCb = (launchArgs: any) => Promise<void> | void;

let dc: ExtendedDebugClient;
function patchLaunchFn(patchLaunchArgsCb: PatchLaunchArgsCb): void {
function patchLaunchArgs(launchArgs): Promise<void> {
function patchLaunchArgs(launchArgs: any): Promise<void> {
launchArgs.request = 'launch';
launchArgs.trace = 'verbose';
const patchReturnVal = patchLaunchArgsCb(launchArgs);
Expand Down
31 changes: 17 additions & 14 deletions src/int-chrome/testUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,21 +73,24 @@ export const writeFileP = util.promisify(fs.writeFile);

export type PromiseOrNot<T> = T | Promise<T>;

export interface PromiseDefer<T> {
promise: Promise<void>;
resolve: (value?: T | PromiseLike<T>) => void;
reject: (reason?: any) => void;
}

export function promiseDefer<T>(): PromiseDefer<T> {
let resolveCallback;
let rejectCallback;
const promise = new Promise<void>((resolve, reject) => {
resolveCallback = resolve;
rejectCallback = reject;
export interface IDeferred<T> {
resolve: (result: T) => void;
reject: (err: Error) => void;
promise: Promise<T>;
}

export function getDeferred<T>(): Promise<IDeferred<T>> {
return new Promise(r => {
// Promise callback is called synchronously
let resolve: IDeferred<T>['resolve'] = () => { throw new Error('Deferred was resolved before intialization'); };
let reject: IDeferred<T>['reject'] = () => { throw new Error('Deferred was rejected before initialization'); };
let promise = new Promise<T>((_resolve, _reject) => {
resolve = _resolve;
reject = _reject;
});

r({ resolve, reject, promise });
});

return { promise, resolve: resolveCallback, reject: rejectCallback };
}

export function sleep(ms: number): Promise<void> {
Expand Down
5 changes: 3 additions & 2 deletions src/int-chrome/wizards/variables/variablesWizard.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,14 +72,15 @@ export class VariablesWizard {
public async assertStackFrameVariablesAre(stackFrame: StackFrameWizard, verifications: IExpectedVariables) {
const scopesWithModifiers = Object.keys(verifications);
const scopesWithoutModifiers = scopesWithModifiers.map(s => this.splitIntoScopeNameAndModifier(s)[0]);
const withoutModifiersToWith = new ValidatedMap(_.zip(scopesWithoutModifiers, scopesWithModifiers)) as any; // TODO@rob
const zippedScopes = _.zip(scopesWithoutModifiers, scopesWithModifiers) as [keyof IExpectedVariables, keyof IExpectedVariables][];
const withoutModifiersToWith = new ValidatedMap<keyof IExpectedVariables, keyof IExpectedVariables>(zippedScopes);
const manyScopes = await (stackFrame).variablesOfScopes(scopesWithoutModifiers);
for (const scope of manyScopes) {
const scopeNameWithModifier = withoutModifiersToWith.get(scope.scopeName)!;
const [, modifier] = this.splitIntoScopeNameAndModifier(scopeNameWithModifier);
switch (modifier) {
case '':
this.verificator.assertVariablesAre(scope.variables, verifications[scopeNameWithModifier]!);
this.verificator.assertVariablesAre(scope.variables, verifications[scopeNameWithModifier] as IScopeExpectedVariables);
break;
case 'contains':
this.verificator.assertVariablesValuesContain(scope.variables, <ManyVariablesValues>verifications[scopeNameWithModifier]!);
Expand Down
2 changes: 1 addition & 1 deletion src/nodeDebugConfigurationProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,7 @@ function createLaunchConfigFromContext(
dir += '/';
}
}
config['preLaunchTask'] = 'tsc: build - tsconfig.json';
(config as any)['preLaunchTask'] = 'tsc: build - tsconfig.json';
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can probably add this as preLaunchTask?: string; in IMandatedConfiguration

}
config['outFiles'] = ['${workspaceFolder}/' + dir + '**/*.js'];
}
Expand Down
2 changes: 1 addition & 1 deletion src/targets/browser/browserLauncher.ts
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ export class BrowserLauncher implements Launcher {
}

async finishLaunch(mainTarget: BrowserTarget): Promise<void> {
if (this._launchParams!.url && !this._launchParams!['skipNavigateForTest'])
if (this._launchParams!.url && !(this._launchParams as any)['skipNavigateForTest'])
await mainTarget.cdp().Page.navigate({ url: this._launchParams!.url });
}

Expand Down
Loading