Skip to content

Commit d2516fa

Browse files
authored
Tsserver tests can be baselined (#44326)
* Tests to baseline tsserver instead of checking Also ensures inferred and auto import projects have name per project service * Log structureIsReused value * more baselines
1 parent 9c50cb9 commit d2516fa

File tree

129 files changed

+20178
-2226
lines changed

Some content is hidden

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

129 files changed

+20178
-2226
lines changed

src/server/editorServices.ts

+9
Original file line numberDiff line numberDiff line change
@@ -658,6 +658,11 @@ namespace ts.server {
658658
reloadLevel?: ConfigFileProgramReloadLevel.Partial | ConfigFileProgramReloadLevel.Full;
659659
}
660660

661+
function createProjectNameFactoryWithCounter(nameFactory: (counter: number) => string) {
662+
let nextId = 1;
663+
return () => nameFactory(nextId++);
664+
}
665+
661666
export class ProjectService {
662667

663668
/*@internal*/
@@ -703,6 +708,10 @@ namespace ts.server {
703708
* projects specified by a tsconfig.json file
704709
*/
705710
readonly configuredProjects: Map<ConfiguredProject> = new Map<string, ConfiguredProject>();
711+
/*@internal*/
712+
readonly newInferredProjectName = createProjectNameFactoryWithCounter(makeInferredProjectName);
713+
/*@internal*/
714+
readonly newAutoImportProviderProjectName = createProjectNameFactoryWithCounter(makeAutoImportProviderProjectName);
706715
/**
707716
* Open files: with value being project root path, and key being Path of the file that is open
708717
*/

src/server/project.ts

+4-13
Original file line numberDiff line numberDiff line change
@@ -1225,12 +1225,12 @@ namespace ts.server {
12251225
);
12261226
const elapsed = timestamp() - start;
12271227
this.sendPerformanceEvent("UpdateGraph", elapsed);
1228-
this.writeLog(`Finishing updateGraphWorker: Project: ${this.getProjectName()} Version: ${this.getProjectVersion()} structureChanged: ${hasNewProgram} Elapsed: ${elapsed}ms`);
1228+
this.writeLog(`Finishing updateGraphWorker: Project: ${this.getProjectName()} Version: ${this.getProjectVersion()} structureChanged: ${hasNewProgram}${this.program ? ` structureIsReused:: ${(ts as any).StructureIsReused[this.program.structureIsReused]}` : ""} Elapsed: ${elapsed}ms`);
12291229
if (this.hasAddedorRemovedFiles) {
12301230
this.print(/*writeProjectFileNames*/ true);
12311231
}
12321232
else if (this.program !== oldProgram) {
1233-
this.writeLog(`Different program with same set of files:: structureIsReused:: ${this.program?.structureIsReused}`);
1233+
this.writeLog(`Different program with same set of files`);
12341234
}
12351235
return hasNewProgram;
12361236
}
@@ -1753,18 +1753,11 @@ namespace ts.server {
17531753
});
17541754
}
17551755

