Skip to content

Commit 49cfbb4

Browse files
committed
Added test for windows style paths watched directories
1 parent 50628e7 commit 49cfbb4

2 files changed

Lines changed: 65 additions & 6 deletions

File tree

src/harness/unittests/tsserverProjectSystem.ts

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5760,4 +5760,44 @@ namespace ts.projectSystem {
57605760
}
57615761
});
57625762
});
5763+
5764+
describe("Watched recursive directories with windows style file system", () => {
5765+
function verifyWatchedDirectories(useProjectAtRoot: boolean) {
5766+
const root = useProjectAtRoot ? "c:/" : "c:/myfolder/allproject/";
5767+
const configFile: FileOrFolder = {
5768+
path: root + "project/tsconfig.json",
5769+
content: "{}"
5770+
};
5771+
const file1: FileOrFolder = {
5772+
path: root + "project/file1.ts",
5773+
content: "let x = 10;"
5774+
};
5775+
const file2: FileOrFolder = {
5776+
path: root + "project/file2.ts",
5777+
content: "let y = 10;"
5778+
};
5779+
const files = [configFile, file1, file2, libFile];
5780+
const host = createServerHost(files, { useWindowsStylePaths: true });
5781+
const projectService = createProjectService(host);
5782+
projectService.openClientFile(file1.path);
5783+
const project = projectService.configuredProjects.get(configFile.path);
5784+
assert.isDefined(project);
5785+
const winsowsStyleLibFilePath = "c:/" + libFile.path.substring(1);
5786+
checkProjectActualFiles(project, files.map(f => f === libFile ? winsowsStyleLibFilePath : f.path));
5787+
checkWatchedFiles(host, mapDefined(files, f => f === libFile ? winsowsStyleLibFilePath : f === file1 ? undefined : f.path));
5788+
checkWatchedDirectories(host, [], /*recursive*/ false);
5789+
checkWatchedDirectories(host, [
5790+
root + "project",
5791+
root + "project/node_modules/@types"
5792+
].concat(useProjectAtRoot ? [] : [root + nodeModulesAtTypes]), /*recursive*/ true);
5793+
}
5794+
5795+
it("When project is in rootFolder", () => {
5796+
verifyWatchedDirectories(/*useProjectAtRoot*/ true);
5797+
});
5798+
5799+
it("When files at some folder other than root", () => {
5800+
verifyWatchedDirectories(/*useProjectAtRoot*/ false);
5801+
});
5802+
});
57635803
}

src/harness/virtualFileSystemWithWatch.ts

Lines changed: 25 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ namespace ts.TestFSWithWatch {
2828
executingFilePath?: string;
2929
currentDirectory?: string;
3030
newLine?: string;
31+
useWindowsStylePaths?: boolean;
3132
}
3233

3334
export function createWatchedSystem(fileOrFolderList: ReadonlyArray<FileOrFolder>, params?: TestServerHostCreationParameters): TestServerHost {
@@ -39,7 +40,8 @@ namespace ts.TestFSWithWatch {
3940
params.executingFilePath || getExecutingFilePathFromLibFile(),
4041
params.currentDirectory || "/",
4142
fileOrFolderList,
42-
params.newLine);
43+
params.newLine,
44+
params.useWindowsStylePaths);
4345
return host;
4446
}
4547

@@ -52,7 +54,8 @@ namespace ts.TestFSWithWatch {
5254
params.executingFilePath || getExecutingFilePathFromLibFile(),
5355
params.currentDirectory || "/",
5456
fileOrFolderList,
55-
params.newLine);
57+
params.newLine,
58+
params.useWindowsStylePaths);
5659
return host;
5760
}
5861

@@ -230,11 +233,14 @@ namespace ts.TestFSWithWatch {
230233
readonly watchedDirectories = createMultiMap<TestDirectoryWatcher>();
231234
readonly watchedDirectoriesRecursive = createMultiMap<TestDirectoryWatcher>();
232235
readonly watchedFiles = createMultiMap<TestFileWatcher>();
236+
private readonly executingFilePath: string;
237+
private readonly currentDirectory: string;
233238

234-
constructor(public withSafeList: boolean, public useCaseSensitiveFileNames: boolean, private executingFilePath: string, private currentDirectory: string, fileOrFolderList: ReadonlyArray<FileOrFolder>, public readonly newLine = "\n") {
239+
constructor(public withSafeList: boolean, public useCaseSensitiveFileNames: boolean, executingFilePath: string, currentDirectory: string, fileOrFolderList: ReadonlyArray<FileOrFolder>, public readonly newLine = "\n", public readonly useWindowsStylePath?: boolean) {
235240
this.getCanonicalFileName = createGetCanonicalFileName(useCaseSensitiveFileNames);
236241
this.toPath = s => toPath(s, currentDirectory, this.getCanonicalFileName);
237-
242+
this.executingFilePath = this.getHostSpecificPath(executingFilePath);
243+
this.currentDirectory = this.getHostSpecificPath(currentDirectory);
238244
this.reloadFS(fileOrFolderList);
239245
}
240246

@@ -250,11 +256,24 @@ namespace ts.TestFSWithWatch {
250256
return this.toPath(this.toNormalizedAbsolutePath(s));
251257
}
252258

259+
getHostSpecificPath(s: string) {
260+
if (this.useWindowsStylePath && s.startsWith(directorySeparator)) {
261+
return "c:/" + s.substring(1);
262+
}
263+
return s;
264+
}
265+
253266
reloadFS(fileOrFolderList: ReadonlyArray<FileOrFolder>) {
254267
const mapNewLeaves = createMap<true>();
255268
const isNewFs = this.fs.size === 0;
256-
// always inject safelist file in the list of files
257-
for (const fileOrDirectory of fileOrFolderList.concat(this.withSafeList ? safeList : [])) {
269+
fileOrFolderList = fileOrFolderList.concat(this.withSafeList ? safeList : []);
270+
const filesOrFoldersToLoad: ReadonlyArray<FileOrFolder> = !this.useWindowsStylePath ? fileOrFolderList :
271+
fileOrFolderList.map<FileOrFolder>(f => {
272+
const result = clone(f);
273+
result.path = this.getHostSpecificPath(f.path);
274+
return result;
275+
});
276+
for (const fileOrDirectory of filesOrFoldersToLoad) {
258277
const path = this.toFullPath(fileOrDirectory.path);
259278
mapNewLeaves.set(path, true);
260279
// If its a change

0 commit comments

Comments
 (0)