Skip to content

Commit 917ab0a

Browse files
committed
Update test harness
1 parent f4e10eb commit 917ab0a

5 files changed

Lines changed: 42 additions & 12 deletions

File tree

src/harness/harness.ts

Lines changed: 26 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ namespace Utils {
127127
export function memoize<T extends Function>(f: T): T {
128128
const cache: { [idx: string]: any } = {};
129129

130-
return <any>(function () {
130+
return <any>(function() {
131131
const key = Array.prototype.join.call(arguments);
132132
const cachedResult = cache[key];
133133
if (cachedResult) {
@@ -609,7 +609,7 @@ namespace Harness {
609609
export const getCurrentDirectory = () => "";
610610
export const args = () => <string[]>[];
611611
export const getExecutingFilePath = () => "";
612-
export const exit = (exitCode: number) => {};
612+
export const exit = (exitCode: number) => { };
613613

614614
export let log = (s: string) => console.log(s);
615615

@@ -826,7 +826,7 @@ namespace Harness {
826826
}
827827

828828
if (!libFileNameSourceFileMap[fileName]) {
829-
libFileNameSourceFileMap[fileName] = createSourceFileAndAssertInvariants(fileName, IO.readFile(libFolder + fileName), ts.ScriptTarget.Latest);
829+
libFileNameSourceFileMap[fileName] = createSourceFileAndAssertInvariants(fileName, IO.readFile(libFolder + fileName), ts.ScriptTarget.Latest);
830830
}
831831
return libFileNameSourceFileMap[fileName];
832832
}
@@ -900,6 +900,20 @@ namespace Harness {
900900

901901

902902
return {
903+
getDefaultTypeDirectiveNames: (path: string) => {
904+
const results: string[] = [];
905+
fileMap.forEachValue((key, value) => {
906+
const rx = /node_modules\/@types\/(\w+)/;
907+
const typeNameResult = rx.exec(key);
908+
if(typeNameResult) {
909+
const typeName = typeNameResult[1];
910+
if (results.indexOf(typeName) < 0) {
911+
results.push(typeName);
912+
}
913+
}
914+
});
915+
return results;
916+
},
903917
getCurrentDirectory: () => currentDirectory,
904918
getSourceFile,
905919
getDefaultLibFileName,
@@ -1441,12 +1455,12 @@ namespace Harness {
14411455
if (currentFileName) {
14421456
// Store result file
14431457
const newTestFile = {
1444-
content: currentFileContent,
1445-
name: currentFileName,
1446-
fileOptions: currentFileOptions,
1447-
originalFilePath: fileName,
1448-
references: refs
1449-
};
1458+
content: currentFileContent,
1459+
name: currentFileName,
1460+
fileOptions: currentFileOptions,
1461+
originalFilePath: fileName,
1462+
references: refs
1463+
};
14501464
testUnitData.push(newTestFile);
14511465

14521466
// Reset local data
@@ -1544,10 +1558,10 @@ namespace Harness {
15441558

15451559
function baselinePath(fileName: string, type: string, baselineFolder: string, subfolder?: string) {
15461560
if (subfolder !== undefined) {
1547-
return Harness.userSpecifiedRoot + baselineFolder + "/" + subfolder + "/" + type + "/" + fileName;
1561+
return Harness.userSpecifiedRoot + baselineFolder + "/" + subfolder + "/" + type + "/" + fileName;
15481562
}
15491563
else {
1550-
return Harness.userSpecifiedRoot + baselineFolder + "/" + type + "/" + fileName;
1564+
return Harness.userSpecifiedRoot + baselineFolder + "/" + type + "/" + fileName;
15511565
}
15521566
}
15531567

@@ -1616,7 +1630,7 @@ namespace Harness {
16161630
}
16171631

16181632
function writeComparison(expected: string, actual: string, relativeFileName: string, actualFileName: string, descriptionForDescribe: string) {
1619-
const encoded_actual = Utils.encodeString(actual);
1633+
const encoded_actual = Utils.encodeString(actual);
16201634
if (expected != encoded_actual) {
16211635
// Overwrite & issue error
16221636
const errMsg = "The baseline file " + relativeFileName + " has changed.";

src/harness/harnessLanguageService.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -600,6 +600,10 @@ namespace Harness.LanguageService {
600600
return this.host.getCurrentDirectory();
601601
}
602602

603+
getDirectories(path: string): string[] {
604+
return [];
605+
}
606+
603607
readDirectory(path: string, extension?: string): string[] {
604608
throw new Error("Not implemented Yet.");
605609
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
// @noImplicitReferences: true
2+
3+
// @filename: tsconfig.json
4+
{ "files": "a.ts" }
5+
6+
// @filename: node_modules/@types/jquery/index.d.ts
7+
declare var $: { x: any };
8+
9+
// @filename: a.ts
10+
$.x;

tests/cases/unittests/cachingInServerLSHost.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ module ts {
4646
getCurrentDirectory: (): string => {
4747
return "";
4848
},
49+
getDirectories: (path: string) => [],
4950
readDirectory: (path: string, extension?: string, exclude?: string[]): string[] => {
5051
throw new Error("NYI");
5152
},

tests/cases/unittests/session.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ namespace ts.server {
1414
resolvePath(): string { return void 0; },
1515
fileExists: () => false,
1616
directoryExists: () => false,
17+
getDirectories: () => [],
1718
createDirectory(): void {},
1819
getExecutingFilePath(): string { return void 0; },
1920
getCurrentDirectory(): string { return void 0; },

0 commit comments

Comments
 (0)