1756-
function createProjectNameFactoryWithCounter(nameFactory: (counter: number) => string) {
1757-
let nextId = 1;
1758-
return () => nameFactory(nextId++);
1759-
}
1760-
17611756
/**
17621757
* If a file is opened and no tsconfig (or jsconfig) is found,
17631758
* the file and its imports/references are put into an InferredProject.
17641759
*/
17651760
export class InferredProject extends Project {
1766-
private static readonly newName = createProjectNameFactoryWithCounter(makeInferredProjectName);
1767-
17681761
private _isJsInferredProject = false;
17691762

17701763
toggleJsInferredProject(isJsInferredProject: boolean) {
@@ -1807,7 +1800,7 @@ namespace ts.server {
18071800
currentDirectory: string | undefined,
18081801
pluginConfigOverrides: ESMap<string, any> | undefined,
18091802
typeAcquisition: TypeAcquisition | undefined) {
1810-
super(InferredProject.newName(),
1803+
super(projectService.newInferredProjectName(),
18111804
ProjectKind.Inferred,
18121805
projectService,
18131806
documentRegistry,
@@ -1874,8 +1867,6 @@ namespace ts.server {
18741867
}
18751868

18761869
export class AutoImportProviderProject extends Project {
1877-
private static readonly newName = createProjectNameFactoryWithCounter(makeAutoImportProviderProjectName);
1878-
18791870
/*@internal*/
18801871
private static readonly maxDependencies = 10;
18811872

@@ -1966,7 +1957,7 @@ namespace ts.server {
19661957
documentRegistry: DocumentRegistry,
19671958
compilerOptions: CompilerOptions,
19681959
) {
1969-
super(AutoImportProviderProject.newName(),
1960+
super(hostProject.projectService.newAutoImportProviderProjectName(),
19701961
ProjectKind.AutoImportProvider,
19711962
hostProject.projectService,
19721963
documentRegistry,

src/testRunner/unittests/tsserver/compileOnSave.ts

+16-33
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
namespace ts.projectSystem {
22
import CommandNames = server.CommandNames;
3-
const nullCancellationToken = server.nullCancellationToken;
4-
53
function createTestTypingsInstaller(host: server.ServerHost) {
64
return new TestTypingsInstaller("/a/data/", /*throttleLimit*/5, host);
75
}
@@ -27,21 +25,6 @@ namespace ts.projectSystem {
2725
}
2826
}
2927

30-
function createSession(host: server.ServerHost, typingsInstaller?: server.ITypingsInstaller): server.Session {
31-
const opts: server.SessionOptions = {
32-
host,
33-
cancellationToken: nullCancellationToken,
34-
useSingleInferredProject: false,
35-
useInferredProjectPerProjectRoot: false,
36-
typingsInstaller: typingsInstaller || server.nullTypingsInstaller,
37-
byteLength: Utils.byteLength,
38-
hrtime: process.hrtime,
39-
logger: createHasErrorMessageLogger().logger,
40-
canUseEvents: false
41-
};
42-
return new server.Session(opts);
43-
}
44-
4528
describe("for configured projects", () => {
4629
let moduleFile1: File;
4730
let file1Consumer1: File;
@@ -113,7 +96,7 @@ namespace ts.projectSystem {
11396
it("should contains only itself if a module file's shape didn't change, and all files referencing it if its shape changed", () => {
11497
const host = createServerHost([moduleFile1, file1Consumer1, file1Consumer2, globalFile3, moduleFile2, configFile, libFile]);
11598
const typingsInstaller = createTestTypingsInstaller(host);
116-
const session = createSession(host, typingsInstaller);
99+
const session = createSession(host, { typingsInstaller });
117100

118101
openFilesForSession([moduleFile1, file1Consumer1], session);
119102

@@ -138,7 +121,7 @@ namespace ts.projectSystem {
138121
it("should be up-to-date with the reference map changes", () => {
139122
const host = createServerHost([moduleFile1, file1Consumer1, file1Consumer2, globalFile3, moduleFile2, configFile, libFile]);
140123
const typingsInstaller = createTestTypingsInstaller(host);
141-
const session = createSession(host, typingsInstaller);
124+
const session = createSession(host, { typingsInstaller });
142125

143126
openFilesForSession([moduleFile1, file1Consumer1], session);
144127

@@ -185,7 +168,7 @@ namespace ts.projectSystem {
185168
it("should be up-to-date with changes made in non-open files", () => {
186169
const host = createServerHost([moduleFile1, file1Consumer1, file1Consumer2, globalFile3, moduleFile2, configFile, libFile]);
187170
const typingsInstaller = createTestTypingsInstaller(host);
188-
const session = createSession(host, typingsInstaller);
171+
const session = createSession(host, { typingsInstaller });
189172

190173
openFilesForSession([moduleFile1], session);
191174

@@ -201,7 +184,7 @@ namespace ts.projectSystem {
201184
it("should be up-to-date with deleted files", () => {
202185
const host = createServerHost([moduleFile1, file1Consumer1, file1Consumer2, globalFile3, moduleFile2, configFile, libFile]);
203186
const typingsInstaller = createTestTypingsInstaller(host);
204-
const session = createSession(host, typingsInstaller);
187+
const session = createSession(host, { typingsInstaller });
205188

206189
openFilesForSession([moduleFile1], session);
207190
sendAffectedFileRequestAndCheckResult(session, moduleFile1FileListRequest, [{ projectFileName: configFile.path, files: [moduleFile1, file1Consumer1, file1Consumer2] }]);
@@ -215,7 +198,7 @@ namespace ts.projectSystem {
215198
it("should be up-to-date with newly created files", () => {
216199
const host = createServerHost([moduleFile1, file1Consumer1, file1Consumer2, globalFile3, moduleFile2, configFile, libFile]);
217200
const typingsInstaller = createTestTypingsInstaller(host);
218-
const session = createSession(host, typingsInstaller);
201+
const session = createSession(host, { typingsInstaller });
219202

220203
openFilesForSession([moduleFile1], session);
221204
sendAffectedFileRequestAndCheckResult(session, moduleFile1FileListRequest, [{ projectFileName: configFile.path, files: [moduleFile1, file1Consumer1, file1Consumer2] }]);
@@ -251,7 +234,7 @@ namespace ts.projectSystem {
251234

252235
const host = createServerHost([moduleFile1, file1Consumer1, configFile, libFile]);
253236
const typingsInstaller = createTestTypingsInstaller(host);
254-
const session = createSession(host, typingsInstaller);
237+
const session = createSession(host, { typingsInstaller });
255238

256239
openFilesForSession([moduleFile1, file1Consumer1], session);
257240
sendAffectedFileRequestAndCheckResult(session, moduleFile1FileListRequest, [{ projectFileName: configFile.path, files: [moduleFile1, file1Consumer1] }]);
@@ -268,7 +251,7 @@ namespace ts.projectSystem {
268251
it("should return all files if a global file changed shape", () => {
269252
const host = createServerHost([moduleFile1, file1Consumer1, file1Consumer2, globalFile3, moduleFile2, configFile, libFile]);
270253
const typingsInstaller = createTestTypingsInstaller(host);
271-
const session = createSession(host, typingsInstaller);
254+
const session = createSession(host, { typingsInstaller });
272255

273256
openFilesForSession([globalFile3], session);
274257
const changeGlobalFile3ShapeRequest = makeSessionRequest<server.protocol.ChangeRequestArgs>(CommandNames.Change, {
@@ -294,7 +277,7 @@ namespace ts.projectSystem {
294277

295278
const host = createServerHost([moduleFile1, file1Consumer1, file1Consumer2, configFile, libFile]);
296279
const typingsInstaller = createTestTypingsInstaller(host);
297-
const session = createSession(host, typingsInstaller);
280+
const session = createSession(host, { typingsInstaller });
298281
openFilesForSession([moduleFile1], session);
299282
sendAffectedFileRequestAndCheckResult(session, moduleFile1FileListRequest, []);
300283
});
@@ -312,7 +295,7 @@ namespace ts.projectSystem {
312295

313296
const host = createServerHost([moduleFile1, file1Consumer1, file1Consumer2, configFile, libFile]);
314297
const typingsInstaller = createTestTypingsInstaller(host);
315-
const session = createSession(host, typingsInstaller);
298+
const session = createSession(host, { typingsInstaller });
316299
openFilesForSession([moduleFile1], session);
317300
sendAffectedFileRequestAndCheckResult(session, moduleFile1FileListRequest, []);
318301
});
@@ -334,7 +317,7 @@ namespace ts.projectSystem {
334317

335318
const host = createServerHost([moduleFile1, file1Consumer1, file1Consumer2, configFile2, configFile, libFile]);
336319
const typingsInstaller = createTestTypingsInstaller(host);
337-
const session = createSession(host, typingsInstaller);
320+
const session = createSession(host, { typingsInstaller });
338321

339322
openFilesForSession([moduleFile1, file1Consumer1], session);
340323
sendAffectedFileRequestAndCheckResult(session, moduleFile1FileListRequest, [{ projectFileName: configFile.path, files: [moduleFile1, file1Consumer1, file1Consumer2] }]);
@@ -353,7 +336,7 @@ namespace ts.projectSystem {
353336

354337
const host = createServerHost([moduleFile1, file1Consumer1, configFile, libFile]);
355338
const typingsInstaller = createTestTypingsInstaller(host);
356-
const session = createSession(host, typingsInstaller);
339+
const session = createSession(host, { typingsInstaller });
357340
openFilesForSession([moduleFile1], session);
358341

359342
const file1ChangeShapeRequest = makeSessionRequest<server.protocol.ChangeRequestArgs>(CommandNames.Change, {
@@ -382,7 +365,7 @@ namespace ts.projectSystem {
382365

383366
const host = createServerHost([moduleFile1, file1Consumer1, configFile, libFile]);
384367
const typingsInstaller = createTestTypingsInstaller(host);
385-
const session = createSession(host, typingsInstaller);
368+
const session = createSession(host, { typingsInstaller });
386369
openFilesForSession([moduleFile1], session);
387370

388371
const file1ChangeShapeRequest = makeSessionRequest<server.protocol.ChangeRequestArgs>(CommandNames.Change, {
@@ -404,7 +387,7 @@ namespace ts.projectSystem {
404387
};
405388
const host = createServerHost([moduleFile1, file1Consumer1, file1Consumer1Consumer1, globalFile3, configFile, libFile]);
406389
const typingsInstaller = createTestTypingsInstaller(host);
407-
const session = createSession(host, typingsInstaller);
390+
const session = createSession(host, { typingsInstaller });
408391

409392
openFilesForSession([moduleFile1, file1Consumer1], session);
410393
sendAffectedFileRequestAndCheckResult(session, moduleFile1FileListRequest, [{ projectFileName: configFile.path, files: [moduleFile1, file1Consumer1, file1Consumer1Consumer1] }]);
@@ -437,7 +420,7 @@ namespace ts.projectSystem {
437420
};
438421
const host = createServerHost([file1, file2, configFile]);
439422
const typingsInstaller = createTestTypingsInstaller(host);
440-
const session = createSession(host, typingsInstaller);
423+
const session = createSession(host, { typingsInstaller });
441424

442425
openFilesForSession([file1, file2], session);
443426
const file1AffectedListRequest = makeSessionRequest<server.protocol.FileRequestArgs>(CommandNames.CompileOnSaveAffectedFileList, { file: file1.path });
@@ -520,7 +503,7 @@ namespace ts.projectSystem {
520503
})
521504
};
522505
const host = createServerHost([dtsFile, f2, config]);
523-
const session = projectSystem.createSession(host);
506+
const session = createSession(host);
524507
session.executeCommand({
525508
seq: 1,
526509
type: "request",
@@ -626,7 +609,7 @@ namespace ts.projectSystem {
626609
})
627610
};
628611
const host = createServerHost([f1, f2, config]);
629-
const session = projectSystem.createSession(host);
612+
const session = createSession(host);
630613
session.executeCommand({
631614
seq: 1,
632615
type: "request",

0 commit comments

Comments
 (0)