* Add test for #35011

When searching for a default configured project, stop at
`node_modules`.

* Be more explicit about inferred projects

* Move test into tsserver/projects.ts

* Use existing helpers to simplify tests
This commit is contained in:
Andrew Casey
2020-03-25 14:48:54 -07:00
committed by GitHub
parent 8615eecfc1
commit e1772fa40e

View File

@@ -1590,5 +1590,34 @@ namespace ts.projectSystem {
assert.isTrue(e.message.indexOf("Debug Failure. False expression: Found script Info still attached to project") === 0);
}
});
it("does not look beyond node_modules folders for default configured projects", () => {
const rootFilePath = server.asNormalizedPath("/project/index.ts");
const rootProjectPath = server.asNormalizedPath("/project/tsconfig.json");
const nodeModulesFilePath1 = server.asNormalizedPath("/project/node_modules/@types/a/index.d.ts");
const nodeModulesProjectPath1 = server.asNormalizedPath("/project/node_modules/@types/a/tsconfig.json");
const nodeModulesFilePath2 = server.asNormalizedPath("/project/node_modules/@types/b/index.d.ts");
const serverHost = createServerHost([
{ path: rootFilePath, content: "import 'a'; import 'b';" },
{ path: rootProjectPath, content: "{}" },
{ path: nodeModulesFilePath1, content: "{}" },
{ path: nodeModulesProjectPath1, content: "{}" },
{ path: nodeModulesFilePath2, content: "{}" },
]);
const projectService = createProjectService(serverHost, { useSingleInferredProject: true });
const openRootFileResult = projectService.openClientFile(rootFilePath);
assert.strictEqual(openRootFileResult.configFileName?.toString(), rootProjectPath);
const openNodeModulesFileResult1 = projectService.openClientFile(nodeModulesFilePath1);
assert.strictEqual(openNodeModulesFileResult1.configFileName?.toString(), nodeModulesProjectPath1);
const openNodeModulesFileResult2 = projectService.openClientFile(nodeModulesFilePath2);
assert.isUndefined(openNodeModulesFileResult2.configFileName);
const rootProject = projectService.findProject(rootProjectPath)!;
checkProjectActualFiles(rootProject, [rootProjectPath, rootFilePath, nodeModulesFilePath1, nodeModulesFilePath2]);
checkNumberOfInferredProjects(projectService, 0);
});
});
}