Skip to content

Tsserver tests can be baselined #44326

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Jun 2, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions src/server/editorServices.ts
Original file line number Diff line number Diff line change
Expand Up @@ -658,6 +658,11 @@ namespace ts.server {
reloadLevel?: ConfigFileProgramReloadLevel.Partial | ConfigFileProgramReloadLevel.Full;
}

function createProjectNameFactoryWithCounter(nameFactory: (counter: number) => string) {
let nextId = 1;
return () => nameFactory(nextId++);
}

export class ProjectService {

/*@internal*/
Expand Down Expand Up @@ -703,6 +708,10 @@ namespace ts.server {
* projects specified by a tsconfig.json file
*/
readonly configuredProjects: Map<ConfiguredProject> = new Map<string, ConfiguredProject>();
/*@internal*/
readonly newInferredProjectName = createProjectNameFactoryWithCounter(makeInferredProjectName);
/*@internal*/
readonly newAutoImportProviderProjectName = createProjectNameFactoryWithCounter(makeAutoImportProviderProjectName);
/**
* Open files: with value being project root path, and key being Path of the file that is open
*/
Expand Down
17 changes: 4 additions & 13 deletions src/server/project.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1225,12 +1225,12 @@ namespace ts.server {
);
const elapsed = timestamp() - start;
this.sendPerformanceEvent("UpdateGraph", elapsed);
this.writeLog(`Finishing updateGraphWorker: Project: ${this.getProjectName()} Version: ${this.getProjectVersion()} structureChanged: ${hasNewProgram} Elapsed: ${elapsed}ms`);
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`);
if (this.hasAddedorRemovedFiles) {
this.print(/*writeProjectFileNames*/ true);
}
else if (this.program !== oldProgram) {
this.writeLog(`Different program with same set of files:: structureIsReused:: ${this.program?.structureIsReused}`);
this.writeLog(`Different program with same set of files`);
}
return hasNewProgram;
}
Expand Down Expand Up @@ -1753,18 +1753,11 @@ namespace ts.server {
});
}

function createProjectNameFactoryWithCounter(nameFactory: (counter: number) => string) {
let nextId = 1;
return () => nameFactory(nextId++);
}

/**
* If a file is opened and no tsconfig (or jsconfig) is found,
* the file and its imports/references are put into an InferredProject.
*/
export class InferredProject extends Project {
private static readonly newName = createProjectNameFactoryWithCounter(makeInferredProjectName);

private _isJsInferredProject = false;

toggleJsInferredProject(isJsInferredProject: boolean) {
Expand Down Expand Up @@ -1807,7 +1800,7 @@ namespace ts.server {
currentDirectory: string | undefined,
pluginConfigOverrides: ESMap<string, any> | undefined,
typeAcquisition: TypeAcquisition | undefined) {
super(InferredProject.newName(),
super(projectService.newInferredProjectName(),
ProjectKind.Inferred,
projectService,
documentRegistry,
Expand Down Expand Up @@ -1874,8 +1867,6 @@ namespace ts.server {
}

export class AutoImportProviderProject extends Project {
private static readonly newName = createProjectNameFactoryWithCounter(makeAutoImportProviderProjectName);

/*@internal*/
private static readonly maxDependencies = 10;

Expand Down Expand Up @@ -1966,7 +1957,7 @@ namespace ts.server {
documentRegistry: DocumentRegistry,
compilerOptions: CompilerOptions,
) {
super(AutoImportProviderProject.newName(),
super(hostProject.projectService.newAutoImportProviderProjectName(),
ProjectKind.AutoImportProvider,
hostProject.projectService,
documentRegistry,
Expand Down
49 changes: 16 additions & 33 deletions src/testRunner/unittests/tsserver/compileOnSave.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
namespace ts.projectSystem {
import CommandNames = server.CommandNames;
const nullCancellationToken = server.nullCancellationToken;

function createTestTypingsInstaller(host: server.ServerHost) {
return new TestTypingsInstaller("/a/data/", /*throttleLimit*/5, host);
}
Expand All @@ -27,21 +25,6 @@ namespace ts.projectSystem {
}
}

function createSession(host: server.ServerHost, typingsInstaller?: server.ITypingsInstaller): server.Session {
const opts: server.SessionOptions = {
host,
cancellationToken: nullCancellationToken,
useSingleInferredProject: false,
useInferredProjectPerProjectRoot: false,
typingsInstaller: typingsInstaller || server.nullTypingsInstaller,
byteLength: Utils.byteLength,
hrtime: process.hrtime,
logger: createHasErrorMessageLogger().logger,
canUseEvents: false
};
return new server.Session(opts);
}

describe("for configured projects", () => {
let moduleFile1: File;
let file1Consumer1: File;
Expand Down Expand Up @@ -113,7 +96,7 @@ namespace ts.projectSystem {
it("should contains only itself if a module file's shape didn't change, and all files referencing it if its shape changed", () => {
const host = createServerHost([moduleFile1, file1Consumer1, file1Consumer2, globalFile3, moduleFile2, configFile, libFile]);
const typingsInstaller = createTestTypingsInstaller(host);
const session = createSession(host, typingsInstaller);
const session = createSession(host, { typingsInstaller });

openFilesForSession([moduleFile1, file1Consumer1], session);

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

openFilesForSession([moduleFile1, file1Consumer1], session);

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

openFilesForSession([moduleFile1], session);

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

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

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

const host = createServerHost([moduleFile1, file1Consumer1, configFile, libFile]);
const typingsInstaller = createTestTypingsInstaller(host);
const session = createSession(host, typingsInstaller);
const session = createSession(host, { typingsInstaller });

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

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

const host = createServerHost([moduleFile1, file1Consumer1, file1Consumer2, configFile, libFile]);
const typingsInstaller = createTestTypingsInstaller(host);
const session = createSession(host, typingsInstaller);
const session = createSession(host, { typingsInstaller });
openFilesForSession([moduleFile1], session);
sendAffectedFileRequestAndCheckResult(session, moduleFile1FileListRequest, []);
});
Expand All @@ -312,7 +295,7 @@ namespace ts.projectSystem {

const host = createServerHost([moduleFile1, file1Consumer1, file1Consumer2, configFile, libFile]);
const typingsInstaller = createTestTypingsInstaller(host);
const session = createSession(host, typingsInstaller);
const session = createSession(host, { typingsInstaller });
openFilesForSession([moduleFile1], session);
sendAffectedFileRequestAndCheckResult(session, moduleFile1FileListRequest, []);
});
Expand All @@ -334,7 +317,7 @@ namespace ts.projectSystem {

const host = createServerHost([moduleFile1, file1Consumer1, file1Consumer2, configFile2, configFile, libFile]);
const typingsInstaller = createTestTypingsInstaller(host);
const session = createSession(host, typingsInstaller);
const session = createSession(host, { typingsInstaller });

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

const host = createServerHost([moduleFile1, file1Consumer1, configFile, libFile]);
const typingsInstaller = createTestTypingsInstaller(host);
const session = createSession(host, typingsInstaller);
const session = createSession(host, { typingsInstaller });
openFilesForSession([moduleFile1], session);

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

const host = createServerHost([moduleFile1, file1Consumer1, configFile, libFile]);
const typingsInstaller = createTestTypingsInstaller(host);
const session = createSession(host, typingsInstaller);
const session = createSession(host, { typingsInstaller });
openFilesForSession([moduleFile1], session);

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

openFilesForSession([moduleFile1, file1Consumer1], session);
sendAffectedFileRequestAndCheckResult(session, moduleFile1FileListRequest, [{ projectFileName: configFile.path, files: [moduleFile1, file1Consumer1, file1Consumer1Consumer1] }]);
Expand Down Expand Up @@ -437,7 +420,7 @@ namespace ts.projectSystem {
};
const host = createServerHost([file1, file2, configFile]);
const typingsInstaller = createTestTypingsInstaller(host);
const session = createSession(host, typingsInstaller);
const session = createSession(host, { typingsInstaller });

openFilesForSession([file1, file2], session);
const file1AffectedListRequest = makeSessionRequest<server.protocol.FileRequestArgs>(CommandNames.CompileOnSaveAffectedFileList, { file: file1.path });
Expand Down Expand Up @@ -520,7 +503,7 @@ namespace ts.projectSystem {
})
};
const host = createServerHost([dtsFile, f2, config]);
const session = projectSystem.createSession(host);
const session = createSession(host);
session.executeCommand({
seq: 1,
type: "request",
Expand Down Expand Up @@ -626,7 +609,7 @@ namespace ts.projectSystem {
})
};
const host = createServerHost([f1, f2, config]);
const session = projectSystem.createSession(host);
const session = createSession(host);
session.executeCommand({
seq: 1,
type: "request",
Expand Down
Loading