1import * as ts from "../../_namespaces/ts"; 2 3describe("unittests:: tsserver:: maxNodeModuleJsDepth for inferred projects", () => { 4 it("should be set to 2 if the project has js root files", () => { 5 const file1: ts.projectSystem.File = { 6 path: "/a/b/file1.js", 7 content: `var t = require("test"); t.` 8 }; 9 const moduleFile: ts.projectSystem.File = { 10 path: "/a/b/node_modules/test/index.js", 11 content: `var v = 10; module.exports = v;` 12 }; 13 14 const host = ts.projectSystem.createServerHost([file1, moduleFile]); 15 const projectService = ts.projectSystem.createProjectService(host); 16 projectService.openClientFile(file1.path); 17 18 let project = projectService.inferredProjects[0]; 19 let options = project.getCompilationSettings(); 20 assert.isTrue(options.maxNodeModuleJsDepth === 2); 21 22 // Assert the option sticks 23 projectService.setCompilerOptionsForInferredProjects({ target: ts.ScriptTarget.ES2016 }); 24 project = projectService.inferredProjects[0]; 25 options = project.getCompilationSettings(); 26 assert.isTrue(options.maxNodeModuleJsDepth === 2); 27 }); 28 29 it("should return to normal state when all js root files are removed from project", () => { 30 const file1 = { 31 path: "/a/file1.ts", 32 content: "let x =1;" 33 }; 34 const file2 = { 35 path: "/a/file2.js", 36 content: "let x =1;" 37 }; 38 39 const host = ts.projectSystem.createServerHost([file1, file2, ts.projectSystem.libFile]); 40 const projectService = ts.projectSystem.createProjectService(host, { useSingleInferredProject: true }); 41 42 projectService.openClientFile(file1.path); 43 ts.projectSystem.checkNumberOfInferredProjects(projectService, 1); 44 let project = projectService.inferredProjects[0]; 45 assert.isUndefined(project.getCompilationSettings().maxNodeModuleJsDepth); 46 47 projectService.openClientFile(file2.path); 48 project = projectService.inferredProjects[0]; 49 assert.isTrue(project.getCompilationSettings().maxNodeModuleJsDepth === 2); 50 51 projectService.closeClientFile(file2.path); 52 project = projectService.inferredProjects[0]; 53 assert.isUndefined(project.getCompilationSettings().maxNodeModuleJsDepth); 54 }); 55}); 56