Add test for failure to use correct current directory in inferred project

Test for #21040
This commit is contained in:
Sheetal Nandi
2018-01-09 15:43:50 -08:00
parent 8bce69e6bd
commit 90a1df9d92
2 changed files with 70 additions and 1 deletions

View File

@@ -6488,4 +6488,73 @@ namespace ts.projectSystem {
verifyWatchedDirectories(/*useProjectAtRoot*/ false);
});
});
describe("tsserverProjectSystem typingsInstaller on inferred Project", () => {
it("when projectRootPath is provided", () => {
const projects = "/users/username/projects";
const projectRootPath = `${projects}/san2`;
const file: FileOrFolder = {
path: `${projectRootPath}/x.js`,
content: "const aaaaaaav = 1;"
};
const currentDirectory = `${projects}/anotherProject`;
const packageJsonInCurrentDirectory: FileOrFolder = {
path: `${currentDirectory}/package.json`,
content: JSON.stringify({
devDependencies: {
"pkgcurrentdirectory": ""
},
})
};
const packageJsonOfPkgcurrentdirectory: FileOrFolder = {
path: `${currentDirectory}/node_modules/pkgcurrentdirectory/package.json`,
content: JSON.stringify({
name: "pkgcurrentdirectory",
main: "index.js",
typings: "index.d.ts"
})
};
const indexOfPkgcurrentdirectory: FileOrFolder = {
path: `${currentDirectory}/node_modules/pkgcurrentdirectory/index.d.ts`,
content: "export function foo() { }"
};
const typingsCache = `/users/username/Library/Caches/typescript/2.7`;
const typingsCachePackageJson: FileOrFolder = {
path: `${typingsCache}/package.json`,
content: JSON.stringify({
devDependencies: {
},
})
};
const files = [file, packageJsonInCurrentDirectory, packageJsonOfPkgcurrentdirectory, indexOfPkgcurrentdirectory, typingsCachePackageJson];
const host = createServerHost(files, { currentDirectory });
const typesRegistry = createMap<void>();
typesRegistry.set("pkgcurrentdirectory", void 0);
const typingsInstaller = new TestTypingsInstaller(typingsCache, /*throttleLimit*/ 5, host, typesRegistry);
const projectService = createProjectService(host, { typingsInstaller });
projectService.setCompilerOptionsForInferredProjects({
module: ModuleKind.CommonJS,
target: ScriptTarget.ES2016,
jsx: JsxEmit.Preserve,
experimentalDecorators: true,
allowJs: true,
allowSyntheticDefaultImports: true,
allowNonTsExtensions: true
});
projectService.openClientFile(file.path, file.content, ScriptKind.JS, projectRootPath);
const project = projectService.inferredProjects[0];
assert.isDefined(project);
// Ensure that we use result from types cache when getting ls
assert.isDefined(project.getLanguageService());
});
});
}

View File

@@ -547,7 +547,7 @@ interface Array<T> {}`
}
readDirectory(path: string, extensions?: ReadonlyArray<string>, exclude?: ReadonlyArray<string>, include?: ReadonlyArray<string>, depth?: number): string[] {
return ts.matchFiles(this.toNormalizedAbsolutePath(path), extensions, exclude, include, this.useCaseSensitiveFileNames, this.getCurrentDirectory(), depth, (dir) => {
return ts.matchFiles(path, extensions, exclude, include, this.useCaseSensitiveFileNames, this.getCurrentDirectory(), depth, (dir) => {
const directories: string[] = [];
const files: string[] = [];
const dirEntry = this.fs.get(this.toPath(dir));