tsserver's typingInstaller test into typingsInstaller unittest

This commit is contained in:
Sheetal Nandi 2018-12-07 12:25:19 -08:00
parent 1b6db32ecd
commit 37a080bca9
2 changed files with 78 additions and 78 deletions

View File

@ -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";

View File

@ -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]);
});
});
}