Add tests

This commit is contained in:
Ben Lichtman 2020-01-23 14:10:37 -08:00
parent c9c3792747
commit 09528dd6d6
2 changed files with 64 additions and 3 deletions

View File

@ -1428,6 +1428,57 @@ var x = 10;`
host.checkTimeoutQueueLength(0);
});
it("synchronizeProjectList provides redirect info when requested", () => {
const projectRootPath = "/users/username/projects/project";
const fileA: File = {
path: `${projectRootPath}/A/a.ts`,
content: "export const foo: string = 5;"
};
const configA: File = {
path: `${projectRootPath}/A/tsconfig.json`,
content: `{
"compilerOptions": {
"composite": true,
"declaration": true
}
}`
};
const fileB: File = {
path: `${projectRootPath}/B/b.ts`,
content: "import { foo } from \"../A/a\"; console.log(foo);"
};
const configB: File = {
path: `${projectRootPath}/B/tsconfig.json`,
content: `{
"compilerOptions": {
"composite": true,
"declaration": true
},
"references": [
{ "path": "../A" }
]
}`
};
const files = [fileA, fileB, configA, configB, libFile];
const host = createServerHost(files);
const projectService = createProjectService(host);
projectService.openClientFile(fileA.path);
projectService.openClientFile(fileB.path);
const knownProjects = projectService.synchronizeProjectList([], /*includeProjectReferenceRedirectInfo*/ true);
assert(knownProjects.length === 2, `Expected 2 projects but received ${knownProjects.length}`);
assert(knownProjects[0].files?.length === 3, `Expected project A to have 3 files but received ${knownProjects[0].files?.length}`);
assert(knownProjects[0].files?.every(
(file: string | protocol.FileWithProjectReferenceRedirectInfo) =>
typeof file === "object" && !file.isSourceOfProjectReferenceRedirect),
`Expected every file in project A to not be redirected.`
);
assert(knownProjects[1].files?.length === 4, `Expected project B to have 4 files but received ${knownProjects[1].files?.length}`);
knownProjects[1].files?.forEach(
(file: string | protocol.FileWithProjectReferenceRedirectInfo) =>
assert(typeof file === "object" && (!file.isSourceOfProjectReferenceRedirect || file.fileName === fileA.path))
);
});
it("handles delayed directory watch invoke on file creation", () => {
const projectRootPath = "/users/username/projects/project";
const fileB: File = {

View File

@ -7052,6 +7052,16 @@ declare namespace ts.server.protocol {
* compiler settings.
*/
type ExternalProjectCompilerOptions = CompilerOptions & CompileOnSaveMixin & WatchOptions;
interface FileWithProjectReferenceRedirectInfo {
/**
* Name of file
*/
fileName: string;
/**
* True if the file is primarily included in a referenced project
*/
isSourceOfProjectReferenceRedirect: boolean;
}
/**
* Represents a set of changes that happen in project
*/
@ -7059,15 +7069,15 @@ declare namespace ts.server.protocol {
/**
* List of added files
*/
added: string[];
added: string[] | FileWithProjectReferenceRedirectInfo[];
/**
* List of removed files
*/
removed: string[];
removed: string[] | FileWithProjectReferenceRedirectInfo[];
/**
* List of updated files
*/
updated: string[];
updated: string[] | FileWithProjectReferenceRedirectInfo[];
}
/**
* Information found in a configure request.