Skip to content

Commit bf71b9d

Browse files
committed
Add test for microsoft#35011
When searching for a default configured project, stop at `node_modules`.
1 parent bc0e5a2 commit bf71b9d

File tree

2 files changed

+34
-0
lines changed

2 files changed

+34
-0
lines changed

src/testRunner/tsconfig.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,7 @@
101101
"unittests/services/extract/ranges.ts",
102102
"unittests/services/hostNewLineSupport.ts",
103103
"unittests/services/languageService.ts",
104+
"unittests/services/projectService.ts",
104105
"unittests/services/organizeImports.ts",
105106
"unittests/services/patternMatcher.ts",
106107
"unittests/services/preProcessFile.ts",
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
namespace ts {
2+
describe("unittests:: services:: projectService", () => {
3+
it("does not return default configured projects for node_modules", () => {
4+
const rootFilePath = server.asNormalizedPath("/project/index.ts");
5+
const rootProjectPath = server.asNormalizedPath("/project/tsconfig.json");
6+
const nodeModulesFilePath1 = server.asNormalizedPath("/project/node_modules/@types/a/index.d.ts");
7+
const nodeModulesProjectPath1 = server.asNormalizedPath("/project/node_modules/@types/a/tsconfig.json");
8+
const nodeModulesFilePath2 = server.asNormalizedPath("/project/node_modules/@types/b/index.d.ts");
9+
const serverHost = projectSystem.createServerHost([
10+
{ path: rootFilePath, content: "import 'a'; import 'b';" },
11+
{ path: rootProjectPath, content: "{}" },
12+
{ path: nodeModulesFilePath1, content: "{}" },
13+
{ path: nodeModulesProjectPath1, content: "{}" },
14+
{ path: nodeModulesFilePath2, content: "{}" },
15+
]);
16+
const projectService = projectSystem.createProjectService(serverHost, { useSingleInferredProject: true });
17+
18+
const openRootFileResult = projectService.openClientFile(rootFilePath);
19+
assert.strictEqual(openRootFileResult.configFileName?.toString(), rootProjectPath);
20+
21+
const openNodeModulesFileResult1 = projectService.openClientFile(nodeModulesFilePath1);
22+
assert.strictEqual(openNodeModulesFileResult1.configFileName?.toString(), nodeModulesProjectPath1);
23+
24+
const openNodeModulesFileResult2 = projectService.openClientFile(nodeModulesFilePath2);
25+
assert.isUndefined(openNodeModulesFileResult2.configFileName);
26+
27+
const rootProject = projectService.findProject(rootProjectPath)!;
28+
assert.isTrue(rootProject.containsFile(rootFilePath));
29+
assert.isTrue(rootProject.containsFile(nodeModulesFilePath1));
30+
assert.isTrue(rootProject.containsFile(nodeModulesFilePath2));
31+
});
32+
});
33+
}

0 commit comments

Comments
 (0)