Skip to content

Commit d105b6a

Browse files
authored
More baselining for future changes (#53564)
1 parent 4d4d5f2 commit d105b6a

File tree

317 files changed

+149510
-3241
lines changed

Some content is hidden

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

317 files changed

+149510
-3241
lines changed

src/testRunner/unittests/services/convertToAsyncFunction.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -414,7 +414,7 @@ function testConvertToAsyncFunction(it: Mocha.PendingTestFunction, caption: stri
414414
files.push(moduleFile);
415415
}
416416
const host = createServerHost(files);
417-
const projectService = createProjectService(host);
417+
const projectService = createProjectService(host, { allowNonBaseliningLogger: true });
418418
projectService.openClientFile(file.path);
419419
return ts.first(projectService.inferredProjects).getLanguageService();
420420
}

src/testRunner/unittests/services/extract/helpers.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ export function testExtractSymbol(caption: string, text: string, baselineFolder:
138138

139139
function makeProgram(f: {path: string, content: string }, includeLib?: boolean) {
140140
const host = createServerHost(includeLib ? [f, libFile] : [f]); // libFile is expensive to parse repeatedly - only test when required
141-
const projectService = createProjectService(host);
141+
const projectService = createProjectService(host, { allowNonBaseliningLogger: true });
142142
projectService.openClientFile(f.path);
143143
const program = projectService.inferredProjects[0].getLanguageService().getProgram()!;
144144
const autoImportProvider = projectService.inferredProjects[0].getLanguageService().getAutoImportProvider();
@@ -163,7 +163,7 @@ export function testExtractSymbolFailed(caption: string, text: string, descripti
163163
content: t.source
164164
};
165165
const host = createServerHost([f, libFile]);
166-
const projectService = createProjectService(host);
166+
const projectService = createProjectService(host, { allowNonBaseliningLogger: true });
167167
projectService.openClientFile(f.path);
168168
const program = projectService.inferredProjects[0].getLanguageService().getProgram()!;
169169
const sourceFile = program.getSourceFile(f.path)!;

src/testRunner/unittests/services/organizeImports.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1036,7 +1036,7 @@ export * from "lib";
10361036

10371037
function makeLanguageService(...files: File[]) {
10381038
const host = createServerHost(files);
1039-
const projectService = createProjectService(host, { useSingleInferredProject: true });
1039+
const projectService = createProjectService(host, { useSingleInferredProject: true, allowNonBaseliningLogger: true });
10401040
projectService.setCompilerOptionsForInferredProjects({ jsx: files.some(f => f.path.endsWith("x")) ? ts.JsxEmit.React : ts.JsxEmit.None });
10411041
files.forEach(f => projectService.openClientFile(f.path));
10421042
return projectService.inferredProjects[0].getLanguageService();

src/testRunner/unittests/tsserver/applyChangesToOpenFiles.ts

Lines changed: 107 additions & 150 deletions
Original file line numberDiff line numberDiff line change
@@ -9,186 +9,143 @@ import {
99
libFile,
1010
} from "../virtualFileSystemWithWatch";
1111
import {
12+
baselineTsserverLogs,
13+
createLoggerWithInMemoryLogs,
1214
createSession,
13-
TestSession,
1415
} from "./helpers";
1516

1617
describe("unittests:: tsserver:: applyChangesToOpenFiles", () => {
17-
const configFile: File = {
18-
path: "/a/b/tsconfig.json",
19-
content: "{}"
20-
};
21-
const file3: File = {
22-
path: "/a/b/file3.ts",
23-
content: "let xyz = 1;"
24-
};
25-
const app: File = {
26-
path: "/a/b/app.ts",
27-
content: "let z = 1;"
28-
};
29-
3018
function fileContentWithComment(file: File) {
3119
return `// some copy right notice
3220
${file.content}`;
3321
}
3422

35-
function verifyText(service: ts.server.ProjectService, file: string, expected: string) {
36-
const info = service.getScriptInfo(file)!;
37-
const snap = info.getSnapshot();
38-
// Verified applied in reverse order
39-
assert.equal(snap.getText(0, snap.getLength()), expected, `Text of changed file: ${file}`);
40-
}
41-
42-
function verifyProjectVersion(project: ts.server.Project, expected: number) {
43-
assert.equal(Number(project.getProjectVersion()), expected);
44-
}
45-
46-
interface Verify {
47-
applyChangesToOpen: (session: TestSession) => void;
48-
openFile1Again: (session: TestSession) => void;
49-
}
50-
function verify({ applyChangesToOpen, openFile1Again }: Verify) {
23+
function setup() {
24+
const configFile: File = {
25+
path: "/a/b/tsconfig.json",
26+
content: "{}"
27+
};
28+
const file3: File = {
29+
path: "/a/b/file3.ts",
30+
content: "let xyz = 1;"
31+
};
32+
const app: File = {
33+
path: "/a/b/app.ts",
34+
content: "let z = 1;"
35+
};
5136
const host = createServerHost([app, file3, commonFile1, commonFile2, libFile, configFile]);
52-
const session = createSession(host);
37+
const session = createSession(host, { logger: createLoggerWithInMemoryLogs(host) });
5338
session.executeCommandSeq<ts.server.protocol.OpenRequest>({
5439
command: ts.server.protocol.CommandTypes.Open,
5540
arguments: { file: app.path }
5641
});
57-
const service = session.getProjectService();
58-
const project = service.configuredProjects.get(configFile.path)!;
59-
assert.isDefined(project);
60-
verifyProjectVersion(project, 1);
6142
session.executeCommandSeq<ts.server.protocol.OpenRequest>({
6243
command: ts.server.protocol.CommandTypes.Open,
6344
arguments: {
6445
file: file3.path,
6546
fileContent: fileContentWithComment(file3)
6647
}
6748
});
68-
verifyProjectVersion(project, 2);
69-
70-
// Verify Texts
71-
verifyText(service, commonFile1.path, commonFile1.content);
72-
verifyText(service, commonFile2.path, commonFile2.content);
73-
verifyText(service, app.path, app.content);
74-
verifyText(service, file3.path, fileContentWithComment(file3));
75-
76-
// Apply changes
77-
applyChangesToOpen(session);
78-
79-
// Verify again
80-
verifyProjectVersion(project, 3);
81-
// Open file contents
82-
verifyText(service, commonFile1.path, fileContentWithComment(commonFile1));
83-
verifyText(service, commonFile2.path, fileContentWithComment(commonFile2));
84-
verifyText(service, app.path, "let zzz = 10;let zz = 10;let z = 1;");
85-
verifyText(service, file3.path, file3.content);
86-
87-
// Open file1 again
88-
openFile1Again(session);
89-
assert.isTrue(service.getScriptInfo(commonFile1.path)!.isScriptOpen());
90-
91-
// Verify that file1 contents are changed
92-
verifyProjectVersion(project, 4);
93-
verifyText(service, commonFile1.path, commonFile1.content);
94-
verifyText(service, commonFile2.path, fileContentWithComment(commonFile2));
95-
verifyText(service, app.path, "let zzz = 10;let zz = 10;let z = 1;");
96-
verifyText(service, file3.path, file3.content);
49+
return { session, file3, app };
9750
}
9851

9952
it("with applyChangedToOpenFiles request", () => {
100-
verify({
101-
applyChangesToOpen: session => session.executeCommandSeq<ts.server.protocol.ApplyChangedToOpenFilesRequest>({
102-
command: ts.server.protocol.CommandTypes.ApplyChangedToOpenFiles,
103-
arguments: {
104-
openFiles: [
105-
{
106-
fileName: commonFile1.path,
107-
content: fileContentWithComment(commonFile1)
108-
},
109-
{
110-
fileName: commonFile2.path,
111-
content: fileContentWithComment(commonFile2)
112-
}
113-
],
114-
changedFiles: [
115-
{
116-
fileName: app.path,
117-
changes: [
118-
{
119-
span: { start: 0, length: 0 },
120-
newText: "let zzz = 10;"
121-
},
122-
{
123-
span: { start: 0, length: 0 },
124-
newText: "let zz = 10;"
125-
}
126-
]
127-
}
128-
],
129-
closedFiles: [
130-
file3.path
131-
]
132-
}
133-
}),
134-
openFile1Again: session => session.executeCommandSeq<ts.server.protocol.ApplyChangedToOpenFilesRequest>({
135-
command: ts.server.protocol.CommandTypes.ApplyChangedToOpenFiles,
136-
arguments: {
137-
openFiles: [{
53+
const { session, file3, app } = setup();
54+
// Apply changes
55+
session.executeCommandSeq<ts.server.protocol.ApplyChangedToOpenFilesRequest>({
56+
command: ts.server.protocol.CommandTypes.ApplyChangedToOpenFiles,
57+
arguments: {
58+
openFiles: [
59+
{
13860
fileName: commonFile1.path,
139-
content: commonFile1.content
140-
}]
141-
}
142-
}),
61+
content: fileContentWithComment(commonFile1)
62+
},
63+
{
64+
fileName: commonFile2.path,
65+
content: fileContentWithComment(commonFile2)
66+
}
67+
],
68+
changedFiles: [
69+
{
70+
fileName: app.path,
71+
changes: [
72+
{
73+
span: { start: 0, length: 0 },
74+
newText: "let zzz = 10;"
75+
},
76+
{
77+
span: { start: 0, length: 0 },
78+
newText: "let zz = 10;"
79+
}
80+
]
81+
}
82+
],
83+
closedFiles: [
84+
file3.path
85+
]
86+
}
14387
});
88+
// Open file1 again
89+
session.executeCommandSeq<ts.server.protocol.ApplyChangedToOpenFilesRequest>({
90+
command: ts.server.protocol.CommandTypes.ApplyChangedToOpenFiles,
91+
arguments: {
92+
openFiles: [{
93+
fileName: commonFile1.path,
94+
content: commonFile1.content
95+
}]
96+
}
97+
});
98+
baselineTsserverLogs("applyChangesToOpenFiles", "with applyChangedToOpenFiles request", session);
14499
});
145100

146101
it("with updateOpen request", () => {
147-
verify({
148-
applyChangesToOpen: session => session.executeCommandSeq<ts.server.protocol.UpdateOpenRequest>({
149-
command: ts.server.protocol.CommandTypes.UpdateOpen,
150-
arguments: {
151-
openFiles: [
152-
{
153-
file: commonFile1.path,
154-
fileContent: fileContentWithComment(commonFile1)
155-
},
156-
{
157-
file: commonFile2.path,
158-
fileContent: fileContentWithComment(commonFile2)
159-
}
160-
],
161-
changedFiles: [
162-
{
163-
fileName: app.path,
164-
textChanges: [
165-
{
166-
start: { line: 1, offset: 1 },
167-
end: { line: 1, offset: 1 },
168-
newText: "let zzz = 10;",
169-
},
170-
{
171-
start: { line: 1, offset: 1 },
172-
end: { line: 1, offset: 1 },
173-
newText: "let zz = 10;",
174-
}
175-
]
176-
}
177-
],
178-
closedFiles: [
179-
file3.path
180-
]
181-
}
182-
}),
183-
openFile1Again: session => session.executeCommandSeq<ts.server.protocol.UpdateOpenRequest>({
184-
command: ts.server.protocol.CommandTypes.UpdateOpen,
185-
arguments: {
186-
openFiles: [{
102+
const { session, file3, app } = setup();
103+
// Apply changes
104+
session.executeCommandSeq<ts.server.protocol.UpdateOpenRequest>({
105+
command: ts.server.protocol.CommandTypes.UpdateOpen,
106+
arguments: {
107+
openFiles: [
108+
{
187109
file: commonFile1.path,
188-
fileContent: commonFile1.content
189-
}]
190-
}
191-
}),
110+
fileContent: fileContentWithComment(commonFile1)
111+
},
112+
{
113+
file: commonFile2.path,
114+
fileContent: fileContentWithComment(commonFile2)
115+
}
116+
],
117+
changedFiles: [
118+
{
119+
fileName: app.path,
120+
textChanges: [
121+
{
122+
start: { line: 1, offset: 1 },
123+
end: { line: 1, offset: 1 },
124+
newText: "let zzz = 10;",
125+
},
126+
{
127+
start: { line: 1, offset: 1 },
128+
end: { line: 1, offset: 1 },
129+
newText: "let zz = 10;",
130+
}
131+
]
132+
}
133+
],
134+
closedFiles: [
135+
file3.path
136+
]
137+
}
138+
});
139+
// Open file1 again
140+
session.executeCommandSeq<ts.server.protocol.UpdateOpenRequest>({
141+
command: ts.server.protocol.CommandTypes.UpdateOpen,
142+
arguments: {
143+
openFiles: [{
144+
file: commonFile1.path,
145+
fileContent: commonFile1.content
146+
}]
147+
}
192148
});
149+
baselineTsserverLogs("applyChangesToOpenFiles", "with updateOpen request", session);
193150
});
194151
});

0 commit comments

Comments
 (0)