Remove VirtualServerBastHost

Instead, pass in additional configuration from TestServerHost
This commit is contained in:
Nathan Shively-Sanders
2022-06-08 14:00:18 -07:00
parent 2ba27a58fb
commit 8be58eb472
3 changed files with 42 additions and 66 deletions
+6 -35
View File
@@ -281,7 +281,7 @@ interface Array<T> { length: number; [n: number]: T; }`
export const timeIncrements = 1000;
export class TestServerHost extends VirtualServerBaseHost implements server.ServerHost {
export class TestServerHost extends VirtualServerHost implements server.ServerHost {
private readonly output: string[] = [];
private time = timeIncrements;
private timeoutCallbacks = new Callbacks(this);
@@ -289,7 +289,6 @@ interface Array<T> { length: number; [n: number]: T; }`
readonly screenClears: number[] = [];
private readonly environmentVariables?: ESMap<string, string>;
public require: ((initialPath: string, moduleName: string) => RequireResult) | undefined;
private readonly runWithoutRecursiveWatches?: boolean;
runWithFallbackPolling: boolean;
public defaultWatchFileKind?: () => WatchFileKind | undefined;
@@ -299,42 +298,14 @@ interface Array<T> { length: number; [n: number]: T; }`
options: TestServerHostCreationParameters = {}) {
super({
...options,
executingFilePath: options.executingFilePath || getExecutingFilePathFromLibFile()
});
const { environmentVariables, runWithoutRecursiveWatches, runWithFallbackPolling } = options;
executingFilePath: options.executingFilePath || getExecutingFilePathFromLibFile(),
},
options,
() => this.defaultWatchFileKind?.());
const { environmentVariables, runWithFallbackPolling } = options;
fileOrFolderOrSymLinkList = fileOrFolderOrSymLinkList.concat(withSafeList ? safeList : []);
const tscWatchFile = environmentVariables && environmentVariables.get("TSC_WATCHFILE");
const tscWatchDirectory = environmentVariables && environmentVariables.get("TSC_WATCHDIRECTORY");
this.runWithoutRecursiveWatches = runWithoutRecursiveWatches;
this.runWithFallbackPolling = !!runWithFallbackPolling;
this.environmentVariables = environmentVariables;
const { watchFile, watchDirectory } = createSystemWatchFunctions({
// We dont have polling watch file
// it is essentially fsWatch but lets get that separate from fsWatch and
// into watchedFiles for easier testing
pollingWatchFile: tscWatchFile === Tsc_WatchFile.SingleFileWatcherPerName ?
createSingleFileWatcherPerName(
this.watchFileWorker.bind(this),
this.useCaseSensitiveFileNames
) :
this.watchFileWorker.bind(this),
getModifiedTime: this.getModifiedTime.bind(this),
setTimeout: this.setTimeout.bind(this),
clearTimeout: this.clearTimeout.bind(this),
fsWatch: this.fsWatch.bind(this),
fileExists: this.fileExists.bind(this),
useCaseSensitiveFileNames: this.useCaseSensitiveFileNames,
getCurrentDirectory: this.getCurrentDirectory.bind(this),
fsSupportsRecursiveFsWatch: tscWatchDirectory ? false : !this.runWithoutRecursiveWatches,
directoryExists: this.directoryExists.bind(this),
getAccessibleSortedChildDirectories: path => this.getDirectories(path),
realpath: this.realpath.bind(this),
tscWatchFile: tscWatchFile,
tscWatchDirectory: tscWatchDirectory,
defaultWatchFileKind: () => this.defaultWatchFileKind?.(),
});
this.watchFile = watchFile;
this.watchDirectory = watchDirectory;
this.reloadFS(fileOrFolderOrSymLinkList);
}
+34 -30
View File
@@ -122,7 +122,7 @@ namespace ts.VirtualFS {
*
* also implements {server.ServerHost} but that would create a circular dependency
*/
export abstract class VirtualServerBaseHost implements FormatDiagnosticsHost, ModuleResolutionHost {
export class VirtualServerHost implements FormatDiagnosticsHost, ModuleResolutionHost {
args: string[] = [];
protected fs: ESMap<Path, FSEntry> = new Map();
@@ -144,7 +144,9 @@ namespace ts.VirtualFS {
constructor({
useCaseSensitiveFileNames, executingFilePath, currentDirectory,
newLine, windowsStyleRoot
}: VirtualServerHostCreationParameters) {
}: VirtualServerHostCreationParameters,
testOptions?: { environmentVariables?: ESMap<string, string>; runWithoutRecursiveWatches?: boolean; },
defaultWatchFileKind?: (() => WatchFileKind | undefined)) {
this.useCaseSensitiveFileNames = !!useCaseSensitiveFileNames;
this.newLine = newLine || "\n";
this.windowsStyleRoot = windowsStyleRoot;
@@ -153,6 +155,36 @@ namespace ts.VirtualFS {
this.toPath = s => toPath(s, currentDirectory, this.getCanonicalFileName);
this.executingFilePath = this.getHostSpecificPath(executingFilePath);
this.currentDirectory = this.getHostSpecificPath(currentDirectory);
const { environmentVariables, runWithoutRecursiveWatches } = testOptions || {};
const tscWatchFile = environmentVariables && environmentVariables.get("TSC_WATCHFILE");
const tscWatchDirectory = environmentVariables && environmentVariables.get("TSC_WATCHDIRECTORY");
const { watchFile, watchDirectory } = createSystemWatchFunctions({
// We dont have polling watch file
// it is essentially fsWatch but lets get that separate from fsWatch and
// into watchedFiles for easier testing
pollingWatchFile: tscWatchFile === Tsc_WatchFile.SingleFileWatcherPerName ?
createSingleFileWatcherPerName(
this.watchFileWorker.bind(this),
this.useCaseSensitiveFileNames
) :
this.watchFileWorker.bind(this),
getModifiedTime: this.getModifiedTime.bind(this),
setTimeout: this.setTimeout.bind(this),
clearTimeout: this.clearTimeout.bind(this),
fsWatch: this.fsWatch.bind(this),
fileExists: this.fileExists.bind(this),
useCaseSensitiveFileNames: this.useCaseSensitiveFileNames,
getCurrentDirectory: this.getCurrentDirectory.bind(this),
fsSupportsRecursiveFsWatch: tscWatchDirectory ? false : !runWithoutRecursiveWatches,
directoryExists: this.directoryExists.bind(this),
getAccessibleSortedChildDirectories: path => this.getDirectories(path),
realpath: this.realpath.bind(this),
defaultWatchFileKind: defaultWatchFileKind ?? (() => undefined),
tscWatchFile,
tscWatchDirectory,
});
this.watchFile = watchFile;
this.watchDirectory = watchDirectory;
}
getNewLine() {
@@ -621,34 +653,6 @@ namespace ts.VirtualFS {
}
}
export class VirtualServerHost extends VirtualServerBaseHost {
constructor(options: VirtualServerHostCreationParameters) {
super(options);
const { watchFile, watchDirectory } = createSystemWatchFunctions({
// We dont have polling watch file
// it is essentially fsWatch but lets get that separate from fsWatch and
// into watchedFiles for easier testing
pollingWatchFile: this.watchFileWorker.bind(this),
getModifiedTime: this.getModifiedTime.bind(this),
setTimeout: this.setTimeout.bind(this),
clearTimeout: this.clearTimeout.bind(this),
fsWatch: this.fsWatch.bind(this),
fileExists: this.fileExists.bind(this),
useCaseSensitiveFileNames: this.useCaseSensitiveFileNames,
getCurrentDirectory: this.getCurrentDirectory.bind(this),
fsSupportsRecursiveFsWatch: true,
directoryExists: this.directoryExists.bind(this),
getAccessibleSortedChildDirectories: path => this.getDirectories(path),
realpath: this.realpath.bind(this),
tscWatchFile: undefined,
tscWatchDirectory: undefined,
defaultWatchFileKind: () => undefined,
});
this.watchFile = watchFile;
this.watchDirectory = watchDirectory;
}
}
function diffFsFile(baseline: string[], fsEntry: FsFile) {
baseline.push(`//// [${fsEntry.fullPath}]\r\n${fsEntry.content}`, "");
}
+2 -1
View File
@@ -6985,7 +6985,8 @@ declare namespace ts.server {
trace?(s: string): void;
require?(initialPath: string, moduleName: string): RequireResult;
}
type FileServerHost = Pick<ServerHost, "readFile" | "writeFile" | "fileExists" | "directoryExists" | "getFileSize" | "getModifiedTime" | "getDirectories" | "getCurrentDirectory" | "getExecutingFilePath" | "realpath" | "resolvePath" | "createDirectory" | "setModifiedTime" | "deleteFile" | "readDirectory" | "watchFile" | "watchDirectory" | "useCaseSensitiveFileNames"> & {
type FileServerHost = Pick<ServerHost, "readFile" | "writeFile" | "fileExists" | "directoryExists" | "getFileSize" | "getModifiedTime" | "getDirectories" | "getCurrentDirectory" | "getExecutingFilePath" | "realpath" | "resolvePath" | "createDirectory" | "setModifiedTime" | "readDirectory" | "watchFile" | "watchDirectory" | "useCaseSensitiveFileNames"> & {
deleteFile(path: string, deleteEmptyParentFolders?: boolean): void;
ensureFileOrFolder(fileOrDirectoryOrSymLink: {
path: string;
} & ({