Skip to content

Commit e256ec1

Browse files
authored
Now that we have osFlavour some of the TestServerHostOptions can be removed (microsoft#57998)
1 parent fcfec8c commit e256ec1

File tree

25 files changed

+535
-397
lines changed

25 files changed

+535
-397
lines changed

src/testRunner/unittests/helpers/virtualFileSystemWithWatch.ts

Lines changed: 15 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -83,10 +83,7 @@ export interface TestServerHostCreationParameters {
8383
newLine?: string;
8484
windowsStyleRoot?: string;
8585
environmentVariables?: Map<string, string>;
86-
runWithoutRecursiveWatches?: boolean;
8786
runWithFallbackPolling?: boolean;
88-
inodeWatching?: boolean;
89-
fsWatchWithTimestamp?: boolean;
9087
osFlavor?: TestServerHostOsFlavor;
9188
}
9289

@@ -362,7 +359,7 @@ export class TestServerHost implements server.ServerHost, FormatDiagnosticsHost,
362359
importPlugin?: (root: string, moduleName: string) => Promise<ModuleImportResult>;
363360
public storeSignatureInfo = true;
364361
watchFile: HostWatchFile;
365-
private inodeWatching: boolean | undefined;
362+
private inodeWatching: boolean;
366363
private readonly inodes?: Map<Path, number>;
367364
watchDirectory: HostWatchDirectory;
368365
service?: server.ProjectService;
@@ -376,17 +373,13 @@ export class TestServerHost implements server.ServerHost, FormatDiagnosticsHost,
376373
newLine,
377374
windowsStyleRoot,
378375
environmentVariables,
379-
runWithoutRecursiveWatches,
380376
runWithFallbackPolling,
381-
inodeWatching,
382-
fsWatchWithTimestamp,
383377
osFlavor,
384378
}: TestServerHostCreationParameters = {},
385379
) {
386380
this.useCaseSensitiveFileNames = !!useCaseSensitiveFileNames;
387381
this.newLine = newLine || "\n";
388382
this.osFlavor = osFlavor || TestServerHostOsFlavor.Windows;
389-
if (this.osFlavor === TestServerHostOsFlavor.Linux) runWithoutRecursiveWatches = true;
390383
this.windowsStyleRoot = windowsStyleRoot;
391384
this.environmentVariables = environmentVariables;
392385
currentDirectory = currentDirectory || "/";
@@ -398,10 +391,8 @@ export class TestServerHost implements server.ServerHost, FormatDiagnosticsHost,
398391
this.runWithFallbackPolling = !!runWithFallbackPolling;
399392
const tscWatchFile = this.environmentVariables && this.environmentVariables.get("TSC_WATCHFILE");
400393
const tscWatchDirectory = this.environmentVariables && this.environmentVariables.get("TSC_WATCHDIRECTORY");
401-
if (inodeWatching) {
402-
this.inodeWatching = true;
403-
this.inodes = new Map();
404-
}
394+
this.inodeWatching = this.osFlavor !== TestServerHostOsFlavor.Windows;
395+
if (this.inodeWatching) this.inodes = new Map();
405396

406397
const { watchFile, watchDirectory } = createSystemWatchFunctions({
407398
// We dont have polling watch file
@@ -415,13 +406,13 @@ export class TestServerHost implements server.ServerHost, FormatDiagnosticsHost,
415406
fileSystemEntryExists: this.fileSystemEntryExists.bind(this),
416407
useCaseSensitiveFileNames: this.useCaseSensitiveFileNames,
417408
getCurrentDirectory: this.getCurrentDirectory.bind(this),
418-
fsSupportsRecursiveFsWatch: tscWatchDirectory ? false : !runWithoutRecursiveWatches,
409+
fsSupportsRecursiveFsWatch: this.osFlavor !== TestServerHostOsFlavor.Linux,
419410
getAccessibleSortedChildDirectories: path => this.getDirectories(path),
420411
realpath: this.realpath.bind(this),
421412
tscWatchFile,
422413
tscWatchDirectory,
423-
inodeWatching: !!this.inodeWatching,
424-
fsWatchWithTimestamp,
414+
inodeWatching: this.inodeWatching,
415+
fsWatchWithTimestamp: this.osFlavor === TestServerHostOsFlavor.MacOs,
425416
sysLog: s => this.write(s + this.newLine),
426417
});
427418
this.watchFile = watchFile;
@@ -712,15 +703,20 @@ export class TestServerHost implements server.ServerHost, FormatDiagnosticsHost,
712703
cb: FsWatchCallback,
713704
) {
714705
if (this.runWithFallbackPolling) throw new Error("Need to use fallback polling instead of file system native watching");
715-
const path = this.toPath(fileOrDirectory);
716-
// Error if the path does not exist
717-
if (this.inodeWatching && !this.inodes?.has(path)) throw new Error();
706+
let inode: number | undefined;
707+
if (this.inodeWatching) {
708+
const entry = this.getRealFileOrFolder(fileOrDirectory);
709+
// Error if the path does not exist
710+
if (!entry) throw new Error("Cannot watch missing file or folder");
711+
inode = this.inodes?.get(entry.path);
712+
if (inode === undefined) throw new Error("inode not found");
713+
}
718714
const result = this.watchUtils.fsWatch(
719715
this.toNormalizedAbsolutePath(fileOrDirectory),
720716
recursive,
721717
{
722718
cb,
723-
inode: this.inodes?.get(path),
719+
inode,
724720
},
725721
) as FsWatchWorkerWatcher;
726722
result.on = noop;

src/testRunner/unittests/tscWatch/watchEnvironment.ts

Lines changed: 21 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import {
1414
libFile,
1515
SymLink,
1616
TestServerHost,
17+
TestServerHostOsFlavor,
1718
Tsc_WatchDirectory,
1819
Tsc_WatchFile,
1920
} from "../helpers/virtualFileSystemWithWatch";
@@ -162,7 +163,7 @@ describe("unittests:: tsc-watch:: watchEnvironment:: tsc-watch with different po
162163
const files = [file, configFile, libFile];
163164
const environmentVariables = new Map<string, string>();
164165
environmentVariables.set("TSC_WATCHDIRECTORY", tscWatchDirectory);
165-
return createWatchedSystem(files, { environmentVariables });
166+
return createWatchedSystem(files, { osFlavor: TestServerHostOsFlavor.Linux, environmentVariables });
166167
},
167168
edits: [
168169
{
@@ -230,7 +231,7 @@ describe("unittests:: tsc-watch:: watchEnvironment:: tsc-watch with different po
230231
const files = [libFile, file1, tsconfig, realA, realB, symLinkA, symLinkB, symLinkBInA, symLinkAInB];
231232
const environmentVariables = new Map<string, string>();
232233
environmentVariables.set("TSC_WATCHDIRECTORY", Tsc_WatchDirectory.NonRecursiveWatchDirectory);
233-
return createWatchedSystem(files, { environmentVariables, currentDirectory: cwd });
234+
return createWatchedSystem(files, { osFlavor: TestServerHostOsFlavor.Linux, environmentVariables, currentDirectory: cwd });
234235
},
235236
});
236237

@@ -252,7 +253,7 @@ describe("unittests:: tsc-watch:: watchEnvironment:: tsc-watch with different po
252253
content: `export const x = 10;`,
253254
};
254255
const files = [libFile, file1, file2, configFile];
255-
return createWatchedSystem(files, { runWithoutRecursiveWatches: true });
256+
return createWatchedSystem(files, { osFlavor: TestServerHostOsFlavor.Linux });
256257
},
257258
edits: [
258259
{
@@ -330,7 +331,7 @@ describe("unittests:: tsc-watch:: watchEnvironment:: tsc-watch with different po
330331
content: `export const x = 10;`,
331332
};
332333
const files = [libFile, file1, file2, configFile];
333-
return createWatchedSystem(files, { runWithoutRecursiveWatches: true });
334+
return createWatchedSystem(files, { osFlavor: TestServerHostOsFlavor.Linux });
334335
},
335336
edits: [
336337
noopChange,
@@ -371,7 +372,7 @@ describe("unittests:: tsc-watch:: watchEnvironment:: tsc-watch with different po
371372
content: `export const x = 10;`,
372373
};
373374
const files = [libFile, file1, file2, configFile];
374-
return createWatchedSystem(files, { runWithoutRecursiveWatches: true });
375+
return createWatchedSystem(files, { osFlavor: TestServerHostOsFlavor.Linux });
375376
},
376377
edits: [
377378
noopChange,
@@ -427,7 +428,7 @@ describe("unittests:: tsc-watch:: watchEnvironment:: tsc-watch with different po
427428
}),
428429
};
429430
const files = [libFile, commonFile1, commonFile2, configFile];
430-
return createWatchedSystem(files, { runWithoutRecursiveWatches: true });
431+
return createWatchedSystem(files, { osFlavor: TestServerHostOsFlavor.Linux });
431432
},
432433
});
433434

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

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

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

