From 460f2a898c983af5b2f7b129830ee4a39c990d81 Mon Sep 17 00:00:00 2001 From: Sheetal Nandi Date: Mon, 2 May 2022 14:24:56 -0700 Subject: [PATCH] Refactor for simpler tests --- src/harness/virtualFileSystemWithWatch.ts | 52 ++----------------- .../unittests/tsbuildWatch/noEmit.ts | 3 +- .../forceConsistentCasingInFileNames.ts | 2 +- src/testRunner/unittests/tsserver/helpers.ts | 2 +- ...n-no-files-are-emitted-with-incremental.js | 26 +++++----- ...when-watching-when-no-files-are-emitted.js | 26 +++++----- 6 files changed, 32 insertions(+), 79 deletions(-) diff --git a/src/harness/virtualFileSystemWithWatch.ts b/src/harness/virtualFileSystemWithWatch.ts index 90763f7cf62..8830e1cb01a 100644 --- a/src/harness/virtualFileSystemWithWatch.ts +++ b/src/harness/virtualFileSystemWithWatch.ts @@ -14,18 +14,6 @@ interface String { charAt: any; } interface Array { length: number; [n: number]: T; }` }; - export const safeList = { - path: "/safeList.json" as Path, - content: JSON.stringify({ - commander: "commander", - express: "express", - jquery: "jquery", - lodash: "lodash", - moment: "moment", - chroma: "chroma-js" - }) - }; - function getExecutingFilePathFromLibFile(): string { return combinePaths(getDirectoryPath(libFile.path), "tsc.js"); } @@ -43,11 +31,11 @@ interface Array { length: number; [n: number]: T; }` } export function createWatchedSystem(fileOrFolderList: readonly FileOrFolderOrSymLink[], params?: TestServerHostCreationParameters): TestServerHost { - return new TestServerHost(/*withSafelist*/ false, fileOrFolderList, params); + return new TestServerHost(fileOrFolderList, params); } export function createServerHost(fileOrFolderList: readonly FileOrFolderOrSymLink[], params?: TestServerHostCreationParameters): TestServerHost { - const host = new TestServerHost(/*withSafelist*/ true, fileOrFolderList, params); + const host = new TestServerHost(fileOrFolderList, params); // Just like sys, patch the host to use writeFile patchWriteFileEnsuringDirectory(host); return host; @@ -338,7 +326,6 @@ interface Array { length: number; [n: number]: T; }` private readonly inodes?: ESMap; watchDirectory: HostWatchDirectory; constructor( - public withSafeList: boolean, fileOrFolderorSymLinkList: readonly FileOrFolderOrSymLink[], { useCaseSensitiveFileNames, executingFilePath, currentDirectory, @@ -430,7 +417,6 @@ interface Array { length: number; [n: number]: T; }` private reloadFS(fileOrFolderOrSymLinkList: readonly FileOrFolderOrSymLink[]) { Debug.assert(this.fs.size === 0); - fileOrFolderOrSymLinkList = fileOrFolderOrSymLinkList.concat(this.withSafeList ? safeList : []); const filesOrFoldersToLoad: readonly FileOrFolderOrSymLink[] = !this.windowsStyleRoot ? fileOrFolderOrSymLinkList : fileOrFolderOrSymLinkList.map(f => { const result = clone(f); @@ -438,39 +424,7 @@ interface Array { length: number; [n: number]: T; }` return result; }); for (const fileOrDirectory of filesOrFoldersToLoad) { - const path = this.toFullPath(fileOrDirectory.path); - // If its a change - const currentEntry = this.fs.get(path); - if (currentEntry) { - if (isFsFile(currentEntry)) { - if (isFile(fileOrDirectory)) { - // Update file - if (currentEntry.content !== fileOrDirectory.content) { - this.modifyFile(fileOrDirectory.path, fileOrDirectory.content); - } - } - else { - // TODO: Changing from file => folder/Symlink - } - } - else if (isFsSymLink(currentEntry)) { - // TODO: update symlinks - } - else { - // Folder - if (isFile(fileOrDirectory)) { - // TODO: Changing from folder => file - } - else { - // Folder update: Nothing to do. - currentEntry.modifiedTime = this.now(); - this.invokeFsWatches(currentEntry.fullPath, "change"); - } - } - } - else { - this.ensureFileOrFolder(fileOrDirectory); - } + this.ensureFileOrFolder(fileOrDirectory); } } diff --git a/src/testRunner/unittests/tsbuildWatch/noEmit.ts b/src/testRunner/unittests/tsbuildWatch/noEmit.ts index ddcf1dd0b28..456bfe36144 100644 --- a/src/testRunner/unittests/tsbuildWatch/noEmit.ts +++ b/src/testRunner/unittests/tsbuildWatch/noEmit.ts @@ -6,11 +6,10 @@ namespace ts.tscWatch { commandLineArgs: ["-b", "-w", "-verbose"], sys: () => createWatchedSystem( [ - libFile, + { path: libFile.path, content: libContent }, { path: `${projectRoot}/a.js`, content: "" }, { path: `${projectRoot}/b.ts`, content: "" }, { path: `${projectRoot}/tsconfig.json`, content: JSON.stringify({ compilerOptions: { allowJs: true, noEmit: true } }) }, - { path: libFile.path, content: libContent } ], { currentDirectory: projectRoot } ), diff --git a/src/testRunner/unittests/tscWatch/forceConsistentCasingInFileNames.ts b/src/testRunner/unittests/tscWatch/forceConsistentCasingInFileNames.ts index 5199b780b06..60a989f2fa3 100644 --- a/src/testRunner/unittests/tscWatch/forceConsistentCasingInFileNames.ts +++ b/src/testRunner/unittests/tscWatch/forceConsistentCasingInFileNames.ts @@ -20,7 +20,7 @@ namespace ts.tscWatch { scenario: "forceConsistentCasingInFileNames", subScenario, commandLineArgs: ["--w", "--p", tsconfig.path], - sys: () => createWatchedSystem([loggerFile, anotherFile, tsconfig, libFile, tsconfig]), + sys: () => createWatchedSystem([loggerFile, anotherFile, tsconfig, libFile]), changes }); } diff --git a/src/testRunner/unittests/tsserver/helpers.ts b/src/testRunner/unittests/tsserver/helpers.ts index 0cf7b4c41d8..de36860b09c 100644 --- a/src/testRunner/unittests/tsserver/helpers.ts +++ b/src/testRunner/unittests/tsserver/helpers.ts @@ -145,7 +145,7 @@ namespace ts.projectSystem { installTypingHost: server.ServerHost, readonly typesRegistry = new Map>(), log?: TI.Log) { - super(installTypingHost, globalTypingsCacheLocation, TestFSWithWatch.safeList.path, customTypesMap.path, throttleLimit, log); + super(installTypingHost, globalTypingsCacheLocation, "/safeList.json" as Path, customTypesMap.path, throttleLimit, log); } protected postExecActions: PostExecAction[] = []; diff --git a/tests/baselines/reference/tsbuildWatch/noEmit/does-not-go-in-loop-when-watching-when-no-files-are-emitted-with-incremental.js b/tests/baselines/reference/tsbuildWatch/noEmit/does-not-go-in-loop-when-watching-when-no-files-are-emitted-with-incremental.js index d65dcbdb946..02b66ff4809 100644 --- a/tests/baselines/reference/tsbuildWatch/noEmit/does-not-go-in-loop-when-watching-when-no-files-are-emitted-with-incremental.js +++ b/tests/baselines/reference/tsbuildWatch/noEmit/does-not-go-in-loop-when-watching-when-no-files-are-emitted-with-incremental.js @@ -27,16 +27,16 @@ declare const console: { log(msg: any): void; }; /a/lib/tsc.js -b -w -verbose --incremental Output:: >> Screen clear -[12:00:25 AM] Starting compilation in watch mode... +[12:00:23 AM] Starting compilation in watch mode... -[12:00:26 AM] Projects in this build: +[12:00:24 AM] Projects in this build: * tsconfig.json -[12:00:27 AM] Project 'tsconfig.json' is out of date because oldest output 'a.js' is older than newest input 'b.ts' +[12:00:25 AM] Project 'tsconfig.json' is out of date because oldest output 'a.js' is older than newest input 'b.ts' -[12:00:28 AM] Building project '/user/username/projects/myproject/tsconfig.json'... +[12:00:26 AM] Building project '/user/username/projects/myproject/tsconfig.json'... -[12:00:33 AM] Found 0 errors. Watching for file changes. +[12:00:31 AM] Found 0 errors. Watching for file changes. @@ -130,13 +130,13 @@ Input:: Output:: >> Screen clear -[12:00:37 AM] File change detected. Starting incremental compilation... +[12:00:35 AM] File change detected. Starting incremental compilation... -[12:00:38 AM] Project 'tsconfig.json' is out of date because output file 'b.js' does not exist +[12:00:36 AM] Project 'tsconfig.json' is out of date because output file 'b.js' does not exist -[12:00:39 AM] Building project '/user/username/projects/myproject/tsconfig.json'... +[12:00:37 AM] Building project '/user/username/projects/myproject/tsconfig.json'... -[12:00:40 AM] Found 0 errors. Watching for file changes. +[12:00:38 AM] Found 0 errors. Watching for file changes. @@ -178,13 +178,13 @@ const x = 10; Output:: >> Screen clear -[12:00:44 AM] File change detected. Starting incremental compilation... +[12:00:42 AM] File change detected. Starting incremental compilation... -[12:00:45 AM] Project 'tsconfig.json' is out of date because output file 'b.js' does not exist +[12:00:43 AM] Project 'tsconfig.json' is out of date because output file 'b.js' does not exist -[12:00:46 AM] Building project '/user/username/projects/myproject/tsconfig.json'... +[12:00:44 AM] Building project '/user/username/projects/myproject/tsconfig.json'... -[12:00:53 AM] Found 0 errors. Watching for file changes. +[12:00:51 AM] Found 0 errors. Watching for file changes. diff --git a/tests/baselines/reference/tsbuildWatch/noEmit/does-not-go-in-loop-when-watching-when-no-files-are-emitted.js b/tests/baselines/reference/tsbuildWatch/noEmit/does-not-go-in-loop-when-watching-when-no-files-are-emitted.js index fac8efbee33..d2b736cdf81 100644 --- a/tests/baselines/reference/tsbuildWatch/noEmit/does-not-go-in-loop-when-watching-when-no-files-are-emitted.js +++ b/tests/baselines/reference/tsbuildWatch/noEmit/does-not-go-in-loop-when-watching-when-no-files-are-emitted.js @@ -27,16 +27,16 @@ declare const console: { log(msg: any): void; }; /a/lib/tsc.js -b -w -verbose Output:: >> Screen clear -[12:00:25 AM] Starting compilation in watch mode... +[12:00:23 AM] Starting compilation in watch mode... -[12:00:26 AM] Projects in this build: +[12:00:24 AM] Projects in this build: * tsconfig.json -[12:00:27 AM] Project 'tsconfig.json' is out of date because oldest output 'a.js' is older than newest input 'b.ts' +[12:00:25 AM] Project 'tsconfig.json' is out of date because oldest output 'a.js' is older than newest input 'b.ts' -[12:00:28 AM] Building project '/user/username/projects/myproject/tsconfig.json'... +[12:00:26 AM] Building project '/user/username/projects/myproject/tsconfig.json'... -[12:00:29 AM] Found 0 errors. Watching for file changes. +[12:00:27 AM] Found 0 errors. Watching for file changes. @@ -82,13 +82,13 @@ Input:: Output:: >> Screen clear -[12:00:33 AM] File change detected. Starting incremental compilation... +[12:00:31 AM] File change detected. Starting incremental compilation... -[12:00:34 AM] Project 'tsconfig.json' is out of date because output file 'b.js' does not exist +[12:00:32 AM] Project 'tsconfig.json' is out of date because output file 'b.js' does not exist -[12:00:35 AM] Building project '/user/username/projects/myproject/tsconfig.json'... +[12:00:33 AM] Building project '/user/username/projects/myproject/tsconfig.json'... -[12:00:36 AM] Found 0 errors. Watching for file changes. +[12:00:34 AM] Found 0 errors. Watching for file changes. @@ -130,13 +130,13 @@ const x = 10; Output:: >> Screen clear -[12:00:40 AM] File change detected. Starting incremental compilation... +[12:00:38 AM] File change detected. Starting incremental compilation... -[12:00:41 AM] Project 'tsconfig.json' is out of date because output file 'b.js' does not exist +[12:00:39 AM] Project 'tsconfig.json' is out of date because output file 'b.js' does not exist -[12:00:42 AM] Building project '/user/username/projects/myproject/tsconfig.json'... +[12:00:40 AM] Building project '/user/username/projects/myproject/tsconfig.json'... -[12:00:43 AM] Found 0 errors. Watching for file changes. +[12:00:41 AM] Found 0 errors. Watching for file changes.