Skip to content

Commit 78a9bc3

Browse files
committed
Some extra tests before the change
1 parent af6c6a9 commit 78a9bc3

File tree

172 files changed

+212647
-454
lines changed

Some content is hidden

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

172 files changed

+212647
-454
lines changed

src/testRunner/unittests/tsserver/configuredProjects.ts

Lines changed: 187 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@ import * as ts from "../../_namespaces/ts";
22
import {
33
jsonToReadableText,
44
} from "../helpers";
5+
import {
6+
compilerOptionsToConfigJson,
7+
} from "../helpers/contents";
58
import {
69
ensureErrorFreeBuild,
710
} from "../helpers/solutionBuilder";
@@ -27,13 +30,10 @@ describe("unittests:: tsserver:: ConfiguredProjects", () => {
2730
it("create configured project without file list", () => {
2831
const configFile: File = {
2932
path: "/a/b/tsconfig.json",
30-
content: `
31-
{
32-
"compilerOptions": {},
33-
"exclude": [
34-
"e"
35-
]
36-
}`,
33+
content: jsonToReadableText({
34+
compilerOptions: {},
35+
exclude: ["e"],
36+
}),
3737
};
3838
const file1: File = {
3939
path: "/a/b/c/f1.ts",
@@ -57,11 +57,10 @@ describe("unittests:: tsserver:: ConfiguredProjects", () => {
5757
it("create configured project with the file list", () => {
5858
const configFile: File = {
5959
path: "/a/b/tsconfig.json",
60-
content: `
61-
{
62-
"compilerOptions": {},
63-
"include": ["*.ts"]
64-
}`,
60+
content: jsonToReadableText({
61+
compilerOptions: {},
62+
include: ["*.ts"],
63+
}),
6564
};
6665
const file1: File = {
6766
path: "/a/b/f1.ts",
@@ -85,9 +84,7 @@ describe("unittests:: tsserver:: ConfiguredProjects", () => {
8584
it("add and then remove a config file in a folder with loose files", () => {
8685
const configFile: File = {
8786
path: `/user/username/projects/myproject/tsconfig.json`,
88-
content: `{
89-
"files": ["commonFile1.ts"]
90-
}`,
87+
content: jsonToReadableText({ files: ["commonFile1.ts"] }),
9188
};
9289
const commonFile1: File = {
9390
path: `/user/username/projects/myproject/commonFile1.ts`,
@@ -101,6 +98,7 @@ describe("unittests:: tsserver:: ConfiguredProjects", () => {
10198
const host = createServerHost([libFile, commonFile1, commonFile2]);
10299

103100
const session = new TestSession(host);
101+
// 1: when both files are open
104102
openFilesForSession([commonFile1, commonFile2], session);
105103

106104
// Add a tsconfig file
@@ -111,9 +109,139 @@ describe("unittests:: tsserver:: ConfiguredProjects", () => {
111109
host.deleteFile(configFile.path);
112110
host.runQueuedTimeoutCallbacks(); // Refresh inferred projects
113111

112+
// Add a tsconfig file
113+
host.writeFile(configFile.path, configFile.content);
114+
host.runQueuedTimeoutCallbacks(); // load configured project from disk + ensureProjectsForOpenFiles
115+
116+
openFilesForSession([{ file: "/random/random.ts", content: "export const y = 10;" }], session);
117+
// Check status when all files are closed
118+
closeFilesForSession([commonFile1, commonFile2, "/random/random.ts"], session);
119+
openFilesForSession([{ file: "/random/random.ts", content: "export const y = 10;" }], session);
120+
121+
// 2: when file is opened while config file is deleted
122+
closeFilesForSession(["/random/random.ts"], session);
123+
openFilesForSession([commonFile1], session);
124+
125+
// remove the tsconfig file
126+
host.deleteFile(configFile.path);
127+
openFilesForSession([commonFile2], session);
128+
129+
// Add a tsconfig file
130+
host.writeFile(configFile.path, configFile.content);
131+
host.runQueuedTimeoutCallbacks(); // load configured project from disk + ensureProjectsForOpenFiles
132+
133+
openFilesForSession([{ file: "/random/random.ts", content: "export const y = 10;" }], session);
134+
// Check status when all files are closed
135+
closeFilesForSession([commonFile1, commonFile2, "/random/random.ts"], session);
136+
openFilesForSession([{ file: "/random/random.ts", content: "export const y = 10;" }], session);
137+
114138
baselineTsserverLogs("configuredProjects", "add and then remove a config file in a folder with loose files", session);
115139
});
116140

141+
it("add and then remove a config file when parent folder has config file", () => {
142+
const configFile: File = {
143+
path: `/user/username/projects/myproject/folder/tsconfig.json`,
144+
content: jsonToReadableText({ files: ["commonFile1.ts"] }),
145+
};
146+
const parentConfigFile: File = {
147+
path: `/user/username/projects/myproject/tsconfig.json`,
148+
content: jsonToReadableText({ files: ["folder/commonFile2.ts"] }),
149+
};
150+
const commonFile1: File = {
151+
path: `/user/username/projects/myproject/folder/commonFile1.ts`,
152+
content: "let x = 1",
153+
};
154+
const commonFile2: File = {
155+
path: `/user/username/projects/myproject/folder/commonFile2.ts`,
156+
content: "let y = 1",
157+
};
158+
159+
const host = createServerHost([libFile, commonFile1, commonFile2, configFile, parentConfigFile]);
160+
161+
const session = new TestSession(host);
162+
163+
// 1: When config file is deleted and then another file is opened
164+
openFilesForSession([commonFile1], session);
165+
166+
// remove the tsconfig file
167+
host.deleteFile(configFile.path);
168+
openFilesForSession([commonFile2], session);
169+
170+
// Add a tsconfig file
171+
host.writeFile(configFile.path, configFile.content);
172+
host.runQueuedTimeoutCallbacks();
173+
174+
// Check the state after files collected
175+
openFilesForSession([{ file: "/random/random.ts", content: "export const y = 10;" }], session);
176+
177+
// Check status when all files are closed
178+
closeFilesForSession([commonFile1, commonFile2, "/random/random.ts"], session);
179+
openFilesForSession([{ file: "/random/random.ts", content: "export const y = 10;" }], session);
180+
181+
// 2: When both files are open and config file is deleted
182+
closeFilesForSession(["/random/random.ts"], session);
183+
openFilesForSession([commonFile1, commonFile2], session);
184+
185+
// remove the tsconfig file
186+
host.deleteFile(configFile.path);
187+
host.runQueuedTimeoutCallbacks();
188+
189+
// Add a tsconfig file
190+
host.writeFile(configFile.path, configFile.content);
191+
host.runQueuedTimeoutCallbacks(); // load configured project from disk + ensureProjectsForOpenFiles
192+
193+
openFilesForSession([{ file: "/random/random.ts", content: "export const y = 10;" }], session);
194+
195+
closeFilesForSession([commonFile1, commonFile2, "/random/random.ts"], session);
196+
openFilesForSession([{ file: "/random/random.ts", content: "export const y = 10;" }], session);
197+
198+
// 3: Check when both files are closed when config file is deleted
199+
closeFilesForSession(["/random/random.ts"], session);
200+
openFilesForSession([commonFile1], session);
201+
202+
// remove the tsconfig file
203+
host.deleteFile(configFile.path);
204+
openFilesForSession([commonFile2], session);
205+
206+
// State after open files are closed
207+
closeFilesForSession([commonFile1, commonFile2], session);
208+
openFilesForSession([{ file: "/random/random.ts", content: "export const y = 10;" }], session);
209+
210+
// 4: Check when both files are closed one by one when file is deleted
211+
host.writeFile(configFile.path, configFile.content);
212+
closeFilesForSession(["/random/random.ts"], session);
213+
openFilesForSession([commonFile1], session);
214+
215+
// remove the tsconfig file
216+
host.deleteFile(configFile.path);
217+
openFilesForSession([commonFile2], session);
218+
219+
// State after open files are closed
220+
closeFilesForSession([commonFile1], session);
221+
openFilesForSession([{ file: "/random/random.ts", content: "export const y = 10;" }], session);
222+
223+
closeFilesForSession([commonFile2, "random/random.ts"], session);
224+
openFilesForSession([{ file: "/random/random.ts", content: "export const y = 10;" }], session);
225+
226+
// 5: Check when both files are closed one by one when file is deleted order changed
227+
host.writeFile(configFile.path, configFile.content);
228+
closeFilesForSession(["/random/random.ts"], session);
229+
openFilesForSession([commonFile1], session);
230+
231+
// remove the tsconfig file
232+
host.deleteFile(configFile.path);
233+
openFilesForSession([commonFile2], session);
234+
235+
// State after open files are closed
236+
closeFilesForSession([commonFile2], session);
237+
openFilesForSession([{ file: "/random/random.ts", content: "export const y = 10;" }], session);
238+
239+
closeFilesForSession([commonFile1, "random/random.ts"], session);
240+
openFilesForSession([{ file: "/random/random.ts", content: "export const y = 10;" }], session);
241+
242+
baselineTsserverLogs("configuredProjects", "add and then remove a config file when parent folder has config file", session);
243+
});
244+
117245
it("add new files to a configured project without file list", () => {
118246
const configFile: File = {
119247
path: "/a/b/tsconfig.json",
@@ -132,13 +260,13 @@ describe("unittests:: tsserver:: ConfiguredProjects", () => {
132260
it("should ignore non-existing files specified in the config file", () => {
133261
const configFile: File = {
134262
path: "/a/b/tsconfig.json",
135-
content: `{
136-
"compilerOptions": {},
137-
"files": [
138-
"commonFile1.ts",
139-
"commonFile3.ts"
140-
]
141-
}`,
263+
content: jsonToReadableText({
264+
compilerOptions: {},
265+
files: [
266+
"commonFile1.ts",
267+
"commonFile3.ts",
268+
],
269+
}),
142270
};
143271
const host = createServerHost([commonFile1, commonFile2, configFile]);
144272
const session = new TestSession(host);
@@ -168,10 +296,10 @@ describe("unittests:: tsserver:: ConfiguredProjects", () => {
168296
it("files explicitly excluded in config file", () => {
169297
const configFile: File = {
170298
path: "/a/b/tsconfig.json",
171-
content: `{
172-
"compilerOptions": {},
173-
"exclude": ["/a/c"]
174-
}`,
299+
content: jsonToReadableText({
300+
compilerOptions: {},
301+
exclude: ["/a/c"],
302+
}),
175303
};
176304
const excludedFile1: File = {
177305
path: "/a/c/excluedFile1.ts",
@@ -204,12 +332,10 @@ describe("unittests:: tsserver:: ConfiguredProjects", () => {
204332
};
205333
const configFile: File = {
206334
path: "/a/b/tsconfig.json",
207-
content: `{
208-
"compilerOptions": {
209-
"moduleResolution": "node"
210-
},
211-
"files": ["${file1.path}"]
212-
}`,
335+
content: jsonToReadableText({
336+
compilerOptions: compilerOptionsToConfigJson({ moduleResolution: ts.ModuleResolutionKind.Node10 }),
337+
files: [file1.path],
338+
}),
213339
};
214340
const files = [file1, nodeModuleFile, classicModuleFile, configFile, randomFile];
215341
const host = createServerHost(files);
@@ -218,12 +344,10 @@ describe("unittests:: tsserver:: ConfiguredProjects", () => {
218344

219345
host.writeFile(
220346
configFile.path,
221-
`{
222-
"compilerOptions": {
223-
"moduleResolution": "classic"
224-
},
225-
"files": ["${file1.path}"]
226-
}`,
347+
jsonToReadableText({
348+
compilerOptions: compilerOptionsToConfigJson({ moduleResolution: ts.ModuleResolutionKind.Classic }),
349+
files: [file1.path],
350+
}),
227351
);
228352
host.runQueuedTimeoutCallbacks();
229353

@@ -244,12 +368,12 @@ describe("unittests:: tsserver:: ConfiguredProjects", () => {
244368
};
245369
const configFile: File = {
246370
path: "/a/b/tsconfig.json",
247-
content: `{
248-
"compilerOptions": {
249-
"target": "es6"
250-
},
251-
"files": [ "main.ts" ]
252-
}`,
371+
content: jsonToReadableText({
372+
compilerOptions: {
373+
target: "es6",
374+
},
375+
files: ["main.ts"],
376+
}),
253377
};
254378
const host = createServerHost([file1, file2, configFile]);
255379
const session = new TestSession(host);
@@ -262,13 +386,13 @@ describe("unittests:: tsserver:: ConfiguredProjects", () => {
262386
it("should tolerate config file errors and still try to build a project", () => {
263387
const configFile: File = {
264388
path: "/a/b/tsconfig.json",
265-
content: `{
266-
"compilerOptions": {
267-
"target": "es6",
268-
"allowAnything": true
269-
},
270-
"someOtherProperty": {}
271-
}`,
389+
content: jsonToReadableText({
390+
compilerOptions: {
391+
target: "es6",
392+
allowAnything: true,
393+
},
394+
someOtherProperty: {},
395+
}),
272396
};
273397
const host = createServerHost([commonFile1, commonFile2, libFile, configFile]);
274398
const session = new TestSession(host);
@@ -287,12 +411,12 @@ describe("unittests:: tsserver:: ConfiguredProjects", () => {
287411
};
288412
const configFile: File = {
289413
path: "/a/b/tsconfig.json",
290-
content: `{
291-
"compilerOptions": {
292-
"target": "es6"
293-
},
294-
"files": [ "main.ts", "main2.ts" ]
295-
}`,
414+
content: jsonToReadableText({
415+
compilerOptions: {
416+
target: "es6",
417+
},
418+
files: ["main.ts", "main2.ts"],
419+
}),
296420
};
297421
const host = createServerHost([file1, file2, configFile, libFile]);
298422
const session = new TestSession({ host, useSingleInferredProject: true });
@@ -309,12 +433,12 @@ describe("unittests:: tsserver:: ConfiguredProjects", () => {
309433
};
310434
const configFile: File = {
311435
path: "/a/b/tsconfig.json",
312-
content: `{
313-
"compilerOptions": {
314-
"target": "es6"
315-
},
316-
"files": [ "main.ts" ]
317-
}`,
436+
content: jsonToReadableText({
437+
compilerOptions: {
438+
target: "es6",
439+
},
440+
files: ["main.ts"],
441+
}),
318442
};
319443
const host = createServerHost([file1, configFile, libFile]);
320444
const session = new TestSession({ host, useSingleInferredProject: true });

0 commit comments

Comments
 (0)