Skip to content

Commit 09528dd

Browse files
author
Ben Lichtman
committed
Add tests
1 parent c9c3792 commit 09528dd

File tree

2 files changed

+64
-3
lines changed

2 files changed

+64
-3
lines changed

src/testRunner/unittests/tsserver/projects.ts

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1428,6 +1428,57 @@ var x = 10;`
14281428
host.checkTimeoutQueueLength(0);
14291429
});
14301430

1431+
it("synchronizeProjectList provides redirect info when requested", () => {
1432+
const projectRootPath = "/users/username/projects/project";
1433+
const fileA: File = {
1434+
path: `${projectRootPath}/A/a.ts`,
1435+
content: "export const foo: string = 5;"
1436+
};
1437+
const configA: File = {
1438+
path: `${projectRootPath}/A/tsconfig.json`,
1439+
content: `{
1440+
"compilerOptions": {
1441+
"composite": true,
1442+
"declaration": true
1443+
}
1444+
}`
1445+
};
1446+
const fileB: File = {
1447+
path: `${projectRootPath}/B/b.ts`,
1448+
content: "import { foo } from \"../A/a\"; console.log(foo);"
1449+
};
1450+
const configB: File = {
1451+
path: `${projectRootPath}/B/tsconfig.json`,
1452+
content: `{
1453+
"compilerOptions": {
1454+
"composite": true,
1455+
"declaration": true
1456+
},
1457+
"references": [
1458+
{ "path": "../A" }
1459+
]
1460+
}`
1461+
};
1462+
const files = [fileA, fileB, configA, configB, libFile];
1463+
const host = createServerHost(files);
1464+
const projectService = createProjectService(host);
1465+
projectService.openClientFile(fileA.path);
1466+
projectService.openClientFile(fileB.path);
1467+
const knownProjects = projectService.synchronizeProjectList([], /*includeProjectReferenceRedirectInfo*/ true);
1468+
assert(knownProjects.length === 2, `Expected 2 projects but received ${knownProjects.length}`);
1469+
assert(knownProjects[0].files?.length === 3, `Expected project A to have 3 files but received ${knownProjects[0].files?.length}`);
1470+
assert(knownProjects[0].files?.every(
1471+
(file: string | protocol.FileWithProjectReferenceRedirectInfo) =>
1472+
typeof file === "object" && !file.isSourceOfProjectReferenceRedirect),
1473+
`Expected every file in project A to not be redirected.`
1474+
);
1475+
assert(knownProjects[1].files?.length === 4, `Expected project B to have 4 files but received ${knownProjects[1].files?.length}`);
1476+
knownProjects[1].files?.forEach(
1477+
(file: string | protocol.FileWithProjectReferenceRedirectInfo) =>
1478+
assert(typeof file === "object" && (!file.isSourceOfProjectReferenceRedirect || file.fileName === fileA.path))
1479+
);
1480+
});
1481+
14311482
it("handles delayed directory watch invoke on file creation", () => {
14321483
const projectRootPath = "/users/username/projects/project";
14331484
const fileB: File = {

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

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7052,22 +7052,32 @@ declare namespace ts.server.protocol {
70527052
* compiler settings.
70537053
*/
70547054
type ExternalProjectCompilerOptions = CompilerOptions & CompileOnSaveMixin & WatchOptions;
7055+
interface FileWithProjectReferenceRedirectInfo {
7056+
/**
7057+
* Name of file
7058+
*/
7059+
fileName: string;
7060+
/**
7061+
* True if the file is primarily included in a referenced project
7062+
*/
7063+
isSourceOfProjectReferenceRedirect: boolean;
7064+
}
70557065
/**
70567066
* Represents a set of changes that happen in project
70577067
*/
70587068
interface ProjectChanges {
70597069
/**
70607070
* List of added files
70617071
*/
7062-
added: string[];
7072+
added: string[] | FileWithProjectReferenceRedirectInfo[];
70637073
/**
70647074
* List of removed files
70657075
*/
7066-
removed: string[];
7076+
removed: string[] | FileWithProjectReferenceRedirectInfo[];
70677077
/**
70687078
* List of updated files
70697079
*/
7070-
updated: string[];
7080+
updated: string[] | FileWithProjectReferenceRedirectInfo[];
70717081
}
70727082
/**
70737083
* Information found in a configure request.

0 commit comments

Comments
 (0)