From 5284804610fe424a6ffb261e71f66d27504b468b Mon Sep 17 00:00:00 2001 From: Nathan Shively-Sanders <293473+sandersn@users.noreply.github.com> Date: Fri, 13 May 2022 10:38:10 -0700 Subject: [PATCH] Move new test to its own file --- src/testRunner/tsconfig.json | 1 + .../tsserver/applyChangesToOpenFiles.ts | 104 ----------------- .../unittests/tsserver/updateFileSystem.ts | 105 ++++++++++++++++++ 3 files changed, 106 insertions(+), 104 deletions(-) create mode 100644 src/testRunner/unittests/tsserver/updateFileSystem.ts diff --git a/src/testRunner/tsconfig.json b/src/testRunner/tsconfig.json index 3e25598e77c..f763f432cac 100644 --- a/src/testRunner/tsconfig.json +++ b/src/testRunner/tsconfig.json @@ -234,6 +234,7 @@ "unittests/tsserver/typeOnlyImportChains.ts", "unittests/tsserver/typeReferenceDirectives.ts", "unittests/tsserver/typingsInstaller.ts", + "unittests/tsserver/updateFileSystem.ts", "unittests/tsserver/versionCache.ts", "unittests/tsserver/watchEnvironment.ts", "unittests/tsserver/webServer.ts", diff --git a/src/testRunner/unittests/tsserver/applyChangesToOpenFiles.ts b/src/testRunner/unittests/tsserver/applyChangesToOpenFiles.ts index 863a2333329..6d5ee91d68d 100644 --- a/src/testRunner/unittests/tsserver/applyChangesToOpenFiles.ts +++ b/src/testRunner/unittests/tsserver/applyChangesToOpenFiles.ts @@ -1,108 +1,4 @@ namespace ts.projectSystem { - // TODO: Make a separate file at some point - describe("unittests:: tsserver:: updateFileSystem", () => { - const config: protocol.FileSystemRequestArgs = { - file: "/a/b/tsconfig.json", - fileContent: "{}" - }; - const file3: protocol.FileSystemRequestArgs = { - file: "/a/b/file3.ts", - fileContent: "export let xyz = 1;" - }; - const app: protocol.FileSystemRequestArgs = { - file: "/a/b/app.ts", - fileContent: "import { xyz } from './file3'; let x = xyz" - }; - const file1: protocol.FileSystemRequestArgs = { - file: "/a/b/commonFile1.ts", - fileContent: "let x = 1" - }; - const file2: protocol.FileSystemRequestArgs = { - file: "/a/b/commonFile2.ts", - fileContent: "let y = 1" - }; - const lib: protocol.FileSystemRequestArgs = { - file: "/a/lib/lib.d.ts", - fileContent: `/// -interface Boolean {} -interface Function {} -interface CallableFunction {} -interface NewableFunction {} -interface IArguments {} -interface Number { toExponential: any; } -interface Object {} -interface RegExp {} -interface String { charAt: any; } -interface Array { length: number; [n: number]: T; }` - }; - - function fileContentWithComment(file: protocol.FileSystemRequestArgs) { - return `// some copy right notice -${file.fileContent}`; - } - function baselineFileSystem(scenario: string, subScenario: string, requests: [string, Partial][], host: VirtualFS.VirtualServerHost, session: TestSession) { - const history: string[] = [] - let prev = host.snap() - for (const [name, request] of requests) { - session.executeCommandSeq(request) - history.push("") - history.push("#### " + name) - host.diff(history, prev) - prev = host.snap() - } - Harness.Baseline.runBaseline(`tsserver/${scenario}/${subScenario.split(" ").join("-")}.txt`, history.join("\r\n")); - baselineTsserverLogs(scenario, subScenario, session) - } - - it("with updateFileSystem request", () => { - const host = VirtualFS.createVirtualServerHost({ executingFilePath: "/a/tsc.js" }); - const session = createSession(host, { fshost: host, logger: createLoggerWithInMemoryLogs(), canUseEvents: true }); - const requests: [string, Partial][] = [ - ["Initial updateFileSystem", { - command: protocol.CommandTypes.UpdateFileSystem, - arguments:{ - fileSystem: "memfs", - files: [app, file1, file2, file3, config, lib], - deleted: [], - } - }], - ["Opening app.ts", { - command: protocol.CommandTypes.Open, - arguments: { file: app.file } - }], - ["Opening file3.ts", { - command: protocol.CommandTypes.Open, - arguments: { - file: file3.file, - fileContent: fileContentWithComment(file3) - } - }], - ["non-delete", { - command: protocol.CommandTypes.UpdateFileSystem, - arguments:{ - fileSystem: "memfs", - files: [], - deleted: [], - } - }], - ["delete", { - command: protocol.CommandTypes.UpdateFileSystem, - arguments:{ - fileSystem: "memfs", - files: [], - deleted: [file1.file], - } - }], - ["close", { - command: protocol.CommandTypes.Close, - arguments: { file: app.file } - }], - ] - const scenario = "updateFileSystem" - const subScenario = "open and close files" - baselineFileSystem(scenario, subScenario, requests, host, session); - }); - }); describe("unittests:: tsserver:: applyChangesToOpenFiles", () => { const configFile: File = { path: "/a/b/tsconfig.json", diff --git a/src/testRunner/unittests/tsserver/updateFileSystem.ts b/src/testRunner/unittests/tsserver/updateFileSystem.ts new file mode 100644 index 00000000000..4d5cba2ad2e --- /dev/null +++ b/src/testRunner/unittests/tsserver/updateFileSystem.ts @@ -0,0 +1,105 @@ +namespace ts.projectSystem { + describe("unittests:: tsserver:: updateFileSystem", () => { + const config: protocol.FileSystemRequestArgs = { + file: "/a/b/tsconfig.json", + fileContent: "{}" + }; + const file3: protocol.FileSystemRequestArgs = { + file: "/a/b/file3.ts", + fileContent: "export let xyz = 1;" + }; + const app: protocol.FileSystemRequestArgs = { + file: "/a/b/app.ts", + fileContent: "import { xyz } from './file3'; let x = xyz" + }; + const file1: protocol.FileSystemRequestArgs = { + file: "/a/b/commonFile1.ts", + fileContent: "let x = 1" + }; + const file2: protocol.FileSystemRequestArgs = { + file: "/a/b/commonFile2.ts", + fileContent: "let y = 1" + }; + const lib: protocol.FileSystemRequestArgs = { + file: "/a/lib/lib.d.ts", + fileContent: `/// +interface Boolean {} +interface Function {} +interface CallableFunction {} +interface NewableFunction {} +interface IArguments {} +interface Number { toExponential: any; } +interface Object {} +interface RegExp {} +interface String { charAt: any; } +interface Array { length: number; [n: number]: T; }` + }; + + function fileContentWithComment(file: protocol.FileSystemRequestArgs) { + return `// some copy right notice +${file.fileContent}`; + } + function baselineFileSystem(scenario: string, subScenario: string, requests: [string, Partial][], host: VirtualFS.VirtualServerHost, session: TestSession) { + const history: string[] = [] + let prev = host.snap() + for (const [name, request] of requests) { + session.executeCommandSeq(request) + history.push("") + history.push("#### " + name) + host.diff(history, prev) + prev = host.snap() + } + Harness.Baseline.runBaseline(`tsserver/${scenario}/${subScenario.split(" ").join("-")}.txt`, history.join("\r\n")); + baselineTsserverLogs(scenario, subScenario, session) + } + + it("with updateFileSystem request", () => { + const host = VirtualFS.createVirtualServerHost({ executingFilePath: "/a/tsc.js" }); + const session = createSession(host, { fshost: host, logger: createLoggerWithInMemoryLogs(), canUseEvents: true }); + const requests: [string, Partial][] = [ + ["Initial updateFileSystem", { + command: protocol.CommandTypes.UpdateFileSystem, + arguments:{ + fileSystem: "memfs", + files: [app, file1, file2, file3, config, lib], + deleted: [], + } + }], + ["Opening app.ts", { + command: protocol.CommandTypes.Open, + arguments: { file: app.file } + }], + ["Opening file3.ts", { + command: protocol.CommandTypes.Open, + arguments: { + file: file3.file, + fileContent: fileContentWithComment(file3) + } + }], + ["non-delete", { + command: protocol.CommandTypes.UpdateFileSystem, + arguments:{ + fileSystem: "memfs", + files: [], + deleted: [], + } + }], + ["delete", { + command: protocol.CommandTypes.UpdateFileSystem, + arguments:{ + fileSystem: "memfs", + files: [], + deleted: [file1.file], + } + }], + ["close", { + command: protocol.CommandTypes.Close, + arguments: { file: app.file } + }], + ] + const scenario = "updateFileSystem" + const subScenario = "open and close files" + baselineFileSystem(scenario, subScenario, requests, host, session); + }); + }); +}