Skip to content

Commit b8cd9f2

Browse files
committed
More baselining of host state
1 parent b10b197 commit b8cd9f2

File tree

405 files changed

+43826
-1410
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

405 files changed

+43826
-1410
lines changed

src/testRunner/unittests/tsserver/cachingFileSystemInformation.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ namespace ts.projectSystem {
146146
logCacheAndClear(projectService.logger);
147147

148148
host.writeFile(imported.path, imported.content);
149-
host.runQueuedTimeoutCallbacks();
149+
projectService.runQueuedTimeoutCallbacks();
150150
logSemanticDiagnostics(projectService, project, root);
151151
logCacheAndClear(projectService.logger);
152152
baselineTsserverLogs("cachingFileSystemInformation", "loads missing files from disk", projectService);
@@ -280,7 +280,7 @@ namespace ts.projectSystem {
280280

281281
// Create file cookie.ts
282282
host.writeFile(file3.path, file3.content);
283-
host.runQueuedTimeoutCallbacks();
283+
projectService.runQueuedTimeoutCallbacks();
284284
logCacheAndClear(projectService.logger);
285285

286286
projectService.openClientFile(file3.path);
@@ -479,15 +479,15 @@ namespace ts.projectSystem {
479479
if (npmInstallComplete || timeoutDuringPartialInstallation) {
480480
if (timeoutQueueLengthWhenRunningTimeouts) {
481481
// Expected project update
482-
host.checkTimeoutQueueLengthAndRun(timeoutQueueLengthWhenRunningTimeouts + 1); // Scheduled invalidation of resolutions
483-
host.runQueuedTimeoutCallbacks(); // Actual update
482+
projectService.checkTimeoutQueueLengthAndRun(timeoutQueueLengthWhenRunningTimeouts + 1); // Scheduled invalidation of resolutions
483+
projectService.runQueuedTimeoutCallbacks(); // Actual update
484484
}
485485
else {
486-
host.checkTimeoutQueueLengthAndRun(timeoutQueueLengthWhenRunningTimeouts);
486+
projectService.checkTimeoutQueueLengthAndRun(timeoutQueueLengthWhenRunningTimeouts);
487487
}
488488
}
489489
else {
490-
host.checkTimeoutQueueLength(3);
490+
projectService.checkTimeoutQueueLength(3);
491491
}
492492
}
493493
}

src/testRunner/unittests/tsserver/configFileSearch.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ namespace ts.projectSystem {
4343

4444
// Delete config file - should create inferred project and not configured project
4545
host.deleteFile(configFile.path);
46-
host.runQueuedTimeoutCallbacks();
46+
service.runQueuedTimeoutCallbacks();
4747
checkNumberOfProjects(service, { inferredProjects: 1 });
4848
baselineTsserverLogs("configFileSearch", "should use projectRootPath when searching for inferred project again", service);
4949
});
@@ -73,7 +73,7 @@ namespace ts.projectSystem {
7373

7474
// Delete config file - should create inferred project with project root path set
7575
host.deleteFile(configFile.path);
76-
host.runQueuedTimeoutCallbacks();
76+
service.runQueuedTimeoutCallbacks();
7777
baselineTsserverLogs("configFileSearch", "should use projectRootPath when searching for inferred project again 2", service);
7878
});
7979

@@ -98,10 +98,10 @@ namespace ts.projectSystem {
9898
const { host, projectService } = openClientFile([file, libFile, tsconfig]);
9999

100100
host.deleteFile(tsconfig.path);
101-
host.runQueuedTimeoutCallbacks();
101+
projectService.runQueuedTimeoutCallbacks();
102102

103103
host.writeFile(tsconfig.path, tsconfig.content);
104-
host.runQueuedTimeoutCallbacks();
104+
projectService.runQueuedTimeoutCallbacks();
105105

106106
baselineTsserverLogs("configFileSearch", "tsconfig for the file exists", projectService);
107107
});
@@ -110,10 +110,10 @@ namespace ts.projectSystem {
110110
const { host, projectService } = openClientFile([file, libFile]);
111111

112112
host.writeFile(tsconfig.path, tsconfig.content);
113-
host.runQueuedTimeoutCallbacks();
113+
projectService.runQueuedTimeoutCallbacks();
114114

115115
host.deleteFile(tsconfig.path);
116-
host.runQueuedTimeoutCallbacks();
116+
projectService.runQueuedTimeoutCallbacks();
117117

118118
baselineTsserverLogs("configFileSearch", "tsconfig for the file does not exist", projectService);
119119
});

