Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Now that we have osFlavour some of the TestServerHostOptions can be removed #57998

Merged
merged 4 commits into from
Mar 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 15 additions & 19 deletions src/testRunner/unittests/helpers/virtualFileSystemWithWatch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,10 +83,7 @@ export interface TestServerHostCreationParameters {
newLine?: string;
windowsStyleRoot?: string;
environmentVariables?: Map<string, string>;
runWithoutRecursiveWatches?: boolean;
runWithFallbackPolling?: boolean;
inodeWatching?: boolean;
fsWatchWithTimestamp?: boolean;
osFlavor?: TestServerHostOsFlavor;
}

Expand Down Expand Up @@ -362,7 +359,7 @@ export class TestServerHost implements server.ServerHost, FormatDiagnosticsHost,
importPlugin?: (root: string, moduleName: string) => Promise<ModuleImportResult>;
public storeSignatureInfo = true;
watchFile: HostWatchFile;
private inodeWatching: boolean | undefined;
private inodeWatching: boolean;
private readonly inodes?: Map<Path, number>;
watchDirectory: HostWatchDirectory;
service?: server.ProjectService;
Expand All @@ -376,17 +373,13 @@ export class TestServerHost implements server.ServerHost, FormatDiagnosticsHost,
newLine,
windowsStyleRoot,
environmentVariables,
runWithoutRecursiveWatches,
runWithFallbackPolling,
inodeWatching,
fsWatchWithTimestamp,
osFlavor,
}: TestServerHostCreationParameters = {},
) {
this.useCaseSensitiveFileNames = !!useCaseSensitiveFileNames;
this.newLine = newLine || "\n";
this.osFlavor = osFlavor || TestServerHostOsFlavor.Windows;
if (this.osFlavor === TestServerHostOsFlavor.Linux) runWithoutRecursiveWatches = true;
this.windowsStyleRoot = windowsStyleRoot;
this.environmentVariables = environmentVariables;
currentDirectory = currentDirectory || "/";
Expand All @@ -398,10 +391,8 @@ export class TestServerHost implements server.ServerHost, FormatDiagnosticsHost,
this.runWithFallbackPolling = !!runWithFallbackPolling;
const tscWatchFile = this.environmentVariables && this.environmentVariables.get("TSC_WATCHFILE");
const tscWatchDirectory = this.environmentVariables && this.environmentVariables.get("TSC_WATCHDIRECTORY");
if (inodeWatching) {
this.inodeWatching = true;
this.inodes = new Map();
}
this.inodeWatching = this.osFlavor !== TestServerHostOsFlavor.Windows;
if (this.inodeWatching) this.inodes = new Map();

const { watchFile, watchDirectory } = createSystemWatchFunctions({
// We dont have polling watch file
Expand All @@ -415,13 +406,13 @@ export class TestServerHost implements server.ServerHost, FormatDiagnosticsHost,
fileSystemEntryExists: this.fileSystemEntryExists.bind(this),
useCaseSensitiveFileNames: this.useCaseSensitiveFileNames,
getCurrentDirectory: this.getCurrentDirectory.bind(this),
fsSupportsRecursiveFsWatch: tscWatchDirectory ? false : !runWithoutRecursiveWatches,
fsSupportsRecursiveFsWatch: this.osFlavor !== TestServerHostOsFlavor.Linux,
getAccessibleSortedChildDirectories: path => this.getDirectories(path),
realpath: this.realpath.bind(this),
tscWatchFile,
tscWatchDirectory,
inodeWatching: !!this.inodeWatching,
fsWatchWithTimestamp,
inodeWatching: this.inodeWatching,
fsWatchWithTimestamp: this.osFlavor === TestServerHostOsFlavor.MacOs,
sysLog: s => this.write(s + this.newLine),
});
this.watchFile = watchFile;
Expand Down Expand Up @@ -712,15 +703,20 @@ export class TestServerHost implements server.ServerHost, FormatDiagnosticsHost,
cb: FsWatchCallback,
) {
if (this.runWithFallbackPolling) throw new Error("Need to use fallback polling instead of file system native watching");
const path = this.toPath(fileOrDirectory);
// Error if the path does not exist
if (this.inodeWatching && !this.inodes?.has(path)) throw new Error();
let inode: number | undefined;
if (this.inodeWatching) {
const entry = this.getRealFileOrFolder(fileOrDirectory);
// Error if the path does not exist
if (!entry) throw new Error("Cannot watch missing file or folder");
inode = this.inodes?.get(entry.path);
if (inode === undefined) throw new Error("inode not found");
}
const result = this.watchUtils.fsWatch(
this.toNormalizedAbsolutePath(fileOrDirectory),
recursive,
{
cb,
inode: this.inodes?.get(path),
inode,
},
) as FsWatchWorkerWatcher;
result.on = noop;
Expand Down
41 changes: 21 additions & 20 deletions src/testRunner/unittests/tscWatch/watchEnvironment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import {
libFile,
SymLink,
TestServerHost,
TestServerHostOsFlavor,
Tsc_WatchDirectory,
Tsc_WatchFile,
} from "../helpers/virtualFileSystemWithWatch";
Expand Down Expand Up @@ -162,7 +163,7 @@ describe("unittests:: tsc-watch:: watchEnvironment:: tsc-watch with different po
const files = [file, configFile, libFile];
const environmentVariables = new Map<string, string>();
environmentVariables.set("TSC_WATCHDIRECTORY", tscWatchDirectory);
return createWatchedSystem(files, { environmentVariables });
return createWatchedSystem(files, { osFlavor: TestServerHostOsFlavor.Linux, environmentVariables });
},
edits: [
{
Expand Down Expand Up @@ -230,7 +231,7 @@ describe("unittests:: tsc-watch:: watchEnvironment:: tsc-watch with different po
const files = [libFile, file1, tsconfig, realA, realB, symLinkA, symLinkB, symLinkBInA, symLinkAInB];
const environmentVariables = new Map<string, string>();
environmentVariables.set("TSC_WATCHDIRECTORY", Tsc_WatchDirectory.NonRecursiveWatchDirectory);
return createWatchedSystem(files, { environmentVariables, currentDirectory: cwd });
return createWatchedSystem(files, { osFlavor: TestServerHostOsFlavor.Linux, environmentVariables, currentDirectory: cwd });
},
});

Expand All @@ -252,7 +253,7 @@ describe("unittests:: tsc-watch:: watchEnvironment:: tsc-watch with different po
content: `export const x = 10;`,
};
const files = [libFile, file1, file2, configFile];
return createWatchedSystem(files, { runWithoutRecursiveWatches: true });
return createWatchedSystem(files, { osFlavor: TestServerHostOsFlavor.Linux });
},
edits: [
{
Expand Down Expand Up @@ -330,7 +331,7 @@ describe("unittests:: tsc-watch:: watchEnvironment:: tsc-watch with different po
content: `export const x = 10;`,
};
const files = [libFile, file1, file2, configFile];
return createWatchedSystem(files, { runWithoutRecursiveWatches: true });
return createWatchedSystem(files, { osFlavor: TestServerHostOsFlavor.Linux });
},
edits: [
noopChange,
Expand Down Expand Up @@ -371,7 +372,7 @@ describe("unittests:: tsc-watch:: watchEnvironment:: tsc-watch with different po
content: `export const x = 10;`,
};
const files = [libFile, file1, file2, configFile];
return createWatchedSystem(files, { runWithoutRecursiveWatches: true });
return createWatchedSystem(files, { osFlavor: TestServerHostOsFlavor.Linux });
},
edits: [
noopChange,
Expand Down Expand Up @@ -427,7 +428,7 @@ describe("unittests:: tsc-watch:: watchEnvironment:: tsc-watch with different po
}),
};
const files = [libFile, commonFile1, commonFile2, configFile];
return createWatchedSystem(files, { runWithoutRecursiveWatches: true });
return createWatchedSystem(files, { osFlavor: TestServerHostOsFlavor.Linux });
},
});

