Skip to content

Commit 345f36d

Browse files
committed
Update tests
1 parent d7ce95d commit 345f36d

File tree

1 file changed

+23
-5
lines changed

1 file changed

+23
-5
lines changed

src/harness/unittests/tsserverProjectSystem.ts

Lines changed: 23 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -247,6 +247,23 @@ namespace ts.projectSystem {
247247
checkFileNames(`${server.ProjectKind[project.projectKind]} project, rootFileNames`, project.getRootFiles(), expectedFiles);
248248
}
249249

250+
function getNodeModuleDirectories(dir: string) {
251+
const result: string[] = [];
252+
while (true) {
253+
result.push(combinePaths(dir, "node_modules"));
254+
const parentDir = getDirectoryPath(dir);
255+
if (parentDir === dir) {
256+
break;
257+
}
258+
dir = parentDir;
259+
}
260+
return result;
261+
}
262+
263+
function getNumberOfWatchesInvokedForRecursiveWatches(recursiveWatchedDirs: string[], file: string) {
264+
return countWhere(recursiveWatchedDirs, dir => file.length > dir.length && startsWith(file, dir) && file[dir.length] === directorySeparator);
265+
}
266+
250267
/**
251268
* Test server cancellation token used to mock host token cancellation requests.
252269
* The cancelAfterRequest constructor param specifies how many isCancellationRequested() calls
@@ -375,7 +392,7 @@ namespace ts.projectSystem {
375392
const configFiles = flatMap(configFileLocations, location => [location + "tsconfig.json", location + "jsconfig.json"]);
376393
checkWatchedFiles(host, configFiles.concat(libFile.path, moduleFile.path));
377394
checkWatchedDirectories(host, [], /*recursive*/ false);
378-
checkWatchedDirectories(host, ["/", typeRootFromTsserverLocation], /*recursive*/ true);
395+
checkWatchedDirectories(host, ["/a/b/c", typeRootFromTsserverLocation], /*recursive*/ true);
379396
});
380397

381398
it("can handle tsconfig file name with difference casing", () => {
@@ -4243,7 +4260,7 @@ namespace ts.projectSystem {
42434260
const { configFileName } = projectService.openClientFile(file1.path);
42444261
assert.equal(configFileName, tsconfigFile.path, `should find config`);
42454262
checkNumberOfConfiguredProjects(projectService, 1);
4246-
const watchingRecursiveDirectories = [`${canonicalFrontendDir}/src`, canonicalFrontendDir, "/"];
4263+
const watchingRecursiveDirectories = [`${canonicalFrontendDir}/src`, canonicalFrontendDir].concat(getNodeModuleDirectories(getDirectoryPath(canonicalFrontendDir)));
42474264

42484265
const project = projectService.configuredProjects.get(canonicalConfigPath);
42494266
verifyProjectAndWatchedDirectories();
@@ -4256,7 +4273,8 @@ namespace ts.projectSystem {
42564273
host.runQueuedTimeoutCallbacks();
42574274

42584275
const canonicalFile3Path = useCaseSensitiveFileNames ? file3.path : file3.path.toLocaleLowerCase();
4259-
callsTrackingHost.verifyCalledOnEachEntryNTimes("fileExists", [canonicalFile3Path], watchingRecursiveDirectories.length);
4276+
const numberOfTimesWatchInvoked = getNumberOfWatchesInvokedForRecursiveWatches(watchingRecursiveDirectories, canonicalFile3Path);
4277+
callsTrackingHost.verifyCalledOnEachEntryNTimes("fileExists", [canonicalFile3Path], numberOfTimesWatchInvoked);
42604278

42614279
// Called for type root resolution
42624280
const directoryExistsCalled = createMap<number>();
@@ -4266,7 +4284,7 @@ namespace ts.projectSystem {
42664284
directoryExistsCalled.set(`/node_modules`, 2);
42674285
directoryExistsCalled.set(`${frontendDir}/types`, 2);
42684286
directoryExistsCalled.set(`${frontendDir}/node_modules/@types`, 2);
4269-
directoryExistsCalled.set(canonicalFile3Path, watchingRecursiveDirectories.length);
4287+
directoryExistsCalled.set(canonicalFile3Path, numberOfTimesWatchInvoked);
42704288
callsTrackingHost.verifyCalledOnEachEntry("directoryExists", directoryExistsCalled);
42714289

42724290
callsTrackingHost.verifyNoCall("getDirectories");
@@ -4353,7 +4371,7 @@ namespace ts.projectSystem {
43534371
const projectService = createProjectService(host);
43544372
const { configFileName } = projectService.openClientFile(app.path);
43554373
assert.equal(configFileName, tsconfigJson.path, `should find config`);
4356-
const recursiveWatchedDirectories: string[] = [appFolder, "/"];
4374+
const recursiveWatchedDirectories: string[] = [appFolder].concat(getNodeModuleDirectories(getDirectoryPath(appFolder)));
43574375
verifyProject();
43584376

43594377
let timeoutAfterReloadFs = timeoutDuringPartialInstallation;

0 commit comments

Comments
 (0)