From ee05d0eb1cfadee576defbae31e8c474b9efcd9e Mon Sep 17 00:00:00 2001 From: Sheetal Nandi Date: Wed, 4 Oct 2017 16:03:16 -0700 Subject: [PATCH] Compile public api so that all the updates are ensured to be correct --- src/harness/unittests/publicApi.ts | 34 ++++++++++++++++--- src/server/project.ts | 2 +- .../reference/api/tsserverlibrary.d.ts | 2 +- 3 files changed, 31 insertions(+), 7 deletions(-) diff --git a/src/harness/unittests/publicApi.ts b/src/harness/unittests/publicApi.ts index bb37dbe9d8d..35acfec57f5 100644 --- a/src/harness/unittests/publicApi.ts +++ b/src/harness/unittests/publicApi.ts @@ -1,10 +1,34 @@ /// describe("Public APIs", () => { - it("for the language service and compiler should be acknowledged when they change", () => { - Harness.Baseline.runBaseline("api/typescript.d.ts", () => Harness.IO.readFile("built/local/typescript.d.ts")); + function verifyApi(fileName: string) { + const builtFile = `built/local/${fileName}`; + const api = `api/${fileName}`; + let fileContent: string; + before(() => { + fileContent = Harness.IO.readFile(builtFile); + }); + + it("should be acknowledged when they change", () => { + Harness.Baseline.runBaseline(api, () => fileContent); + }); + + it("should compile", () => { + const testFile: Harness.Compiler.TestFile = { + unitName: builtFile, + content: fileContent + }; + const inputFiles = [testFile]; + const output = Harness.Compiler.compileFiles(inputFiles, [], /*harnessSettings*/ undefined, /*options*/ {}, /*currentDirectory*/ undefined); + assert(!output.result.errors || !output.result.errors.length, Harness.Compiler.minimalDiagnosticsToString(output.result.errors, /*pretty*/ true)); + }); + } + + describe("for the language service and compiler", () => { + verifyApi("typescript.d.ts"); }); - it("for the language server should be acknowledged when they change", () => { - Harness.Baseline.runBaseline("api/tsserverlibrary.d.ts", () => Harness.IO.readFile("built/local/tsserverlibrary.d.ts")); + + describe("for the language server", () => { + verifyApi("tsserverlibrary.d.ts"); }); -}); \ No newline at end of file +}); diff --git a/src/server/project.ts b/src/server/project.ts index 655f3ed0cfc..ac18738027b 100644 --- a/src/server/project.ts +++ b/src/server/project.ts @@ -296,7 +296,7 @@ namespace ts.server { } } - getCancellationToken() { + getCancellationToken(): HostCancellationToken { return this.cancellationToken; } diff --git a/tests/baselines/reference/api/tsserverlibrary.d.ts b/tests/baselines/reference/api/tsserverlibrary.d.ts index 1feb6b7d073..3bb2ed11674 100644 --- a/tests/baselines/reference/api/tsserverlibrary.d.ts +++ b/tests/baselines/reference/api/tsserverlibrary.d.ts @@ -7104,7 +7104,7 @@ declare namespace ts.server { getScriptKind(fileName: string): ScriptKind; getScriptVersion(filename: string): string; getScriptSnapshot(filename: string): IScriptSnapshot; - getCancellationToken(): ThrottledCancellationToken; + getCancellationToken(): HostCancellationToken; getCurrentDirectory(): string; getDefaultLibFileName(): string; useCaseSensitiveFileNames(): boolean;