Expand All @@ -445,7 +446,7 @@ describe("unittests:: tsc-watch:: watchEnvironment:: tsc-watch with different po
}),
};
const files = [libFile, commonFile1, commonFile2, configFile];
return createWatchedSystem(files, { runWithoutRecursiveWatches: true, runWithFallbackPolling: true });
return createWatchedSystem(files, { osFlavor: TestServerHostOsFlavor.Linux, runWithFallbackPolling: true });
},
});

Expand All @@ -464,7 +465,7 @@ describe("unittests:: tsc-watch:: watchEnvironment:: tsc-watch with different po
});

describe("exclude options", () => {
function sys(watchOptions: ts.WatchOptions, runWithoutRecursiveWatches?: boolean): TestServerHost {
function sys(watchOptions: ts.WatchOptions, osFlavor?: TestServerHostOsFlavor.Linux): TestServerHost {
const configFile: File = {
path: `/user/username/projects/myproject/tsconfig.json`,
content: jsonToReadableText({ exclude: ["node_modules"], watchOptions }),
Expand All @@ -490,7 +491,7 @@ describe("unittests:: tsc-watch:: watchEnvironment:: tsc-watch with different po
content: "export function temp(): string;",
};
const files = [libFile, main, bar, foo, fooBar, temp, configFile];
return createWatchedSystem(files, { currentDirectory: "/user/username/projects/myproject", runWithoutRecursiveWatches });
return createWatchedSystem(files, { currentDirectory: "/user/username/projects/myproject", osFlavor });
}

function verifyWorker(...additionalFlags: string[]) {
Expand Down Expand Up @@ -526,7 +527,7 @@ describe("unittests:: tsc-watch:: watchEnvironment:: tsc-watch with different po
scenario,
subScenario: `watchOptions/with excludeDirectories option with recursive directory watching${additionalFlags.join("")}`,
commandLineArgs: ["-w", ...additionalFlags],
sys: () => sys({ excludeDirectories: ["**/temp"] }, /*runWithoutRecursiveWatches*/ true),
sys: () => sys({ excludeDirectories: ["**/temp"] }, TestServerHostOsFlavor.Linux),
edits: [
{
caption: "Directory watch updates because of main.js creation",
Expand Down Expand Up @@ -599,7 +600,7 @@ describe("unittests:: tsc-watch:: watchEnvironment:: tsc-watch with different po
},
{
currentDirectory: "/user/username/projects/myproject",
inodeWatching: true,
osFlavor: TestServerHostOsFlavor.MacOs,
},
),
edits: [
Expand Down Expand Up @@ -630,7 +631,7 @@ describe("unittests:: tsc-watch:: watchEnvironment:: tsc-watch with different po
},
{
currentDirectory: "/user/username/projects/myproject",
inodeWatching: true,
osFlavor: TestServerHostOsFlavor.MacOs,
},
),
edits: [
Expand Down Expand Up @@ -664,7 +665,7 @@ describe("unittests:: tsc-watch:: watchEnvironment:: tsc-watch with different po
},
{
currentDirectory: "/user/username/projects/myproject",
inodeWatching: true,
osFlavor: TestServerHostOsFlavor.MacOs,
},
),
edits: [
Expand All @@ -690,10 +691,10 @@ describe("unittests:: tsc-watch:: watchEnvironment:: tsc-watch with different po
});

describe("with fsWatch with fsWatchWithTimestamp", () => {
function verify(fsWatchWithTimestamp: boolean, watchFile?: "useFsEventsOnParentDirectory") {
function verify(osFlavor: TestServerHostOsFlavor, watchFile?: "useFsEventsOnParentDirectory") {
verifyTscWatch({
scenario,
subScenario: `fsWatch/fsWatchWithTimestamp ${fsWatchWithTimestamp}${watchFile ? ` ${watchFile}` : ""}`,
subScenario: `fsWatch/fsWatchWithTimestamp ${osFlavor === TestServerHostOsFlavor.MacOs}${watchFile ? ` ${watchFile}` : ""}`,
commandLineArgs: ["-w", "--extendedDiagnostics", ...(watchFile ? ["--watchFile", watchFile] : [])],
sys: () =>
createWatchedSystem(
Expand All @@ -704,7 +705,7 @@ describe("unittests:: tsc-watch:: watchEnvironment:: tsc-watch with different po
},
{
currentDirectory: "/user/username/projects/myproject",
fsWatchWithTimestamp,
osFlavor,
},
),
edits: [
Expand All @@ -721,10 +722,10 @@ describe("unittests:: tsc-watch:: watchEnvironment:: tsc-watch with different po
],
});
}
verify(/*fsWatchWithTimestamp*/ true);
verify(/*fsWatchWithTimestamp*/ false);
verify(/*fsWatchWithTimestamp*/ true, "useFsEventsOnParentDirectory");
verify(/*fsWatchWithTimestamp*/ false, "useFsEventsOnParentDirectory");
verify(TestServerHostOsFlavor.MacOs);
verify(TestServerHostOsFlavor.Windows);
verify(TestServerHostOsFlavor.MacOs, "useFsEventsOnParentDirectory");
verify(TestServerHostOsFlavor.Windows, "useFsEventsOnParentDirectory");
});

verifyTscWatch({
Expand Down
18 changes: 11 additions & 7 deletions src/testRunner/unittests/tsserver/watchEnvironment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import {
createServerHost,
File,
libFile,
TestServerHostOsFlavor,
Tsc_WatchDirectory,
} from "../helpers/virtualFileSystemWithWatch";

Expand Down Expand Up @@ -52,7 +53,7 @@ describe("unittests:: tsserver:: watchEnvironment:: tsserverProjectSystem watchD
const files = [index, file1, configFile, libFile];
const environmentVariables = new Map<string, string>();
environmentVariables.set("TSC_WATCHDIRECTORY", tscWatchDirectory);
const host = createServerHost(files, { environmentVariables });
const host = createServerHost(files, { osFlavor: TestServerHostOsFlavor.Linux, environmentVariables });
const session = new TestSession(host);
openFilesForSession([index], session);
session.executeCommandSeq<ts.server.protocol.CompletionsRequest>({
Expand Down Expand Up @@ -141,7 +142,10 @@ describe("unittests:: tsserver:: watchEnvironment:: recursiveWatchDirectory", ()
};
const environmentVariables = new Map<string, string>();
environmentVariables.set("TSC_WATCHDIRECTORY", Tsc_WatchDirectory.NonRecursiveWatchDirectory);
const host = createServerHost([index, file1, configFile, libFile, nodeModulesExistingUnusedFile], { environmentVariables });
const host = createServerHost(
[index, file1, configFile, libFile, nodeModulesExistingUnusedFile],
{ osFlavor: TestServerHostOsFlavor.Linux, environmentVariables },
);
const session = new TestSession(host);
openFilesForSession([index], session);

Expand Down Expand Up @@ -237,7 +241,7 @@ describe("unittests:: tsserver:: watchEnvironment:: handles watch compiler optio
content: "{}",
};
const files = [libFile, commonFile2, configFile];
const host = createServerHost(files.concat(commonFile1), { runWithoutRecursiveWatches: true });
const host = createServerHost(files.concat(commonFile1), { osFlavor: TestServerHostOsFlavor.Linux });
const session = new TestSession(host);
session.executeCommandSeq<ts.server.protocol.ConfigureRequest>({
command: ts.server.protocol.CommandTypes.Configure,
Expand All @@ -257,7 +261,7 @@ describe("unittests:: tsserver:: watchEnvironment:: handles watch compiler optio
content: "{}",
};
const files = [libFile, commonFile2, configFile];
const host = createServerHost(files.concat(commonFile1), { runWithoutRecursiveWatches: true, runWithFallbackPolling: true });
const host = createServerHost(files.concat(commonFile1), { osFlavor: TestServerHostOsFlavor.Linux, runWithFallbackPolling: true });
const session = new TestSession(host);
session.executeCommandSeq<ts.server.protocol.ConfigureRequest>({
command: ts.server.protocol.CommandTypes.Configure,
Expand Down Expand Up @@ -297,7 +301,7 @@ describe("unittests:: tsserver:: watchEnvironment:: handles watch compiler optio
}),
};
const files = [libFile, commonFile2, configFile];
const host = createServerHost(files.concat(commonFile1), { runWithoutRecursiveWatches: true });
const host = createServerHost(files.concat(commonFile1), { osFlavor: TestServerHostOsFlavor.Linux });
const session = new TestSession(host);
openFilesForSession([{ file: commonFile1, projectRootPath: "/a/b" }], session);
baselineTsserverLogs("watchEnvironment", `with watchDirectory option in configFile`, session);
Expand All @@ -313,7 +317,7 @@ describe("unittests:: tsserver:: watchEnvironment:: handles watch compiler optio
}),
};
const files = [libFile, commonFile2, configFile];
const host = createServerHost(files.concat(commonFile1), { runWithoutRecursiveWatches: true, runWithFallbackPolling: true });
const host = createServerHost(files.concat(commonFile1), { osFlavor: TestServerHostOsFlavor.Linux, runWithFallbackPolling: true });
const session = new TestSession(host);
session.executeCommandSeq<ts.server.protocol.ConfigureRequest>({
command: ts.server.protocol.CommandTypes.Configure,
Expand Down Expand Up @@ -515,7 +519,7 @@ describe("unittests:: tsserver:: watchEnvironment:: watching at workspaces codes
path: "/workspaces/somerepo/node_modules/@types/random-seed/index.d.ts",
content: `export function randomSeed(): string;`,
};
const host = createServerHost([config, main, randomSeed, libFile], { inodeWatching: true, runWithoutRecursiveWatches: true });
const host = createServerHost([config, main, randomSeed, libFile], { osFlavor: TestServerHostOsFlavor.Linux });
const session = new TestSession(host);
openFilesForSession([main], session);
verifyGetErrRequest({ session, files: [main] });
Expand Down
Loading