src/testRunner/unittests/tsserver/configuredProjects.ts

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -90,11 +90,11 @@ namespace ts.projectSystem {
9090

9191
// Add a tsconfig file
9292
host.writeFile(configFile.path, configFile.content);
93-
host.checkTimeoutQueueLengthAndRun(2); // load configured project from disk + ensureProjectsForOpenFiles
93+
projectService.checkTimeoutQueueLengthAndRun(2); // load configured project from disk + ensureProjectsForOpenFiles
9494

9595
// remove the tsconfig file
9696
host.deleteFile(configFile.path);
97-
host.checkTimeoutQueueLengthAndRun(1); // Refresh inferred projects
97+
projectService.checkTimeoutQueueLengthAndRun(1); // Refresh inferred projects
9898

9999
baselineTsserverLogs("configuredProjects", "add and then remove a config file in a folder with loose files", projectService);
100100
});
@@ -110,7 +110,7 @@ namespace ts.projectSystem {
110110

111111
// add a new ts file
112112
host.writeFile(commonFile2.path, commonFile2.content);
113-
host.checkTimeoutQueueLengthAndRun(2);
113+
projectService.checkTimeoutQueueLengthAndRun(2);
114114
baselineTsserverLogs("configuredProjects", "add new files to a configured project without file list", projectService);
115115
});
116116

