Skip to content

Commit 8c18c76

Browse files
author
Ben Lichtman
committed
Add tests
1 parent f047111 commit 8c18c76

File tree

2 files changed

+75
-0
lines changed

2 files changed

+75
-0
lines changed

src/testRunner/unittests/tsserver/projects.ts

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1482,6 +1482,76 @@ var x = 10;`
14821482
);
14831483
});
14841484

1485+
it("synchronizeProjectList provides updates to redirect info when requested", () => {
1486+
const projectRootPath = "/users/username/projects/project";
1487+
const fileA: File = {
1488+
path: `${projectRootPath}/A/a.ts`,
1489+
content: "export const foo: string = 5;"
1490+
};
1491+
const configA: File = {
1492+
path: `${projectRootPath}/A/tsconfig.json`,
1493+
content: `{
1494+
"compilerOptions": {
1495+
"composite": true,
1496+
"declaration": true
1497+
}
1498+
}`
1499+
};
1500+
const fileB: File = {
1501+
path: `${projectRootPath}/B/b.ts`,
1502+
content: "import { foo } from \"../B/b2\"; console.log(foo);"
1503+
};
1504+
const fileB2: File = {
1505+
path: `${projectRootPath}/B/b2.ts`,
1506+
content: "export const foo: string = 5;"
1507+
};
1508+
const configB: File = {
1509+
path: `${projectRootPath}/B/tsconfig.json`,
1510+
content: `{
1511+
"compilerOptions": {
1512+
"composite": true,
1513+
"declaration": true
1514+
},
1515+
"references": [
1516+
{ "path": "../A" }
1517+
]
1518+
}`
1519+
};
1520+
const files = [fileA, fileB, fileB2, configA, configB, libFile];
1521+
const host = createServerHost(files);
1522+
const projectService = createProjectService(host);
1523+
projectService.openClientFile(fileA.path);
1524+
projectService.openClientFile(fileB.path);
1525+
const knownProjects = projectService.synchronizeProjectList([], /*includeProjectReferenceRedirectInfo*/ true);
1526+
assert(knownProjects.length === 2, `Expected 2 projects but received ${knownProjects.length}`);
1527+
assert(knownProjects[0].files?.length === 3, `Expected project A to have 3 files but received ${knownProjects[0].files?.length}`);
1528+
assert(knownProjects[0].files?.every(
1529+
(file: string | protocol.FileWithProjectReferenceRedirectInfo) =>
1530+
typeof file === "object" && !file.isSourceOfProjectReferenceRedirect),
1531+
`Expected every file in project A to not be redirected.`
1532+
);
1533+
assert(knownProjects[1].files?.length === 4, `Expected project B to have 4 files but received ${knownProjects[1].files?.length}`);
1534+
assert(knownProjects[1].files?.every(
1535+
(file: string | protocol.FileWithProjectReferenceRedirectInfo) =>
1536+
typeof file === "object" && !file.isSourceOfProjectReferenceRedirect),
1537+
`Expected every file in project B to not be redirected.`
1538+
);
1539+
1540+
host.modifyFile(configA.path, `{
1541+
"compilerOptions": {
1542+
"composite": true,
1543+
"declaration": true
1544+
},
1545+
"include": [
1546+
"**/*",
1547+
"../B/b2.ts"
1548+
]
1549+
}`);
1550+
const newKnownProjects = projectService.synchronizeProjectList(knownProjects.map(proj => proj.info!), /*includeProjectReferenceRedirectInfo*/ true);
1551+
assert(newKnownProjects[0].changes?.added.length === 1, `Expected b2.ts to be added to project A`);
1552+
assert(newKnownProjects[1].changes?.updatedRedirects?.length === 1, `Expected b2.ts to be updated in project B`);
1553+
});
1554+
14851555
it("handles delayed directory watch invoke on file creation", () => {
14861556
const projectRootPath = "/users/username/projects/project";
14871557
const fileB: File = {

tests/baselines/reference/api/tsserverlibrary.d.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7079,6 +7079,11 @@ declare namespace ts.server.protocol {
70797079
* List of updated files
70807080
*/
70817081
updated: string[] | FileWithProjectReferenceRedirectInfo[];
7082+
/**
7083+
* List of files that have had their project reference redirect status updated
7084+
* Only provided when the synchronizeProjectList request has includeProjectReferenceRedirectInfo set to true
7085+
*/
7086+
updatedRedirects?: FileWithProjectReferenceRedirectInfo[];
70827087
}
70837088
/**
70847089
* Information found in a configure request.

0 commit comments

Comments
 (0)