Skip to content

Commit

Permalink
Fix all typescript errors when compiled in strict mode #5 (#4421)
Browse files Browse the repository at this point in the history
* corrections

* more corrections

* Merge conflicts

* skip

* Update src/test/debugger/misc.test.ts

Co-Authored-By: karrtikr <karraj@microsoft.com>

* Skip more tests

* corrections

* corrections

* corrected CI

* Delete jupyterServerManager.unit.test.ts

* code reviews

* skip more tests
  • Loading branch information
Kartik Raj committed Mar 4, 2019
1 parent 0d56551 commit 35177a4
Show file tree
Hide file tree
Showing 17 changed files with 140 additions and 104 deletions.
2 changes: 1 addition & 1 deletion src/client/unittests/common/managers/baseTestManager.ts
Expand Up @@ -415,7 +415,7 @@ export abstract class BaseTestManager implements ITestManager {

private createDiagnostics(message: IPythonUnitTestMessage): Diagnostic {
const stackStart = message.locationStack![0];
const diagPrefix = this.unitTestDiagnosticService.getMessagePrefix(message.status);
const diagPrefix = this.unitTestDiagnosticService.getMessagePrefix(message.status!);
const severity = this.unitTestDiagnosticService.getSeverity(message.severity)!;
const diagMsg = message.message!.split('\n')[0];
const diagnostic = new Diagnostic(stackStart.location.range, `${diagPrefix ? `${diagPrefix}: ` : ''}${diagMsg}`, severity);
Expand Down
2 changes: 1 addition & 1 deletion src/test/common.ts
Expand Up @@ -399,7 +399,7 @@ export async function unzip(zipFile: string, targetFolder: string): Promise<void
storeEntries: true
});
zip.on('ready', async () => {
zip.extract('extension', targetFolder, err => {
zip.extract('extension', targetFolder, (err: any) => {
if (err) {
reject(err);
} else {
Expand Down
2 changes: 1 addition & 1 deletion src/test/common/configSettings.test.ts
Expand Up @@ -27,7 +27,7 @@ suite('Configuration Settings', () => {
settingValue = systemVariables.resolve(settingValue);
}
// tslint:disable-next-line:no-any
const pythonSettingValue = (pythonSettings[key] as string);
const pythonSettingValue = ((pythonSettings as any)[key] as string);
if (key.endsWith('Path') && IS_WINDOWS) {
assert.equal(settingValue.toUpperCase(), pythonSettingValue.toUpperCase(), `Setting ${key} not the same`);
} else if (key === 'workspaceSymbols' && IS_WINDOWS) {
Expand Down
21 changes: 14 additions & 7 deletions src/test/common/configSettings/configSettings.unit.test.ts
Expand Up @@ -48,25 +48,29 @@ suite('Python Settings', () => {
// string settings
for (const name of ['pythonPath', 'venvPath', 'condaPath', 'pipenvPath', 'envFile']) {
config.setup(c => c.get<string>(name))
.returns(() => sourceSettings[name]);
// tslint:disable-next-line:no-any
.returns(() => (sourceSettings as any)[name]);
}
if (sourceSettings.jediEnabled) {
config.setup(c => c.get<string>('jediPath'))
.returns(() => sourceSettings.jediPath);
}
for (const name of ['venvFolders']) {
config.setup(c => c.get<string[]>(name))
.returns(() => sourceSettings[name]);
// tslint:disable-next-line:no-any
.returns(() => (sourceSettings as any)[name]);
}

// boolean settings
for (const name of ['downloadLanguageServer', 'jediEnabled', 'autoUpdateLanguageServer']) {
config.setup(c => c.get<boolean>(name, true))
.returns(() => sourceSettings[name]);
// tslint:disable-next-line:no-any
.returns(() => (sourceSettings as any)[name]);
}
for (const name of ['disableInstallationCheck', 'globalModuleInstallation']) {
config.setup(c => c.get<boolean>(name))
.returns(() => sourceSettings[name]);
// tslint:disable-next-line:no-any
.returns(() => (sourceSettings as any)[name]);
}

// number settings
Expand Down Expand Up @@ -147,7 +151,8 @@ suite('Python Settings', () => {
settings.update(config.object);

for (const key of Object.keys(expected.formatting)) {
expect(settings.formatting[key]).to.be.deep.equal(expected.formatting[key]);
// tslint:disable-next-line:no-any
expect((settings.formatting as any)[key]).to.be.deep.equal((expected.formatting as any)[key]);
}
config.verifyAll();
});
Expand All @@ -172,8 +177,10 @@ suite('Python Settings', () => {
if (!key.endsWith('path')) {
continue;
}
const expectedPath = untildify(expected.formatting[key]);
expect(settings.formatting[key]).to.be.equal(expectedPath);
// tslint:disable-next-line:no-any
const expectedPath = untildify((expected.formatting as any)[key]);
// tslint:disable-next-line:no-any
expect((settings.formatting as any)[key]).to.be.equal(expectedPath);
}
config.verifyAll();
});
Expand Down
8 changes: 4 additions & 4 deletions src/test/common/configuration/service.test.ts
Expand Up @@ -2,7 +2,7 @@
// Licensed under the MIT License.
import { expect } from 'chai';
import { workspace } from 'vscode';
import { IAsyncDisposableRegistry, IConfigurationService, IDisposable } from '../../../client/common/types';
import { IAsyncDisposableRegistry, IConfigurationService } from '../../../client/common/types';
import { getExtensionSettings } from '../../common';
import { initialize } from '../../initialize';
import { UnitTestIocContainer } from '../../unittests/serviceRegistry';
Expand All @@ -17,7 +17,7 @@ suite('Configuration Service', () => {
});
teardown(() => ioc.dispose());

test('Ensure same instance of settings return', () => {
test('Ensure same instance of settings return', () => {
const workspaceUri = workspace.workspaceFolders![0].uri;
const settings = ioc.serviceContainer.get<IConfigurationService>(IConfigurationService).getSettings(workspaceUri);
const instanceIsSame = settings === getExtensionSettings(workspaceUri);
Expand All @@ -27,8 +27,8 @@ suite('Configuration Service', () => {
test('Ensure async registry works', async () => {
const asyncRegistry = ioc.serviceContainer.get<IAsyncDisposableRegistry>(IAsyncDisposableRegistry);
let disposed = false;
const disposable : IDisposable = {
dispose() : Promise<void> {
const disposable = {
dispose(): Promise<void> {
disposed = true;
return Promise.resolve();
}
Expand Down
15 changes: 9 additions & 6 deletions src/test/common/localize.unit.test.ts
Expand Up @@ -51,7 +51,7 @@ suite('localize tests', () => {
const funcs = Object.keys(namespace);

// Run every function, this should fill up our asked for keys collection
funcs.forEach((f : string) => {
funcs.forEach((f: string) => {
const func = namespace[f];
func();
});
Expand All @@ -61,19 +61,22 @@ suite('localize tests', () => {
// Now verify all of the asked for keys exist
const askedFor = localize.getAskedForCollection();
const missing = {};
Object.keys(askedFor).forEach((key : string) => {
Object.keys(askedFor).forEach((key: string) => {
// Now check that this key exists somewhere in the nls collection
if (!nlsCollection[key]) {
missing[key] = askedFor[key];
// tslint:disable-next-line:no-any
if (!(nlsCollection as any)[key]) {
// tslint:disable-next-line:no-any
(missing as any)[key] = askedFor[key];
}
});

// If any missing keys, output an error
const missingKeys = Object.keys(missing);
if (missingKeys && missingKeys.length > 0) {
let message = 'Missing keys. Add the following to package.nls.json:\n';
missingKeys.forEach((k : string) => {
message = message.concat(`\t"${k}" : "${missing[k]}",\n`);
missingKeys.forEach((k: string) => {
// tslint:disable-next-line:no-any
message = message.concat(`\t"${k}" : "${(missing as any)[k]}",\n`);
});
assert.fail(message);
}
Expand Down
2 changes: 1 addition & 1 deletion src/test/common/platform/filesystem.unit.test.ts
Expand Up @@ -97,7 +97,7 @@ suite('FileSystem', () => {
await fileSystem.createTemporaryFile('.tmp').then((tf: TemporaryFile) => {
expect(tf).to.not.equal(undefined, 'Error trying to create a temporary file');
const writeStream = fileSystem.createWriteStream(tf.filePath);
writeStream.write('hello', 'utf8', (err) => {
writeStream.write('hello', 'utf8', (err: Error) => {
expect(err).to.equal(undefined, `Failed to write to a temp file, error is ${err}`);
});
}, (failReason) => {
Expand Down
2 changes: 1 addition & 1 deletion src/test/common/socketCallbackHandler.test.ts
Expand Up @@ -95,7 +95,7 @@ class MockSocketClient {
}
public start(): Promise<any> {
this.def = createDeferred<any>();
this.socket = net.connect(this.port, this.connectionListener.bind(this));
this.socket = net.connect(this.port as any, this.connectionListener.bind(this));
return this.def.promise;
}
private connectionListener() {
Expand Down
79 changes: 47 additions & 32 deletions src/test/common/socketStream.test.ts
Expand Up @@ -4,68 +4,75 @@
//

// Place this right on top
import { initialize } from './../initialize';
// The module 'assert' provides assertion methods from node
import * as assert from 'assert';

// You can import and use all API from the 'vscode' module
// as well as import your extension to test it
import * as vscode from 'vscode';
import { SocketStream } from '../../client/common/net/socket/SocketStream';
import * as net from 'net';
const uint64be = require("uint64be");
import { SocketStream } from '../../client/common/net/socket/SocketStream';
// tslint:disable:no-require-imports no-var-requires
const uint64be = require('uint64be');

class MockSocket {
private _data: string;
// tslint:disable-next-line:no-any
private _rawDataWritten: any;
constructor() {
this._data = '';
}
private _data: string;
private _rawDataWritten: any;
public get dataWritten(): string {
return this._data;
}
// tslint:disable-next-line:no-any
public get rawDataWritten(): any {
return this._rawDataWritten;
}
write(data: any) {
this._data = data + '';
// tslint:disable-next-line:no-any
public write(data: any) {
this._data = `${data}` + '';
this._rawDataWritten = data;
}
}
// Defines a Mocha test suite to group tests of similar kind together
// tslint:disable-next-line:max-func-body-length
suite('SocketStream', () => {
test('Read Byte', done => {
let buffer = new Buffer("X");
const buffer = new Buffer('X');
const byteValue = buffer[0];
const socket = new MockSocket();
const stream = new SocketStream((socket as any) as net.Socket, buffer)
// tslint:disable-next-line:no-any
const stream = new SocketStream((socket as any) as net.Socket, buffer);

assert.equal(stream.ReadByte(), byteValue);
done();
});
test('Read Int32', done => {
const num = 1234;
const socket = new MockSocket();
let buffer = uint64be.encode(num);
const stream = new SocketStream((socket as any) as net.Socket, buffer)
const buffer = uint64be.encode(num);
// tslint:disable-next-line:no-any
const stream = new SocketStream((socket as any) as net.Socket, buffer);

assert.equal(stream.ReadInt32(), num);
done();
});
test('Read Int64', done => {
const num = 9007199254740993;
const socket = new MockSocket();
let buffer = uint64be.encode(num);
const stream = new SocketStream((socket as any) as net.Socket, buffer)
const buffer = uint64be.encode(num);
// tslint:disable-next-line:no-any
const stream = new SocketStream((socket as any) as net.Socket, buffer);

assert.equal(stream.ReadInt64(), num);
done();
});
test('Read Ascii String', done => {
const message = 'Hello World';
const socket = new MockSocket();
let buffer = Buffer.concat([new Buffer('A'), uint64be.encode(message.length), new Buffer(message)]);
const stream = new SocketStream((socket as any) as net.Socket, buffer)
const buffer = Buffer.concat([new Buffer('A'), uint64be.encode(message.length), new Buffer(message)]);
// tslint:disable-next-line:no-any
const stream = new SocketStream((socket as any) as net.Socket, buffer);

assert.equal(stream.ReadString(), message);
done();
Expand All @@ -74,8 +81,9 @@ suite('SocketStream', () => {
const message = 'Hello World - Функция проверки ИНН и КПП - 说明';
const socket = new MockSocket();
const stringBuffer = new Buffer(message);
let buffer = Buffer.concat([Buffer.concat([new Buffer('U'), uint64be.encode(stringBuffer.byteLength)]), stringBuffer]);
const stream = new SocketStream((socket as any) as net.Socket, buffer)
const buffer = Buffer.concat([Buffer.concat([new Buffer('U'), uint64be.encode(stringBuffer.byteLength)]), stringBuffer]);
// tslint:disable-next-line:no-any
const stream = new SocketStream((socket as any) as net.Socket, buffer);

assert.equal(stream.ReadString(), message);
done();
Expand All @@ -88,11 +96,12 @@ suite('SocketStream', () => {
// Write part of a second message
const partOfSecondMessage = Buffer.concat([new Buffer('A'), uint64be.encode(message.length)]);
buffer = Buffer.concat([buffer, partOfSecondMessage]);
const stream = new SocketStream((socket as any) as net.Socket, buffer)
// tslint:disable-next-line:no-any
const stream = new SocketStream((socket as any) as net.Socket, buffer);

stream.BeginTransaction();
assert.equal(stream.ReadString(), message, 'First message not read properly');
const secondMessage = stream.ReadString();
stream.ReadString();
assert.equal(stream.HasInsufficientDataForReading, true, 'Should not have sufficient data for reading');
stream.RollBackTransaction();
assert.equal(stream.ReadString(), message, 'First message not read properly after rolling back transaction');
Expand All @@ -106,11 +115,12 @@ suite('SocketStream', () => {
// Write part of a second message
const partOfSecondMessage = Buffer.concat([new Buffer('A'), uint64be.encode(message.length)]);
buffer = Buffer.concat([buffer, partOfSecondMessage]);
const stream = new SocketStream((socket as any) as net.Socket, buffer)
// tslint:disable-next-line:no-any
const stream = new SocketStream((socket as any) as net.Socket, buffer);

stream.BeginTransaction();
assert.equal(stream.ReadString(), message, 'First message not read properly');
const secondMessage = stream.ReadString();
stream.ReadString();
assert.equal(stream.HasInsufficientDataForReading, true, 'Should not have sufficient data for reading');
stream.EndTransaction();
stream.RollBackTransaction();
Expand All @@ -121,50 +131,55 @@ suite('SocketStream', () => {
const message = 'Hello World';
const buffer = new Buffer('');
const socket = new MockSocket();
const stream = new SocketStream((socket as any) as net.Socket, buffer)
// tslint:disable-next-line:no-any
const stream = new SocketStream((socket as any) as net.Socket, buffer);
stream.Write(new Buffer(message));

assert.equal(socket.dataWritten, message)
assert.equal(socket.dataWritten, message);
done();
});
test('Write Int32', done => {
const num = 1234;
const buffer = new Buffer('');
const socket = new MockSocket();
const stream = new SocketStream((socket as any) as net.Socket, buffer)
// tslint:disable-next-line:no-any
const stream = new SocketStream((socket as any) as net.Socket, buffer);
stream.WriteInt32(num);

assert.equal(uint64be.decode(socket.rawDataWritten), num)
assert.equal(uint64be.decode(socket.rawDataWritten), num);
done();
});
test('Write Int64', done => {
const num = 9007199254740993;
const buffer = new Buffer('');
const socket = new MockSocket();
const stream = new SocketStream((socket as any) as net.Socket, buffer)
// tslint:disable-next-line:no-any
const stream = new SocketStream((socket as any) as net.Socket, buffer);
stream.WriteInt64(num);

assert.equal(uint64be.decode(socket.rawDataWritten), num)
assert.equal(uint64be.decode(socket.rawDataWritten), num);
done();
});
test('Write Ascii String', done => {
const message = 'Hello World';
const buffer = new Buffer('');
const socket = new MockSocket();
const stream = new SocketStream((socket as any) as net.Socket, buffer)
// tslint:disable-next-line:no-any
const stream = new SocketStream((socket as any) as net.Socket, buffer);
stream.WriteString(message);

assert.equal(socket.dataWritten, message)
assert.equal(socket.dataWritten, message);
done();
});
test('Write Unicode String', done => {
const message = 'Hello World - Функция проверки ИНН и КПП - 说明';
const buffer = new Buffer('');
const socket = new MockSocket();
const stream = new SocketStream((socket as any) as net.Socket, buffer)
// tslint:disable-next-line:no-any
const stream = new SocketStream((socket as any) as net.Socket, buffer);
stream.WriteString(message);

assert.equal(socket.dataWritten, message)
assert.equal(socket.dataWritten, message);
done();
});
});
4 changes: 2 additions & 2 deletions src/test/common/terminals/helper.unit.test.ts
Expand Up @@ -186,7 +186,7 @@ suite('Terminal Service helpers', () => {
test('Ensure empty args are ignored', async () => {
getNamesAndValues<TerminalShellType>(TerminalShellType).forEach(item => {
const command = 'python3.7.exe';
const args = [];
const args: string[] = [];
const commandPrefix = (item.value === TerminalShellType.powershell || item.value === TerminalShellType.powershellCore) ? '& ' : '';
const expectedTerminalCommand = `${commandPrefix}${command}`;

Expand All @@ -198,7 +198,7 @@ suite('Terminal Service helpers', () => {
test('Ensure empty args are ignored with s in command', async () => {
getNamesAndValues<TerminalShellType>(TerminalShellType).forEach(item => {
const command = 'c:\\python 3.7.exe';
const args = [];
const args: string[] = [];
const commandPrefix = (item.value === TerminalShellType.powershell || item.value === TerminalShellType.powershellCore) ? '& ' : '';
const expectedTerminalCommand = `${commandPrefix}${command.fileToCommandArgument()}`;

Expand Down

0 comments on commit 35177a4

Please sign in to comment.