Skip to content
This repository was archived by the owner on Oct 16, 2020. It is now read-only.

Commit 4454996

Browse files
committed
Fix types in tests
1 parent 7da07c7 commit 4454996

File tree

1 file changed

+75
-37
lines changed

1 file changed

+75
-37
lines changed

src/test/typescript-service-helpers.ts

Lines changed: 75 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import * as ts from 'typescript';
44
import { CompletionItemKind, CompletionList, DiagnosticSeverity, TextDocumentIdentifier, TextDocumentItem, WorkspaceEdit } from 'vscode-languageserver';
55
import { Command, Diagnostic, Hover, Location, SignatureHelp, SymbolInformation, SymbolKind } from 'vscode-languageserver-types';
66
import { LanguageClient, RemoteLanguageClient } from '../lang-handler';
7-
import { TextDocumentContentParams, WorkspaceFilesParams } from '../request-type';
7+
import { DependencyReference, PackageInformation, ReferenceInformation, TextDocumentContentParams, WorkspaceFilesParams } from '../request-type';
88
import { SymbolLocationInformation } from '../request-type';
99
import { TypeScriptService, TypeScriptServiceFactory } from '../typescript-service';
1010
import { toUnixPath, uri2path } from '../util';
@@ -847,7 +847,9 @@ export function describeTypeScriptService(createService: TypeScriptServiceFactor
847847

848848
describe('workspaceXreferences()', function (this: TestContext) {
849849
it('should return all references to a method', async function (this: TestContext) {
850-
const result = await this.service.workspaceXreferences({ query: { name: 'foo', kind: 'method', containerName: 'a' } }).reduce<jsonpatch.Operation, Location[]>(jsonpatch.applyReducer, null as any).toPromise();
850+
const result: ReferenceInformation[] = await this.service.workspaceXreferences({ query: { name: 'foo', kind: 'method', containerName: 'a' } })
851+
.reduce<jsonpatch.Operation, ReferenceInformation[]>(jsonpatch.applyReducer, null as any)
852+
.toPromise();
851853
assert.deepEqual(result, [{
852854
symbol: {
853855
filePath: 'a.ts',
@@ -872,7 +874,9 @@ export function describeTypeScriptService(createService: TypeScriptServiceFactor
872874
}]);
873875
} as any);
874876
it('should return all references to a method with hinted dependee package name', async function (this: TestContext) {
875-
const result = await this.service.workspaceXreferences({ query: { name: 'foo', kind: 'method', containerName: 'a' }, hints: { dependeePackageName: 'mypkg' } }).reduce<jsonpatch.Operation, Location[]>(jsonpatch.applyReducer, null as any).toPromise();
877+
const result: ReferenceInformation[] = await this.service.workspaceXreferences({ query: { name: 'foo', kind: 'method', containerName: 'a' }, hints: { dependeePackageName: 'mypkg' } })
878+
.reduce<jsonpatch.Operation, ReferenceInformation[]>(jsonpatch.applyReducer, null as any)
879+
.toPromise();
876880
assert.deepEqual(result, [{
877881
symbol: {
878882
filePath: 'a.ts',
@@ -901,7 +905,9 @@ export function describeTypeScriptService(createService: TypeScriptServiceFactor
901905
assert.deepEqual(result, []);
902906
} as any);
903907
it('should return all references to a symbol from a dependency', async function (this: TestContext) {
904-
const result = await this.service.workspaceXreferences({ query: { name: 'x', containerName: '' } }).reduce<jsonpatch.Operation, Location[]>(jsonpatch.applyReducer, null as any).toPromise();
908+
const result: ReferenceInformation[] = await this.service.workspaceXreferences({ query: { name: 'x', containerName: '' } })
909+
.reduce<jsonpatch.Operation, ReferenceInformation[]>(jsonpatch.applyReducer, null as any)
910+
.toPromise();
905911
assert.deepEqual(result, [{
906912
reference: {
907913
range: {
@@ -926,7 +932,9 @@ export function describeTypeScriptService(createService: TypeScriptServiceFactor
926932
}]);
927933
} as any);
928934
it('should return all references to all symbols if empty SymbolDescriptor query is passed', async function (this: TestContext) {
929-
const result = await this.service.workspaceXreferences({ query: {} }).reduce<jsonpatch.Operation, Location[]>(jsonpatch.applyReducer, null as any).toPromise();
935+
const result: ReferenceInformation[] = await this.service.workspaceXreferences({ query: {} })
936+
.reduce<jsonpatch.Operation, ReferenceInformation[]>(jsonpatch.applyReducer, null as any)
937+
.toPromise();
930938
assert.deepEqual(result, [
931939
{
932940
symbol: {
@@ -1174,7 +1182,9 @@ export function describeTypeScriptService(createService: TypeScriptServiceFactor
11741182

11751183
describe('workspaceXdependencies()', function (this: TestContext) {
11761184
it('should account for all dependencies', async function (this: TestContext) {
1177-
const result = await this.service.workspaceXdependencies().reduce<jsonpatch.Operation, Location[]>(jsonpatch.applyReducer, null as any).toPromise();
1185+
const result: DependencyReference[] = await this.service.workspaceXdependencies()
1186+
.reduce<jsonpatch.Operation, DependencyReference[]>(jsonpatch.applyReducer, null as any)
1187+
.toPromise();
11781188
assert.deepEqual(result, [
11791189
{ attributes: { name: 'babel-code-frame', version: '^6.16.0' }, hints: { dependeePackageName: 'tslint' } },
11801190
{ attributes: { name: 'findup-sync', version: '~0.3.0' }, hints: { dependeePackageName: 'tslint' } },
@@ -1191,7 +1201,9 @@ export function describeTypeScriptService(createService: TypeScriptServiceFactor
11911201
} as any);
11921202
describe('workspaceXpackages()', function (this: TestContext) {
11931203
it('should accournt for all packages', async function (this: TestContext) {
1194-
const result = await this.service.workspaceXpackages().reduce<jsonpatch.Operation, Location[]>(jsonpatch.applyReducer, null as any).toPromise();
1204+
const result: PackageInformation[] = await this.service.workspaceXpackages()
1205+
.reduce<jsonpatch.Operation, PackageInformation[]>(jsonpatch.applyReducer, null as any)
1206+
.toPromise();
11951207
assert.deepEqual(result, [{
11961208
package: {
11971209
name: 'tslint',
@@ -1300,7 +1312,10 @@ export function describeTypeScriptService(createService: TypeScriptServiceFactor
13001312
}]
13011313
});
13021314

1303-
assert.deepEqual(await this.service.textDocumentHover(hoverParams).reduce<jsonpatch.Operation, Location[]>(jsonpatch.applyReducer, null as any).toPromise(), {
1315+
const result: Hover = await this.service.textDocumentHover(hoverParams)
1316+
.reduce<jsonpatch.Operation, Hover>(jsonpatch.applyReducer, null as any)
1317+
.toPromise();
1318+
assert.deepEqual(result, {
13041319
range,
13051320
contents: [
13061321
{ language: 'typescript', value: 'let parameters: number[]' },
@@ -1338,7 +1353,10 @@ export function describeTypeScriptService(createService: TypeScriptServiceFactor
13381353
}
13391354
});
13401355

1341-
assert.deepEqual(await this.service.textDocumentHover(hoverParams).reduce<jsonpatch.Operation, Location[]>(jsonpatch.applyReducer, null as any).toPromise(), {
1356+
const result: Hover = await this.service.textDocumentHover(hoverParams)
1357+
.reduce<jsonpatch.Operation, Hover>(jsonpatch.applyReducer, null as any)
1358+
.toPromise();
1359+
assert.deepEqual(result, {
13421360
range,
13431361
contents: [
13441362
{ language: 'typescript', value: 'let parameters: any[]' },
@@ -1370,13 +1388,18 @@ export function describeTypeScriptService(createService: TypeScriptServiceFactor
13701388
}
13711389
};
13721390

1373-
assert.deepEqual(await this.service.textDocumentHover(hoverParams).reduce<jsonpatch.Operation, Location[]>(jsonpatch.applyReducer, null as any).toPromise(), {
1374-
range,
1375-
contents: [
1376-
{ language: 'typescript', value: 'let parameters: any[]' },
1377-
'**let**'
1378-
]
1379-
});
1391+
{
1392+
const result: Hover = await this.service.textDocumentHover(hoverParams)
1393+
.reduce<jsonpatch.Operation, Hover>(jsonpatch.applyReducer, null as any)
1394+
.toPromise();
1395+
assert.deepEqual(result, {
1396+
range,
1397+
contents: [
1398+
{ language: 'typescript', value: 'let parameters: any[]' },
1399+
'**let**'
1400+
]
1401+
});
1402+
}
13801403

13811404
await this.service.textDocumentDidOpen({
13821405
textDocument: {
@@ -1387,13 +1410,18 @@ export function describeTypeScriptService(createService: TypeScriptServiceFactor
13871410
}
13881411
});
13891412

1390-
assert.deepEqual(await this.service.textDocumentHover(hoverParams).reduce<jsonpatch.Operation, Location[]>(jsonpatch.applyReducer, null as any).toPromise(), {
1391-
range,
1392-
contents: [
1393-
{ language: 'typescript', value: 'let parameters: string[]' },
1394-
'**let**'
1395-
]
1396-
});
1413+
{
1414+
const result: Hover = await this.service.textDocumentHover(hoverParams)
1415+
.reduce<jsonpatch.Operation, Hover>(jsonpatch.applyReducer, null as any)
1416+
.toPromise();
1417+
assert.deepEqual(result, {
1418+
range,
1419+
contents: [
1420+
{ language: 'typescript', value: 'let parameters: string[]' },
1421+
'**let**'
1422+
]
1423+
});
1424+
}
13971425

13981426
await this.service.textDocumentDidChange({
13991427
textDocument: {
@@ -1405,27 +1433,37 @@ export function describeTypeScriptService(createService: TypeScriptServiceFactor
14051433
}]
14061434
});
14071435

1408-
assert.deepEqual(await this.service.textDocumentHover(hoverParams).reduce<jsonpatch.Operation, Location[]>(jsonpatch.applyReducer, null as any).toPromise(), {
1409-
range,
1410-
contents: [
1411-
{ language: 'typescript', value: 'let parameters: number[]' },
1412-
'**let**'
1413-
]
1414-
});
1436+
{
1437+
const result: Hover = await this.service.textDocumentHover(hoverParams)
1438+
.reduce<jsonpatch.Operation, Hover>(jsonpatch.applyReducer, null as any)
1439+
.toPromise();
1440+
assert.deepEqual(result, {
1441+
range,
1442+
contents: [
1443+
{ language: 'typescript', value: 'let parameters: number[]' },
1444+
'**let**'
1445+
]
1446+
});
1447+
}
14151448

14161449
await this.service.textDocumentDidClose({
14171450
textDocument: {
14181451
uri: rootUri + 'a.ts'
14191452
}
14201453
});
14211454

1422-
assert.deepEqual(await this.service.textDocumentHover(hoverParams).reduce<jsonpatch.Operation, Location[]>(jsonpatch.applyReducer, null as any).toPromise(), {
1423-
range,
1424-
contents: [
1425-
{ language: 'typescript', value: 'let parameters: any[]' },
1426-
'**let**'
1427-
]
1428-
});
1455+
{
1456+
const result: Hover = await this.service.textDocumentHover(hoverParams)
1457+
.reduce<jsonpatch.Operation, Hover>(jsonpatch.applyReducer, null as any)
1458+
.toPromise();
1459+
assert.deepEqual(result, {
1460+
range,
1461+
contents: [
1462+
{ language: 'typescript', value: 'let parameters: any[]' },
1463+
'**let**'
1464+
]
1465+
});
1466+
}
14291467
} as any);
14301468
} as any);
14311469

0 commit comments

Comments
 (0)