diff --git a/src/testRunner/unittests/tsserverProjectSystem.ts b/src/testRunner/unittests/tsserverProjectSystem.ts index 3ccb7b2ffa0..69de01cf969 100644 --- a/src/testRunner/unittests/tsserverProjectSystem.ts +++ b/src/testRunner/unittests/tsserverProjectSystem.ts @@ -7329,84 +7329,6 @@ var x = 10;` }); }); - describe("tsserverProjectSystem typingsInstaller on inferred Project", () => { - it("when projectRootPath is provided", () => { - const projects = "/users/username/projects"; - const projectRootPath = `${projects}/san2`; - const file: File = { - path: `${projectRootPath}/x.js`, - content: "const aaaaaaav = 1;" - }; - - const currentDirectory = `${projects}/anotherProject`; - const packageJsonInCurrentDirectory: File = { - path: `${currentDirectory}/package.json`, - content: JSON.stringify({ - devDependencies: { - pkgcurrentdirectory: "" - }, - }) - }; - const packageJsonOfPkgcurrentdirectory: File = { - path: `${currentDirectory}/node_modules/pkgcurrentdirectory/package.json`, - content: JSON.stringify({ - name: "pkgcurrentdirectory", - main: "index.js", - typings: "index.d.ts" - }) - }; - const indexOfPkgcurrentdirectory: File = { - path: `${currentDirectory}/node_modules/pkgcurrentdirectory/index.d.ts`, - content: "export function foo() { }" - }; - - const typingsCache = `/users/username/Library/Caches/typescript/2.7`; - const typingsCachePackageJson: File = { - path: `${typingsCache}/package.json`, - content: JSON.stringify({ - devDependencies: { - }, - }) - }; - const typingsCachePackageLockJson: File = { - path: `${typingsCache}/package-lock.json`, - content: JSON.stringify({ - dependencies: { - }, - }) - }; - - const files = [file, packageJsonInCurrentDirectory, packageJsonOfPkgcurrentdirectory, indexOfPkgcurrentdirectory, typingsCachePackageJson, typingsCachePackageLockJson]; - const host = createServerHost(files, { currentDirectory }); - - const typesRegistry = createTypesRegistry("pkgcurrentdirectory"); - const typingsInstaller = new TestTypingsInstaller(typingsCache, /*throttleLimit*/ 5, host, typesRegistry); - - const projectService = createProjectService(host, { typingsInstaller }); - - projectService.setCompilerOptionsForInferredProjects({ - module: ModuleKind.CommonJS, - target: ScriptTarget.ES2016, - jsx: JsxEmit.Preserve, - experimentalDecorators: true, - allowJs: true, - allowSyntheticDefaultImports: true, - allowNonTsExtensions: true - }); - - projectService.openClientFile(file.path, file.content, ScriptKind.JS, projectRootPath); - - const project = projectService.inferredProjects[0]; - assert.isDefined(project); - - // Ensure that we use result from types cache when getting ls - assert.isDefined(project.getLanguageService()); - - // Verify that the pkgcurrentdirectory from the current directory isnt picked up - checkProjectActualFiles(project, [file.path]); - }); - }); - describe("tsserverProjectSystem with symLinks", () => { it("rename in common file renames all project", () => { const projects = "/users/username/projects"; diff --git a/src/testRunner/unittests/typingsInstaller.ts b/src/testRunner/unittests/typingsInstaller.ts index 2b18af6a71f..f0cd9549e6c 100644 --- a/src/testRunner/unittests/typingsInstaller.ts +++ b/src/testRunner/unittests/typingsInstaller.ts @@ -1774,4 +1774,82 @@ namespace ts.projectSystem { `, ["foo"], [fooAA, fooAB, fooAC]); }); }); + + describe("typingsInstaller:: tsserver:: with inferred Project", () => { + it("when projectRootPath is provided", () => { + const projects = "/users/username/projects"; + const projectRootPath = `${projects}/san2`; + const file: File = { + path: `${projectRootPath}/x.js`, + content: "const aaaaaaav = 1;" + }; + + const currentDirectory = `${projects}/anotherProject`; + const packageJsonInCurrentDirectory: File = { + path: `${currentDirectory}/package.json`, + content: JSON.stringify({ + devDependencies: { + pkgcurrentdirectory: "" + }, + }) + }; + const packageJsonOfPkgcurrentdirectory: File = { + path: `${currentDirectory}/node_modules/pkgcurrentdirectory/package.json`, + content: JSON.stringify({ + name: "pkgcurrentdirectory", + main: "index.js", + typings: "index.d.ts" + }) + }; + const indexOfPkgcurrentdirectory: File = { + path: `${currentDirectory}/node_modules/pkgcurrentdirectory/index.d.ts`, + content: "export function foo() { }" + }; + + const typingsCache = `/users/username/Library/Caches/typescript/2.7`; + const typingsCachePackageJson: File = { + path: `${typingsCache}/package.json`, + content: JSON.stringify({ + devDependencies: { + }, + }) + }; + const typingsCachePackageLockJson: File = { + path: `${typingsCache}/package-lock.json`, + content: JSON.stringify({ + dependencies: { + }, + }) + }; + + const files = [file, packageJsonInCurrentDirectory, packageJsonOfPkgcurrentdirectory, indexOfPkgcurrentdirectory, typingsCachePackageJson, typingsCachePackageLockJson]; + const host = createServerHost(files, { currentDirectory }); + + const typesRegistry = createTypesRegistry("pkgcurrentdirectory"); + const typingsInstaller = new TestTypingsInstaller(typingsCache, /*throttleLimit*/ 5, host, typesRegistry); + + const projectService = createProjectService(host, { typingsInstaller }); + + projectService.setCompilerOptionsForInferredProjects({ + module: ModuleKind.CommonJS, + target: ScriptTarget.ES2016, + jsx: JsxEmit.Preserve, + experimentalDecorators: true, + allowJs: true, + allowSyntheticDefaultImports: true, + allowNonTsExtensions: true + }); + + projectService.openClientFile(file.path, file.content, ScriptKind.JS, projectRootPath); + + const project = projectService.inferredProjects[0]; + assert.isDefined(project); + + // Ensure that we use result from types cache when getting ls + assert.isDefined(project.getLanguageService()); + + // Verify that the pkgcurrentdirectory from the current directory isnt picked up + checkProjectActualFiles(project, [file.path]); + }); + }); }