Skip to content

Commit e1772fa

Browse files
authored
* Add test for microsoft#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
1 parent 8615eec commit e1772fa

File tree

1 file changed

+29
-0
lines changed

1 file changed

+29
-0
lines changed

src/testRunner/unittests/tsserver/projects.ts

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1590,5 +1590,34 @@ namespace ts.projectSystem {
15901590
assert.isTrue(e.message.indexOf("Debug Failure. False expression: Found script Info still attached to project") === 0);
15911591
}
15921592
});
1593+
it("does not look beyond node_modules folders for default configured projects", () => {
1594+
const rootFilePath = server.asNormalizedPath("/project/index.ts");
1595+
const rootProjectPath = server.asNormalizedPath("/project/tsconfig.json");
1596+
const nodeModulesFilePath1 = server.asNormalizedPath("/project/node_modules/@types/a/index.d.ts");
1597+
const nodeModulesProjectPath1 = server.asNormalizedPath("/project/node_modules/@types/a/tsconfig.json");
1598+
const nodeModulesFilePath2 = server.asNormalizedPath("/project/node_modules/@types/b/index.d.ts");
1599+
const serverHost = createServerHost([
1600+
{ path: rootFilePath, content: "import 'a'; import 'b';" },
1601+
{ path: rootProjectPath, content: "{}" },
1602+
{ path: nodeModulesFilePath1, content: "{}" },
1603+
{ path: nodeModulesProjectPath1, content: "{}" },
1604+
{ path: nodeModulesFilePath2, content: "{}" },
1605+
]);
1606+
const projectService = createProjectService(serverHost, { useSingleInferredProject: true });
1607+
1608+
const openRootFileResult = projectService.openClientFile(rootFilePath);
1609+
assert.strictEqual(openRootFileResult.configFileName?.toString(), rootProjectPath);
1610+
1611+
const openNodeModulesFileResult1 = projectService.openClientFile(nodeModulesFilePath1);
1612+
assert.strictEqual(openNodeModulesFileResult1.configFileName?.toString(), nodeModulesProjectPath1);
1613+
1614+
const openNodeModulesFileResult2 = projectService.openClientFile(nodeModulesFilePath2);
1615+
assert.isUndefined(openNodeModulesFileResult2.configFileName);
1616+
1617+
const rootProject = projectService.findProject(rootProjectPath)!;
1618+
checkProjectActualFiles(rootProject, [rootProjectPath, rootFilePath, nodeModulesFilePath1, nodeModulesFilePath2]);
1619+
1620+
checkNumberOfInferredProjects(projectService, 0);
1621+
});
15931622
});
15941623
}

0 commit comments

Comments
 (0)