Refactor for simpler tests

This commit is contained in:
Sheetal Nandi committed 2022-05-06 10:59:38 -07:00
1 parent 03fa5b3a98
commit 460f2a898c
6 files changed
+32 -79

No files matched your search

+3 -49
View File
@@ -14,18 +14,6 @@ interface String { charAt: any; }
interface Array<T> { 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<T> { 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<T> { length: number; [n: number]: T; }`
private readonly inodes?: ESMap<Path, number>;
watchDirectory: HostWatchDirectory;
constructor(
public withSafeList: boolean,
fileOrFolderorSymLinkList: readonly FileOrFolderOrSymLink[],
{
useCaseSensitiveFileNames, executingFilePath, currentDirectory,
@@ -430,7 +417,6 @@ interface Array<T> { 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<FileOrFolderOrSymLink>(f => {
const result = clone(f);
@@ -438,39 +424,7 @@ interface Array<T> { 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);
}
}
@@ -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 }
),
@@ -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
});
}
+1 -1
View File
@@ -145,7 +145,7 @@ namespace ts.projectSystem {
installTypingHost: server.ServerHost,
readonly typesRegistry = new Map<string, MapLike<string>>(),
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[] = [];
@@ -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.
@@ -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.