496497
function verifyWorker(...additionalFlags: string[]) {
@@ -526,7 +527,7 @@ describe("unittests:: tsc-watch:: watchEnvironment:: tsc-watch with different po
526527
scenario,
527528
subScenario: `watchOptions/with excludeDirectories option with recursive directory watching${additionalFlags.join("")}`,
528529
commandLineArgs: ["-w", ...additionalFlags],
529-
sys: () => sys({ excludeDirectories: ["**/temp"] }, /*runWithoutRecursiveWatches*/ true),
530+
sys: () => sys({ excludeDirectories: ["**/temp"] }, TestServerHostOsFlavor.Linux),
530531
edits: [
531532
{
532533
caption: "Directory watch updates because of main.js creation",
@@ -599,7 +600,7 @@ describe("unittests:: tsc-watch:: watchEnvironment:: tsc-watch with different po
599600
},
600601
{
601602
currentDirectory: "/user/username/projects/myproject",
602-
inodeWatching: true,
603+
osFlavor: TestServerHostOsFlavor.MacOs,
603604
},
604605
),
605606
edits: [
@@ -630,7 +631,7 @@ describe("unittests:: tsc-watch:: watchEnvironment:: tsc-watch with different po
630631
},
631632
{
632633
currentDirectory: "/user/username/projects/myproject",
633-
inodeWatching: true,
634+
osFlavor: TestServerHostOsFlavor.MacOs,
634635
},
635636
),
636637
edits: [
@@ -664,7 +665,7 @@ describe("unittests:: tsc-watch:: watchEnvironment:: tsc-watch with different po
664665
},
665666
{
666667
currentDirectory: "/user/username/projects/myproject",
667-
inodeWatching: true,
668+
osFlavor: TestServerHostOsFlavor.MacOs,
668669
},
669670
),
670671
edits: [
@@ -690,10 +691,10 @@ describe("unittests:: tsc-watch:: watchEnvironment:: tsc-watch with different po
690691
});
691692

692693
describe("with fsWatch with fsWatchWithTimestamp", () => {
693-
function verify(fsWatchWithTimestamp: boolean, watchFile?: "useFsEventsOnParentDirectory") {
694+
function verify(osFlavor: TestServerHostOsFlavor, watchFile?: "useFsEventsOnParentDirectory") {
694695
verifyTscWatch({
695696
scenario,
696-
subScenario: `fsWatch/fsWatchWithTimestamp ${fsWatchWithTimestamp}${watchFile ? ` ${watchFile}` : ""}`,
697+
subScenario: `fsWatch/fsWatchWithTimestamp ${osFlavor === TestServerHostOsFlavor.MacOs}${watchFile ? ` ${watchFile}` : ""}`,
697698
commandLineArgs: ["-w", "--extendedDiagnostics", ...(watchFile ? ["--watchFile", watchFile] : [])],
698699
sys: () =>
699700
createWatchedSystem(
@@ -704,7 +705,7 @@ describe("unittests:: tsc-watch:: watchEnvironment:: tsc-watch with different po
704705
},
705706
{
706707
currentDirectory: "/user/username/projects/myproject",
707-
fsWatchWithTimestamp,
708+
osFlavor,
708709
},
709710
),
710711
edits: [
@@ -721,10 +722,10 @@ describe("unittests:: tsc-watch:: watchEnvironment:: tsc-watch with different po
721722
],
722723
});
723724
}
724-
verify(/*fsWatchWithTimestamp*/ true);
725-
verify(/*fsWatchWithTimestamp*/ false);
726-
verify(/*fsWatchWithTimestamp*/ true, "useFsEventsOnParentDirectory");
727-
verify(/*fsWatchWithTimestamp*/ false, "useFsEventsOnParentDirectory");
725+
verify(TestServerHostOsFlavor.MacOs);
726+
verify(TestServerHostOsFlavor.Windows);
727+
verify(TestServerHostOsFlavor.MacOs, "useFsEventsOnParentDirectory");
728+
verify(TestServerHostOsFlavor.Windows, "useFsEventsOnParentDirectory");
728729
});
729730

730731
verifyTscWatch({

src/testRunner/unittests/tsserver/watchEnvironment.ts

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ import {
2424
createServerHost,
2525
File,
2626
libFile,
27+
TestServerHostOsFlavor,
2728
Tsc_WatchDirectory,
2829
} from "../helpers/virtualFileSystemWithWatch";
2930

@@ -52,7 +53,7 @@ describe("unittests:: tsserver:: watchEnvironment:: tsserverProjectSystem watchD
5253
const files = [index, file1, configFile, libFile];
5354
const environmentVariables = new Map<string, string>();
5455
environmentVariables.set("TSC_WATCHDIRECTORY", tscWatchDirectory);
55-
const host = createServerHost(files, { environmentVariables });
56+
const host = createServerHost(files, { osFlavor: TestServerHostOsFlavor.Linux, environmentVariables });
5657
const session = new TestSession(host);
5758
openFilesForSession([index], session);
5859
session.executeCommandSeq<ts.server.protocol.CompletionsRequest>({
@@ -141,7 +142,10 @@ describe("unittests:: tsserver:: watchEnvironment:: recursiveWatchDirectory", ()
141142
};
142143
const environmentVariables = new Map<string, string>();
143144
environmentVariables.set("TSC_WATCHDIRECTORY", Tsc_WatchDirectory.NonRecursiveWatchDirectory);
144-
const host = createServerHost([index, file1, configFile, libFile, nodeModulesExistingUnusedFile], { environmentVariables });
145+
const host = createServerHost(
146+
[index, file1, configFile, libFile, nodeModulesExistingUnusedFile],
147+
{ osFlavor: TestServerHostOsFlavor.Linux, environmentVariables },
148+
);
145149
const session = new TestSession(host);
146150
openFilesForSession([index], session);
147151

@@ -237,7 +241,7 @@ describe("unittests:: tsserver:: watchEnvironment:: handles watch compiler optio
237241
content: "{}",
238242
};
239243
const files = [libFile, commonFile2, configFile];
240-
const host = createServerHost(files.concat(commonFile1), { runWithoutRecursiveWatches: true });
244+
const host = createServerHost(files.concat(commonFile1), { osFlavor: TestServerHostOsFlavor.Linux });
241245
const session = new TestSession(host);
242246
session.executeCommandSeq<ts.server.protocol.ConfigureRequest>({
243247
command: ts.server.protocol.CommandTypes.Configure,
@@ -257,7 +261,7 @@ describe("unittests:: tsserver:: watchEnvironment:: handles watch compiler optio
257261
content: "{}",
258262
};
259263
const files = [libFile, commonFile2, configFile];
260-
const host = createServerHost(files.concat(commonFile1), { runWithoutRecursiveWatches: true, runWithFallbackPolling: true });
264+
const host = createServerHost(files.concat(commonFile1), { osFlavor: TestServerHostOsFlavor.Linux, runWithFallbackPolling: true });
261265
const session = new TestSession(host);
262266
session.executeCommandSeq<ts.server.protocol.ConfigureRequest>({
263267
command: ts.server.protocol.CommandTypes.Configure,
@@ -297,7 +301,7 @@ describe("unittests:: tsserver:: watchEnvironment:: handles watch compiler optio
297301
}),
298302
};
299303
const files = [libFile, commonFile2, configFile];
300-
const host = createServerHost(files.concat(commonFile1), { runWithoutRecursiveWatches: true });
304+
const host = createServerHost(files.concat(commonFile1), { osFlavor: TestServerHostOsFlavor.Linux });
301305
const session = new TestSession(host);
302306
openFilesForSession([{ file: commonFile1, projectRootPath: "/a/b" }], session);
303307
baselineTsserverLogs("watchEnvironment", `with watchDirectory option in configFile`, session);
@@ -313,7 +317,7 @@ describe("unittests:: tsserver:: watchEnvironment:: handles watch compiler optio
313317
}),
314318
};
315319
const files = [libFile, commonFile2, configFile];
316-
const host = createServerHost(files.concat(commonFile1), { runWithoutRecursiveWatches: true, runWithFallbackPolling: true });
320+
const host = createServerHost(files.concat(commonFile1), { osFlavor: TestServerHostOsFlavor.Linux, runWithFallbackPolling: true });
317321
const session = new TestSession(host);
318322
session.executeCommandSeq<ts.server.protocol.ConfigureRequest>({
319323
command: ts.server.protocol.CommandTypes.Configure,
@@ -515,7 +519,7 @@ describe("unittests:: tsserver:: watchEnvironment:: watching at workspaces codes
515519
path: "/workspaces/somerepo/node_modules/@types/random-seed/index.d.ts",
516520
content: `export function randomSeed(): string;`,
517521
};
518-
const host = createServerHost([config, main, randomSeed, libFile], { inodeWatching: true, runWithoutRecursiveWatches: true });
522+
const host = createServerHost([config, main, randomSeed, libFile], { osFlavor: TestServerHostOsFlavor.Linux });
519523
const session = new TestSession(host);
520524
openFilesForSession([main], session);
521525
verifyGetErrRequest({ session, files: [main] });

0 commit comments

Comments
 (0)