From 917ab0aa0afa7501ff0dc75f3ee191718e03eaac Mon Sep 17 00:00:00 2001 From: Ryan Cavanaugh Date: Wed, 18 May 2016 10:43:44 -0700 Subject: [PATCH] Update test harness --- src/harness/harness.ts | 38 +++++++++++++------ src/harness/harnessLanguageService.ts | 4 ++ .../conformance/typings/typingsLookup1.ts | 10 +++++ .../cases/unittests/cachingInServerLSHost.ts | 1 + tests/cases/unittests/session.ts | 1 + 5 files changed, 42 insertions(+), 12 deletions(-) create mode 100644 tests/cases/conformance/typings/typingsLookup1.ts diff --git a/src/harness/harness.ts b/src/harness/harness.ts index ef9b36b50e2..ca8102b2ff4 100644 --- a/src/harness/harness.ts +++ b/src/harness/harness.ts @@ -127,7 +127,7 @@ namespace Utils { export function memoize(f: T): T { const cache: { [idx: string]: any } = {}; - return (function () { + return (function() { const key = Array.prototype.join.call(arguments); const cachedResult = cache[key]; if (cachedResult) { @@ -609,7 +609,7 @@ namespace Harness { export const getCurrentDirectory = () => ""; export const args = () => []; export const getExecutingFilePath = () => ""; - export const exit = (exitCode: number) => {}; + export const exit = (exitCode: number) => { }; export let log = (s: string) => console.log(s); @@ -826,7 +826,7 @@ namespace Harness { } if (!libFileNameSourceFileMap[fileName]) { - libFileNameSourceFileMap[fileName] = createSourceFileAndAssertInvariants(fileName, IO.readFile(libFolder + fileName), ts.ScriptTarget.Latest); + libFileNameSourceFileMap[fileName] = createSourceFileAndAssertInvariants(fileName, IO.readFile(libFolder + fileName), ts.ScriptTarget.Latest); } return libFileNameSourceFileMap[fileName]; } @@ -900,6 +900,20 @@ namespace Harness { return { + getDefaultTypeDirectiveNames: (path: string) => { + const results: string[] = []; + fileMap.forEachValue((key, value) => { + const rx = /node_modules\/@types\/(\w+)/; + const typeNameResult = rx.exec(key); + if(typeNameResult) { + const typeName = typeNameResult[1]; + if (results.indexOf(typeName) < 0) { + results.push(typeName); + } + } + }); + return results; + }, getCurrentDirectory: () => currentDirectory, getSourceFile, getDefaultLibFileName, @@ -1441,12 +1455,12 @@ namespace Harness { if (currentFileName) { // Store result file const newTestFile = { - content: currentFileContent, - name: currentFileName, - fileOptions: currentFileOptions, - originalFilePath: fileName, - references: refs - }; + content: currentFileContent, + name: currentFileName, + fileOptions: currentFileOptions, + originalFilePath: fileName, + references: refs + }; testUnitData.push(newTestFile); // Reset local data @@ -1544,10 +1558,10 @@ namespace Harness { function baselinePath(fileName: string, type: string, baselineFolder: string, subfolder?: string) { if (subfolder !== undefined) { - return Harness.userSpecifiedRoot + baselineFolder + "/" + subfolder + "/" + type + "/" + fileName; + return Harness.userSpecifiedRoot + baselineFolder + "/" + subfolder + "/" + type + "/" + fileName; } else { - return Harness.userSpecifiedRoot + baselineFolder + "/" + type + "/" + fileName; + return Harness.userSpecifiedRoot + baselineFolder + "/" + type + "/" + fileName; } } @@ -1616,7 +1630,7 @@ namespace Harness { } function writeComparison(expected: string, actual: string, relativeFileName: string, actualFileName: string, descriptionForDescribe: string) { - const encoded_actual = Utils.encodeString(actual); + const encoded_actual = Utils.encodeString(actual); if (expected != encoded_actual) { // Overwrite & issue error const errMsg = "The baseline file " + relativeFileName + " has changed."; diff --git a/src/harness/harnessLanguageService.ts b/src/harness/harnessLanguageService.ts index 8aaff65febc..3df0e8e7d8f 100644 --- a/src/harness/harnessLanguageService.ts +++ b/src/harness/harnessLanguageService.ts @@ -600,6 +600,10 @@ namespace Harness.LanguageService { return this.host.getCurrentDirectory(); } + getDirectories(path: string): string[] { + return []; + } + readDirectory(path: string, extension?: string): string[] { throw new Error("Not implemented Yet."); } diff --git a/tests/cases/conformance/typings/typingsLookup1.ts b/tests/cases/conformance/typings/typingsLookup1.ts new file mode 100644 index 00000000000..702bd4bc21c --- /dev/null +++ b/tests/cases/conformance/typings/typingsLookup1.ts @@ -0,0 +1,10 @@ +// @noImplicitReferences: true + +// @filename: tsconfig.json +{ "files": "a.ts" } + +// @filename: node_modules/@types/jquery/index.d.ts +declare var $: { x: any }; + +// @filename: a.ts +$.x; diff --git a/tests/cases/unittests/cachingInServerLSHost.ts b/tests/cases/unittests/cachingInServerLSHost.ts index 58bcd76e246..899b59c1600 100644 --- a/tests/cases/unittests/cachingInServerLSHost.ts +++ b/tests/cases/unittests/cachingInServerLSHost.ts @@ -46,6 +46,7 @@ module ts { getCurrentDirectory: (): string => { return ""; }, + getDirectories: (path: string) => [], readDirectory: (path: string, extension?: string, exclude?: string[]): string[] => { throw new Error("NYI"); }, diff --git a/tests/cases/unittests/session.ts b/tests/cases/unittests/session.ts index ee9742482cd..40be5fee411 100644 --- a/tests/cases/unittests/session.ts +++ b/tests/cases/unittests/session.ts @@ -14,6 +14,7 @@ namespace ts.server { resolvePath(): string { return void 0; }, fileExists: () => false, directoryExists: () => false, + getDirectories: () => [], createDirectory(): void {}, getExecutingFilePath(): string { return void 0; }, getCurrentDirectory(): string { return void 0; },