mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-02-12 21:37:41 -06:00
tsserver's typingInstaller test into typingsInstaller unittest
This commit is contained in:
parent
1b6db32ecd
commit
37a080bca9
@ -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";
|
||||
|
||||
@ -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]);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user