1namespace ts.projectSystem { 2 const aTs: File = { 3 path: "/a.ts", 4 content: `import { B } from "./b";` 5 }; 6 const bDts: File = { 7 path: "/b.d.ts", 8 content: `export declare class B {}` 9 }; 10 const bJs: File = { 11 path: "/b.js", 12 content: `export class B {}` 13 }; 14 describe("unittests:: tsserver:: auxiliaryProject", () => { 15 it("AuxiliaryProject does not remove scrips from InferredProject", () => { 16 const host = createServerHost([aTs, bDts, bJs]); 17 const session = createSession(host); 18 const projectService = session.getProjectService(); 19 openFilesForSession([aTs], session); 20 21 // Open file is in inferred project 22 checkNumberOfInferredProjects(projectService, 1); 23 const inferredProject = projectService.inferredProjects[0]; 24 25 // getNoDtsResolutionProject will create an AuxiliaryProject with a.ts and b.js 26 const auxProject = inferredProject.getNoDtsResolutionProject([aTs.path]); 27 auxProject.updateGraph(); 28 29 // b.js ScriptInfo is now available because it's contained by the AuxiliaryProject. 30 // The AuxiliaryProject should never be the default project for anything, so 31 // the ScriptInfo should still report being an orphan, and getting its default 32 // project should throw. 33 const bJsScriptInfo = Debug.checkDefined(projectService.getScriptInfo(bJs.path)); 34 assert(bJsScriptInfo.isOrphan()); 35 assert(bJsScriptInfo.isContainedByBackgroundProject()); 36 assert.deepEqual(bJsScriptInfo.containingProjects, [auxProject]); 37 assert.throws(() => bJsScriptInfo.getDefaultProject()); 38 39 // When b.js is opened in the editor, it should be put into an InferredProject 40 // even though it's still contained by the AuxiliaryProject. 41 openFilesForSession([bJs], session); 42 assert(!bJsScriptInfo.isOrphan()); 43 assert(bJsScriptInfo.isContainedByBackgroundProject()); 44 assert.equal(bJsScriptInfo.getDefaultProject().projectKind, server.ProjectKind.Inferred); 45 }); 46 }); 47} 48