Skip to content

Commit 35177a4

Browse files
author
Kartik Raj
authored
Fix all typescript errors when compiled in strict mode microsoft#5 (microsoft#4421)
* 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
1 parent 0d56551 commit 35177a4

17 files changed

Lines changed: 140 additions & 104 deletions

src/client/unittests/common/managers/baseTestManager.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -415,7 +415,7 @@ export abstract class BaseTestManager implements ITestManager {
415415

416416
private createDiagnostics(message: IPythonUnitTestMessage): Diagnostic {
417417
const stackStart = message.locationStack![0];
418-
const diagPrefix = this.unitTestDiagnosticService.getMessagePrefix(message.status);
418+
const diagPrefix = this.unitTestDiagnosticService.getMessagePrefix(message.status!);
419419
const severity = this.unitTestDiagnosticService.getSeverity(message.severity)!;
420420
const diagMsg = message.message!.split('\n')[0];
421421
const diagnostic = new Diagnostic(stackStart.location.range, `${diagPrefix ? `${diagPrefix}: ` : ''}${diagMsg}`, severity);

src/test/common.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -399,7 +399,7 @@ export async function unzip(zipFile: string, targetFolder: string): Promise<void
399399
storeEntries: true
400400
});
401401
zip.on('ready', async () => {
402-
zip.extract('extension', targetFolder, err => {
402+
zip.extract('extension', targetFolder, (err: any) => {
403403
if (err) {
404404
reject(err);
405405
} else {

src/test/common/configSettings.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ suite('Configuration Settings', () => {
2727
settingValue = systemVariables.resolve(settingValue);
2828
}
2929
// tslint:disable-next-line:no-any
30-
const pythonSettingValue = (pythonSettings[key] as string);
30+
const pythonSettingValue = ((pythonSettings as any)[key] as string);
3131
if (key.endsWith('Path') && IS_WINDOWS) {
3232
assert.equal(settingValue.toUpperCase(), pythonSettingValue.toUpperCase(), `Setting ${key} not the same`);
3333
} else if (key === 'workspaceSymbols' && IS_WINDOWS) {

src/test/common/configSettings/configSettings.unit.test.ts

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -48,25 +48,29 @@ suite('Python Settings', () => {
4848
// string settings
4949
for (const name of ['pythonPath', 'venvPath', 'condaPath', 'pipenvPath', 'envFile']) {
5050
config.setup(c => c.get<string>(name))
51-
.returns(() => sourceSettings[name]);
51+
// tslint:disable-next-line:no-any
52+
.returns(() => (sourceSettings as any)[name]);
5253
}
5354
if (sourceSettings.jediEnabled) {
5455
config.setup(c => c.get<string>('jediPath'))
5556
.returns(() => sourceSettings.jediPath);
5657
}
5758
for (const name of ['venvFolders']) {
5859
config.setup(c => c.get<string[]>(name))
59-
.returns(() => sourceSettings[name]);
60+
// tslint:disable-next-line:no-any
61+
.returns(() => (sourceSettings as any)[name]);
6062
}
6163

6264
// boolean settings
6365
for (const name of ['downloadLanguageServer', 'jediEnabled', 'autoUpdateLanguageServer']) {
6466
config.setup(c => c.get<boolean>(name, true))
65-
.returns(() => sourceSettings[name]);
67+
// tslint:disable-next-line:no-any
68+
.returns(() => (sourceSettings as any)[name]);
6669
}
6770
for (const name of ['disableInstallationCheck', 'globalModuleInstallation']) {
6871
config.setup(c => c.get<boolean>(name))
69-
.returns(() => sourceSettings[name]);
72+
// tslint:disable-next-line:no-any
73+
.returns(() => (sourceSettings as any)[name]);
7074
}
7175

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

149153
for (const key of Object.keys(expected.formatting)) {
150-
expect(settings.formatting[key]).to.be.deep.equal(expected.formatting[key]);
154+
// tslint:disable-next-line:no-any
155+
expect((settings.formatting as any)[key]).to.be.deep.equal((expected.formatting as any)[key]);
151156
}
152157
config.verifyAll();
153158
});
@@ -172,8 +177,10 @@ suite('Python Settings', () => {
172177
if (!key.endsWith('path')) {
173178
continue;
174179
}
175-
const expectedPath = untildify(expected.formatting[key]);
176-
expect(settings.formatting[key]).to.be.equal(expectedPath);
180+
// tslint:disable-next-line:no-any
181+
const expectedPath = untildify((expected.formatting as any)[key]);
182+
// tslint:disable-next-line:no-any
183+
expect((settings.formatting as any)[key]).to.be.equal(expectedPath);
177184
}
178185
config.verifyAll();
179186
});

src/test/common/configuration/service.test.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
// Licensed under the MIT License.
33
import { expect } from 'chai';
44
import { workspace } from 'vscode';
5-
import { IAsyncDisposableRegistry, IConfigurationService, IDisposable } from '../../../client/common/types';
5+
import { IAsyncDisposableRegistry, IConfigurationService } from '../../../client/common/types';
66
import { getExtensionSettings } from '../../common';
77
import { initialize } from '../../initialize';
88
import { UnitTestIocContainer } from '../../unittests/serviceRegistry';
@@ -17,7 +17,7 @@ suite('Configuration Service', () => {
1717
});
1818
teardown(() => ioc.dispose());
1919

20-
test('Ensure same instance of settings return', () => {
20+
test('Ensure same instance of settings return', () => {
2121
const workspaceUri = workspace.workspaceFolders![0].uri;
2222
const settings = ioc.serviceContainer.get<IConfigurationService>(IConfigurationService).getSettings(workspaceUri);
2323
const instanceIsSame = settings === getExtensionSettings(workspaceUri);
@@ -27,8 +27,8 @@ suite('Configuration Service', () => {
2727
test('Ensure async registry works', async () => {
2828
const asyncRegistry = ioc.serviceContainer.get<IAsyncDisposableRegistry>(IAsyncDisposableRegistry);
2929
let disposed = false;
30-
const disposable : IDisposable = {
31-
dispose() : Promise<void> {
30+
const disposable = {
31+
dispose(): Promise<void> {
3232
disposed = true;
3333
return Promise.resolve();
3434
}

src/test/common/localize.unit.test.ts

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ suite('localize tests', () => {
5151
const funcs = Object.keys(namespace);
5252

5353
// Run every function, this should fill up our asked for keys collection
54-
funcs.forEach((f : string) => {
54+
funcs.forEach((f: string) => {
5555
const func = namespace[f];
5656
func();
5757
});
@@ -61,19 +61,22 @@ suite('localize tests', () => {
6161
// Now verify all of the asked for keys exist
6262
const askedFor = localize.getAskedForCollection();
6363
const missing = {};
64-
Object.keys(askedFor).forEach((key : string) => {
64+
Object.keys(askedFor).forEach((key: string) => {
6565
// Now check that this key exists somewhere in the nls collection
66-
if (!nlsCollection[key]) {
67-
missing[key] = askedFor[key];
66+
// tslint:disable-next-line:no-any
67+
if (!(nlsCollection as any)[key]) {
68+
// tslint:disable-next-line:no-any
69+
(missing as any)[key] = askedFor[key];
6870
}
6971
});
7072

7173
// If any missing keys, output an error
7274
const missingKeys = Object.keys(missing);
7375
if (missingKeys && missingKeys.length > 0) {
7476
let message = 'Missing keys. Add the following to package.nls.json:\n';
75-
missingKeys.forEach((k : string) => {
76-
message = message.concat(`\t"${k}" : "${missing[k]}",\n`);
77+
missingKeys.forEach((k: string) => {
78+
// tslint:disable-next-line:no-any
79+
message = message.concat(`\t"${k}" : "${(missing as any)[k]}",\n`);
7780
});
7881
assert.fail(message);
7982
}

src/test/common/platform/filesystem.unit.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ suite('FileSystem', () => {
9797
await fileSystem.createTemporaryFile('.tmp').then((tf: TemporaryFile) => {
9898
expect(tf).to.not.equal(undefined, 'Error trying to create a temporary file');
9999
const writeStream = fileSystem.createWriteStream(tf.filePath);
100-
writeStream.write('hello', 'utf8', (err) => {
100+
writeStream.write('hello', 'utf8', (err: Error) => {
101101
expect(err).to.equal(undefined, `Failed to write to a temp file, error is ${err}`);
102102
});
103103
}, (failReason) => {

src/test/common/socketCallbackHandler.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ class MockSocketClient {
9595
}
9696
public start(): Promise<any> {
9797
this.def = createDeferred<any>();
98-
this.socket = net.connect(this.port, this.connectionListener.bind(this));
98+
this.socket = net.connect(this.port as any, this.connectionListener.bind(this));
9999
return this.def.promise;
100100
}
101101
private connectionListener() {

src/test/common/socketStream.test.ts

Lines changed: 47 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -4,68 +4,75 @@
44
//
55

66
// Place this right on top
7-
import { initialize } from './../initialize';
87
// The module 'assert' provides assertion methods from node
98
import * as assert from 'assert';
109

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

1817
class MockSocket {
18+
private _data: string;
19+
// tslint:disable-next-line:no-any
20+
private _rawDataWritten: any;
1921
constructor() {
2022
this._data = '';
2123
}
22-
private _data: string;
23-
private _rawDataWritten: any;
2424
public get dataWritten(): string {
2525
return this._data;
2626
}
27+
// tslint:disable-next-line:no-any
2728
public get rawDataWritten(): any {
2829
return this._rawDataWritten;
2930
}
30-
write(data: any) {
31-
this._data = data + '';
31+
// tslint:disable-next-line:no-any
32+
public write(data: any) {
33+
this._data = `${data}` + '';
3234
this._rawDataWritten = data;
3335
}
3436
}
3537
// Defines a Mocha test suite to group tests of similar kind together
38+
// tslint:disable-next-line:max-func-body-length
3639
suite('SocketStream', () => {
3740
test('Read Byte', done => {
38-
let buffer = new Buffer("X");
41+
const buffer = new Buffer('X');
3942
const byteValue = buffer[0];
4043
const socket = new MockSocket();
41-
const stream = new SocketStream((socket as any) as net.Socket, buffer)
44+
// tslint:disable-next-line:no-any
45+
const stream = new SocketStream((socket as any) as net.Socket, buffer);
4246

4347
assert.equal(stream.ReadByte(), byteValue);
4448
done();
4549
});
4650
test('Read Int32', done => {
4751
const num = 1234;
4852
const socket = new MockSocket();
49-
let buffer = uint64be.encode(num);
50-
const stream = new SocketStream((socket as any) as net.Socket, buffer)
53+
const buffer = uint64be.encode(num);
54+
// tslint:disable-next-line:no-any
55+
const stream = new SocketStream((socket as any) as net.Socket, buffer);
5156

5257
assert.equal(stream.ReadInt32(), num);
5358
done();
5459
});
5560
test('Read Int64', done => {
5661
const num = 9007199254740993;
5762
const socket = new MockSocket();
58-
let buffer = uint64be.encode(num);
59-
const stream = new SocketStream((socket as any) as net.Socket, buffer)
63+
const buffer = uint64be.encode(num);
64+
// tslint:disable-next-line:no-any
65+
const stream = new SocketStream((socket as any) as net.Socket, buffer);
6066

6167
assert.equal(stream.ReadInt64(), num);
6268
done();
6369
});
6470
test('Read Ascii String', done => {
6571
const message = 'Hello World';
6672
const socket = new MockSocket();
67-
let buffer = Buffer.concat([new Buffer('A'), uint64be.encode(message.length), new Buffer(message)]);
68-
const stream = new SocketStream((socket as any) as net.Socket, buffer)
73+
const buffer = Buffer.concat([new Buffer('A'), uint64be.encode(message.length), new Buffer(message)]);
74+
// tslint:disable-next-line:no-any
75+
const stream = new SocketStream((socket as any) as net.Socket, buffer);
6976

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

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

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

111121
stream.BeginTransaction();
112122
assert.equal(stream.ReadString(), message, 'First message not read properly');
113-
const secondMessage = stream.ReadString();
123+
stream.ReadString();
114124
assert.equal(stream.HasInsufficientDataForReading, true, 'Should not have sufficient data for reading');
115125
stream.EndTransaction();
116126
stream.RollBackTransaction();
@@ -121,50 +131,55 @@ suite('SocketStream', () => {
121131
const message = 'Hello World';
122132
const buffer = new Buffer('');
123133
const socket = new MockSocket();
124-
const stream = new SocketStream((socket as any) as net.Socket, buffer)
134+
// tslint:disable-next-line:no-any
135+
const stream = new SocketStream((socket as any) as net.Socket, buffer);
125136
stream.Write(new Buffer(message));
126137

127-
assert.equal(socket.dataWritten, message)
138+
assert.equal(socket.dataWritten, message);
128139
done();
129140
});
130141
test('Write Int32', done => {
131142
const num = 1234;
132143
const buffer = new Buffer('');
133144
const socket = new MockSocket();
134-
const stream = new SocketStream((socket as any) as net.Socket, buffer)
145+
// tslint:disable-next-line:no-any
146+
const stream = new SocketStream((socket as any) as net.Socket, buffer);
135147
stream.WriteInt32(num);
136148

137-
assert.equal(uint64be.decode(socket.rawDataWritten), num)
149+
assert.equal(uint64be.decode(socket.rawDataWritten), num);
138150
done();
139151
});
140152
test('Write Int64', done => {
141153
const num = 9007199254740993;
142154
const buffer = new Buffer('');
143155
const socket = new MockSocket();
144-
const stream = new SocketStream((socket as any) as net.Socket, buffer)
156+
// tslint:disable-next-line:no-any
157+
const stream = new SocketStream((socket as any) as net.Socket, buffer);
145158
stream.WriteInt64(num);
146159

147-
assert.equal(uint64be.decode(socket.rawDataWritten), num)
160+
assert.equal(uint64be.decode(socket.rawDataWritten), num);
148161
done();
149162
});
150163
test('Write Ascii String', done => {
151164
const message = 'Hello World';
152165
const buffer = new Buffer('');
153166
const socket = new MockSocket();
154-
const stream = new SocketStream((socket as any) as net.Socket, buffer)
167+
// tslint:disable-next-line:no-any
168+
const stream = new SocketStream((socket as any) as net.Socket, buffer);
155169
stream.WriteString(message);
156170

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

167-
assert.equal(socket.dataWritten, message)
182+
assert.equal(socket.dataWritten, message);
168183
done();
169184
});
170185
});

src/test/common/terminals/helper.unit.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,7 @@ suite('Terminal Service helpers', () => {
186186
test('Ensure empty args are ignored', async () => {
187187
getNamesAndValues<TerminalShellType>(TerminalShellType).forEach(item => {
188188
const command = 'python3.7.exe';
189-
const args = [];
189+
const args: string[] = [];
190190
const commandPrefix = (item.value === TerminalShellType.powershell || item.value === TerminalShellType.powershellCore) ? '& ' : '';
191191
const expectedTerminalCommand = `${commandPrefix}${command}`;
192192

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

0 commit comments

Comments
 (0)