@@ -548,7 +548,7 @@ namespace ts.projectSystem {
548548
assert.isTrue(configProject1.hasOpenRef()); // file1 and file3
549549

550550
host.writeFile(configFile.path, "{}");
551-
host.runQueuedTimeoutCallbacks();
551+
projectService.runQueuedTimeoutCallbacks();
552552

553553
assert.isTrue(configProject1.hasOpenRef()); // file1, file2, file3
554554
assert.isTrue(projectService.inferredProjects[0].isOrphan());
@@ -577,6 +577,7 @@ namespace ts.projectSystem {
577577
content: "let zz = 1;"
578578
};
579579
host.writeFile(file5.path, file5.content);
580+
projectService.baselineHost("File5 written");
580581
projectService.openClientFile(file5.path);
581582

582583
baselineTsserverLogs("configuredProjects", "Open ref of configured project when open file gets added to the project as part of configured file update", projectService);
@@ -1032,23 +1033,23 @@ foo();`
10321033
strict: true
10331034
}
10341035
}));
1035-
host.checkTimeoutQueueLengthAndRun(3);
1036+
projectService.checkTimeoutQueueLengthAndRun(3);
10361037

10371038
host.writeFile(bravoExtendedConfig.path, JSON.stringify({
10381039
extends: "./alpha.tsconfig.json",
10391040
compilerOptions: {
10401041
strict: false
10411042
}
10421043
}));
1043-
host.checkTimeoutQueueLengthAndRun(2);
1044+
projectService.checkTimeoutQueueLengthAndRun(2);
10441045

10451046
host.writeFile(bConfig.path, JSON.stringify({
10461047
extends: "../extended/alpha.tsconfig.json",
10471048
}));
1048-
host.checkTimeoutQueueLengthAndRun(2);
1049+
projectService.checkTimeoutQueueLengthAndRun(2);
10491050

10501051
host.writeFile(alphaExtendedConfig.path, "{}");
1051-
host.checkTimeoutQueueLengthAndRun(3);
1052+
projectService.checkTimeoutQueueLengthAndRun(3);
10521053
baselineTsserverLogs("configuredProjects", "should watch the extended configs of multiple projects", projectService);
10531054
});
10541055

@@ -1182,8 +1183,8 @@ foo();`
11821183
projectService.openClientFile(file1.path);
11831184

11841185
host.writeFile(file2.path, file2.content);
1185-
host.runQueuedTimeoutCallbacks(); // Scheduled invalidation of resolutions
1186-
host.runQueuedTimeoutCallbacks(); // Actual update
1186+
projectService.runQueuedTimeoutCallbacks(); // Scheduled invalidation of resolutions
1187+
projectService.runQueuedTimeoutCallbacks(); // Actual update
11871188

11881189
// On next file open the files file2a should be closed and not watched any more
11891190
projectService.openClientFile(file2.path);

src/testRunner/unittests/tsserver/events/projectUpdatedInBackground.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -442,7 +442,7 @@ namespace ts.projectSystem {
442442

443443
file3.content += "export class d {}";
444444
host.writeFile(file3.path, file3.content);
445-
host.checkTimeoutQueueLengthAndRun(2);
445+
session.checkTimeoutQueueLengthAndRun(2);
446446

447447
// Since this is first event
448448
verifyProjectsUpdatedInBackgroundEventHandler([{
@@ -453,8 +453,8 @@ namespace ts.projectSystem {
453453
}]);
454454

455455
host.writeFile(file2.path, file2.content);
456-
host.runQueuedTimeoutCallbacks(); // For invalidation
457-
host.runQueuedTimeoutCallbacks(); // For actual update
456+
session.runQueuedTimeoutCallbacks(); // For invalidation
457+
session.runQueuedTimeoutCallbacks(); // For actual update
458458

459459
verifyProjectsUpdatedInBackgroundEventHandler(useSlashRootAsSomeNotRootFolderInUserDirectory ? [{
460460
eventName: server.ProjectsUpdatedInBackgroundEvent,

src/testRunner/unittests/tsserver/helpers.ts

Lines changed: 72 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ namespace ts.projectSystem {
142142
.replace(/getExportInfoMap: done in \d+(?:\.\d+)?/g, `getExportInfoMap: done in *`)
143143
.replace(/collectAutoImports: \d+(?:\.\d+)?/g, `collectAutoImports: *`)
144144
.replace(/dependencies in \d+(?:\.\d+)?/g, `dependencies in *`)
145-
.replace(/\"exportMapKey\"\:\"[_$a-zA-Z][_$_$a-zA-Z0-9]*\|\d+\|/g, match => match.replace(/\|\d+\|/, `|*|`))
145+
.replace(/\"exportMapKey\"\:\s*\"[_$a-zA-Z][_$_$a-zA-Z0-9]*\|\d+\|/g, match => match.replace(/\|\d+\|/, `|*|`))
146146
)
147147
}, host);
148148
}
@@ -395,15 +395,41 @@ namespace ts.projectSystem {
395395
private baseline<T extends protocol.Request | server.HandlerResponse>(type: "request" | "response", requestOrResult: T): T {
396396
if (!this.logger.hasLevel(server.LogLevel.verbose)) return requestOrResult;
397397
if (type === "request") this.logger.info(`request:${server.indent(JSON.stringify(requestOrResult, undefined, 2))}`);
398-
this.baselineHost();
398+
this.baselineHost(type === "request" ? "Before request" : "After request");
399399
if (type === "response") this.logger.info(`response:${server.indent(JSON.stringify(requestOrResult, undefined, 2))}`);
400400
return requestOrResult;
401401
}
402402

403-
baselineHost() {
403+
baselineHost(title: string) {
404+
if (!this.logger.hasLevel(server.LogLevel.verbose)) return;
405+
this.logger.logs.push(title);
404406
this.testhost.diff(this.logger.logs, this.hostDiff);
405407
this.testhost.serializeWatches(this.logger.logs);
406408
this.hostDiff = this.testhost.snap();
409+
this.testhost.writtenFiles.clear();
410+
}
411+
412+
checkTimeoutQueueLengthAndRun(expected: number) {
413+
this.baselineHost(`Before checking timeout queue length (${expected}) and running`);
414+
this.testhost.checkTimeoutQueueLengthAndRun(expected);
415+
this.baselineHost(`After checking timeout queue length (${expected}) and running`);
416+
}
417+
418+
checkTimeoutQueueLength(expected: number) {
419+
this.baselineHost(`Checking timeout queue length: ${expected}`);
420+
this.testhost.checkTimeoutQueueLength(expected);
421+
}
422+
423+
runQueuedTimeoutCallbacks(timeoutId?: number) {
424+
this.baselineHost(`Before running timeout callback${timeoutId === undefined ? "s" : timeoutId}`);
425+
this.testhost.runQueuedTimeoutCallbacks(timeoutId);
426+
this.baselineHost(`After running timeout callback${timeoutId === undefined ? "s" : timeoutId}`);
427+
}
428+
429+
runQueuedImmediateCallbacks(checkCount?: number) {
430+
this.baselineHost(`Before running immediate callbacks${checkCount === undefined ? "" : ` and checking length (${checkCount})`}`);
431+
this.testhost.runQueuedImmediateCallbacks(checkCount);
432+
this.baselineHost(`Before running immediate callbacks${checkCount === undefined ? "" : ` and checking length (${checkCount})`}`);
407433
}
408434
}
409435

@@ -471,7 +497,9 @@ namespace ts.projectSystem {
471497
}
472498

473499
export class TestProjectService extends server.ProjectService {
474-
constructor(host: server.ServerHost, public logger: Logger, cancellationToken: HostCancellationToken, useSingleInferredProject: boolean,
500+
public testhost: TestFSWithWatch.TestServerHostTrackingWrittenFiles;
501+
private hostDiff: ReturnType<TestServerHost["snap"]> | undefined;
502+
constructor(host: TestServerHost, public logger: Logger, cancellationToken: HostCancellationToken, useSingleInferredProject: boolean,
475503
typingsInstaller: server.ITypingsInstaller, opts: Partial<TestProjectServiceOptions> = {}) {
476504
super({
477505
host,
@@ -484,14 +512,48 @@ namespace ts.projectSystem {
484512
typesMapLocation: customTypesMap.path,
485513
...opts
486514
});
515+
this.testhost = TestFSWithWatch.changeToHostTrackingWrittenFiles(this.host as TestServerHost);
516+
this.baselineHost("Creating project service");
487517
}
488518

489519
checkNumberOfProjects(count: { inferredProjects?: number, configuredProjects?: number, externalProjects?: number }) {
490520
checkNumberOfProjects(this, count);
491521
}
522+
523+
baselineHost(title: string) {
524+
if (!this.logger.hasLevel(server.LogLevel.verbose)) return;
525+
this.logger.logs.push(title);
526+
this.testhost.diff(this.logger.logs, this.hostDiff);
527+
this.testhost.serializeWatches(this.logger.logs);
528+
this.hostDiff = this.testhost.snap();
529+
this.testhost.writtenFiles.clear();
530+
}
531+
532+
checkTimeoutQueueLengthAndRun(expected: number) {
533+
this.baselineHost(`Before checking timeout queue length (${expected}) and running`);
534+
this.testhost.checkTimeoutQueueLengthAndRun(expected);
535+
this.baselineHost(`After checking timeout queue length (${expected}) and running`);
536+
}
537+
538+
checkTimeoutQueueLength(expected: number) {
539+
this.baselineHost(`Checking timeout queue length: ${expected}`);
540+
this.testhost.checkTimeoutQueueLength(expected);
541+
}
542+
543+
runQueuedTimeoutCallbacks(timeoutId?: number) {
544+
this.baselineHost(`Before running timeout callback${timeoutId === undefined ? "s" : timeoutId}`);
545+
this.testhost.runQueuedTimeoutCallbacks(timeoutId);
546+
this.baselineHost(`After running timeout callback${timeoutId === undefined ? "s" : timeoutId}`);
547+
}
548+
549+
runQueuedImmediateCallbacks(checkCount?: number) {
550+
this.baselineHost(`Before running immediate callbacks${checkCount === undefined ? "" : ` and checking length (${checkCount})`}`);
551+
this.testhost.runQueuedImmediateCallbacks(checkCount);
552+
this.baselineHost(`Before running immediate callbacks${checkCount === undefined ? "" : ` and checking length (${checkCount})`}`);
553+
}
492554
}
493555

494-
export function createProjectService(host: server.ServerHost, options?: Partial<TestProjectServiceOptions>) {
556+
export function createProjectService(host: TestServerHost, options?: Partial<TestProjectServiceOptions>) {
495557
const cancellationToken = options?.cancellationToken || server.nullCancellationToken;
496558
const logger = options?.logger || createHasErrorMessageLogger();
497559
const useSingleInferredProject = options?.useSingleInferredProject !== undefined ? options.useSingleInferredProject : false;
@@ -792,14 +854,14 @@ namespace ts.projectSystem {
792854
Debug.assert(session.logger.logs.length);
793855
for (let i = 0; i < files.length; i++) {
794856
if (existingTimeouts !== undefined) {
795-
host.checkTimeoutQueueLength(existingTimeouts + 1);
796-
host.runQueuedTimeoutCallbacks(host.getNextTimeoutId() - 1);
857+
session.checkTimeoutQueueLength(existingTimeouts + 1);
858+
session.runQueuedTimeoutCallbacks(host.getNextTimeoutId() - 1);
797859
}
798860
else {
799-
host.checkTimeoutQueueLengthAndRun(1);
861+
session.checkTimeoutQueueLengthAndRun(1);
800862
}
801-
if (!skip?.[i]?.semantic) host.runQueuedImmediateCallbacks(1);
802-
if (!skip?.[i]?.suggestion) host.runQueuedImmediateCallbacks(1);
863+
if (!skip?.[i]?.semantic) session.runQueuedImmediateCallbacks(1);
864+
if (!skip?.[i]?.suggestion) session.runQueuedImmediateCallbacks(1);
803865
}
804866
}
805867

0 commit comments

Comments
 (0)