Skip to content

Commit 8bb01ab

Browse files
committed
Test
1 parent b9c71c3 commit 8bb01ab

File tree

28 files changed

+17645
-134
lines changed

28 files changed

+17645
-134
lines changed

src/testRunner/unittests/tsserver/configuredProjects.ts

Lines changed: 131 additions & 79 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ import {
2020
SymLink,
2121
} from "../helpers/virtualFileSystemWithWatch.js";
2222

23-
describe("unittests:: tsserver:: ConfiguredProjects", () => {
23+
describe("unittests:: tsserver:: configuredProjects::", () => {
2424
it("create configured project without file list", () => {
2525
const configFile: File = {
2626
path: "/a/b/tsconfig.json",
@@ -132,108 +132,160 @@ describe("unittests:: tsserver:: ConfiguredProjects", () => {
132132
baselineTsserverLogs("configuredProjects", "add and then remove a config file in a folder with loose files", session);
133133
});
134134

135-
it("add and then remove a config file when parent folder has config file", () => {
136-
const configFile: File = {
137-
path: `/user/username/projects/myproject/folder/tsconfig.json`,
138-
content: jsonToReadableText({ files: ["commonFile1.ts"] }),
139-
};
140-
const parentConfigFile: File = {
141-
path: `/user/username/projects/myproject/tsconfig.json`,
142-
content: jsonToReadableText({ files: ["folder/commonFile2.ts"] }),
143-
};
144-
const commonFile1: File = {
145-
path: `/user/username/projects/myproject/folder/commonFile1.ts`,
146-
content: "let x = 1",
147-
};
148-
const commonFile2: File = {
149-
path: `/user/username/projects/myproject/folder/commonFile2.ts`,
150-
content: "let y = 1",
151-
};
135+
describe("add and then remove a config file with another config", () => {
136+
function setup(parentOrSiblingConfigFile: File) {
137+
const configFile: File = {
138+
path: `/user/username/projects/myproject/folder/tsconfig.json`,
139+
content: jsonToReadableText({ files: ["commonFile1.ts"] }),
140+
};
141+
const commonFile1: File = {
142+
path: `/user/username/projects/myproject/folder/commonFile1.ts`,
143+
content: "let x = 1",
144+
};
145+
const commonFile2: File = {
146+
path: `/user/username/projects/myproject/folder/commonFile2.ts`,
147+
content: "let y = 1",
148+
};
152149

153-
const host = createServerHost([libFile, commonFile1, commonFile2, configFile, parentConfigFile]);
150+
const host = createServerHost([libFile, commonFile1, commonFile2, configFile, parentOrSiblingConfigFile]);
151+
const session = new TestSession(host);
152+
return { host, session, commonFile1, commonFile2, configFile };
153+
}
154+
function verify(scenario: string, parentOrSiblingConfigFile: File) {
155+
it(`add and then remove a config file ${scenario}`, () => {
156+
const { host, session, commonFile1, commonFile2, configFile } = setup(parentOrSiblingConfigFile);
154157

155-
const session = new TestSession(host);
158+
openFilesForSession([commonFile1], session);
156159

157-
// 1: When config file is deleted and then another file is opened
158-
openFilesForSession([commonFile1], session);
160+
session.logger.log("1: When config file is deleted and then another file is opened");
161+
// remove the tsconfig file
162+
host.deleteFile(configFile.path);
163+
openFilesForSession([commonFile2], session);
159164

160-
// remove the tsconfig file
161-
host.deleteFile(configFile.path);
162-
openFilesForSession([commonFile2], session);
165+
// Add a tsconfig file
166+
host.writeFile(configFile.path, configFile.content);
167+
host.runQueuedTimeoutCallbacks();
163168

164-
// Add a tsconfig file
165-
host.writeFile(configFile.path, configFile.content);
166-
host.runQueuedTimeoutCallbacks();
169+
// Check the state after files collected
170+
openFilesForSession([{ file: "/random/random.ts", content: "export const y = 10;" }], session);
167171

168-
// Check the state after files collected
169-
openFilesForSession([{ file: "/random/random.ts", content: "export const y = 10;" }], session);
172+
// Check status when all files are closed
173+
closeFilesForSession([commonFile1, commonFile2, "/random/random.ts"], session);
174+
openFilesForSession([{ file: "/random/random.ts", content: "export const y = 10;" }], session);
170175

171-
// Check status when all files are closed
172-
closeFilesForSession([commonFile1, commonFile2, "/random/random.ts"], session);
173-
openFilesForSession([{ file: "/random/random.ts", content: "export const y = 10;" }], session);
176+
closeFilesForSession(["/random/random.ts"], session);
177+
openFilesForSession([commonFile1, commonFile2], session);
174178

175-
// 2: When both files are open and config file is deleted
176-
closeFilesForSession(["/random/random.ts"], session);
177-
openFilesForSession([commonFile1, commonFile2], session);
179+
session.logger.log("2: When both files are open and config file is deleted");
180+
// remove the tsconfig file
181+
host.deleteFile(configFile.path);
182+
host.runQueuedTimeoutCallbacks();
178183

179-
// remove the tsconfig file
180-
host.deleteFile(configFile.path);
181-
host.runQueuedTimeoutCallbacks();
184+
// Add a tsconfig file
185+
host.writeFile(configFile.path, configFile.content);
186+
host.runQueuedTimeoutCallbacks(); // load configured project from disk + ensureProjectsForOpenFiles
182187

183-
// Add a tsconfig file
184-
host.writeFile(configFile.path, configFile.content);
185-
host.runQueuedTimeoutCallbacks(); // load configured project from disk + ensureProjectsForOpenFiles
188+
openFilesForSession([{ file: "/random/random.ts", content: "export const y = 10;" }], session);
186189

187-
openFilesForSession([{ file: "/random/random.ts", content: "export const y = 10;" }], session);
190+
closeFilesForSession([commonFile1, commonFile2, "/random/random.ts"], session);
191+
openFilesForSession([{ file: "/random/random.ts", content: "export const y = 10;" }], session);
188192

189-
closeFilesForSession([commonFile1, commonFile2, "/random/random.ts"], session);
190-
openFilesForSession([{ file: "/random/random.ts", content: "export const y = 10;" }], session);
193+
closeFilesForSession(["/random/random.ts"], session);
194+
openFilesForSession([commonFile1], session);
191195

192-
// 3: Check when both files are closed when config file is deleted
193-
closeFilesForSession(["/random/random.ts"], session);
194-
openFilesForSession([commonFile1], session);
196+
session.logger.log("3: Check when both files are closed when config file is deleted");
197+
// remove the tsconfig file
198+
host.deleteFile(configFile.path);
199+
openFilesForSession([commonFile2], session);
195200

196-
// remove the tsconfig file
197-
host.deleteFile(configFile.path);
198-
openFilesForSession([commonFile2], session);
201+
// State after open files are closed
202+
closeFilesForSession([commonFile1, commonFile2], session);
203+
openFilesForSession([{ file: "/random/random.ts", content: "export const y = 10;" }], session);
199204

200-
// State after open files are closed
201-
closeFilesForSession([commonFile1, commonFile2], session);
202-
openFilesForSession([{ file: "/random/random.ts", content: "export const y = 10;" }], session);
205+
host.writeFile(configFile.path, configFile.content);
206+
closeFilesForSession(["/random/random.ts"], session);
207+
openFilesForSession([commonFile1], session);
203208

204-
// 4: Check when both files are closed one by one when file is deleted
205-
host.writeFile(configFile.path, configFile.content);
206-
closeFilesForSession(["/random/random.ts"], session);
207-
openFilesForSession([commonFile1], session);
209+
session.logger.log("4: Check when both files are closed one by one when file is deleted");
210+
// remove the tsconfig file
211+
host.deleteFile(configFile.path);
212+
openFilesForSession([commonFile2], session);
208213

209-
// remove the tsconfig file
210-
host.deleteFile(configFile.path);
211-
openFilesForSession([commonFile2], session);
214+
// State after open files are closed
215+
closeFilesForSession([commonFile1], session);
216+
openFilesForSession([{ file: "/random/random.ts", content: "export const y = 10;" }], session);
212217

213-
// State after open files are closed
214-
closeFilesForSession([commonFile1], session);
215-
openFilesForSession([{ file: "/random/random.ts", content: "export const y = 10;" }], session);
218+
closeFilesForSession([commonFile2, "random/random.ts"], session);
219+
openFilesForSession([{ file: "/random/random.ts", content: "export const y = 10;" }], session);
216220

217-
closeFilesForSession([commonFile2, "random/random.ts"], session);
218-
openFilesForSession([{ file: "/random/random.ts", content: "export const y = 10;" }], session);
221+
host.writeFile(configFile.path, configFile.content);
222+
closeFilesForSession(["/random/random.ts"], session);
223+
openFilesForSession([commonFile1], session);
219224

220-
// 5: Check when both files are closed one by one when file is deleted order changed
221-
host.writeFile(configFile.path, configFile.content);
222-
closeFilesForSession(["/random/random.ts"], session);
223-
openFilesForSession([commonFile1], session);
225+
session.logger.log("5: Check when both files are closed one by one when file is deleted order changed");
226+
// remove the tsconfig file
227+
host.deleteFile(configFile.path);
228+
openFilesForSession([commonFile2], session);
224229

225-
// remove the tsconfig file
226-
host.deleteFile(configFile.path);
227-
openFilesForSession([commonFile2], session);
230+
// State after open files are closed
231+
closeFilesForSession([commonFile2], session);
232+
openFilesForSession([{ file: "/random/random.ts", content: "export const y = 10;" }], session);
228233

229-
// State after open files are closed
230-
closeFilesForSession([commonFile2], session);
231-
openFilesForSession([{ file: "/random/random.ts", content: "export const y = 10;" }], session);
234+
closeFilesForSession([commonFile1, "random/random.ts"], session);
235+
openFilesForSession([{ file: "/random/random.ts", content: "export const y = 10;" }], session);
232236

233-
closeFilesForSession([commonFile1, "random/random.ts"], session);
234-
openFilesForSession([{ file: "/random/random.ts", content: "export const y = 10;" }], session);
237+
session.logger.log("6. Check closing commonFile2 first");
238+
host.writeFile(configFile.path, configFile.content);
239+
closeFilesForSession(["/random/random.ts"], session);
240+
openFilesForSession([commonFile1, commonFile2], session);
241+
closeFilesForSession([commonFile2], session);
242+
openFilesForSession([{ file: "/random/random.ts", content: "export const y = 10;" }], session);
243+
244+
baselineTsserverLogs("configuredProjects", `add and then remove a config file ${scenario}`, session);
245+
});
246+
247+
it(`add and then remove a config file ${scenario} and file from first config is not open`, () => {
248+
const { host, session, commonFile2, configFile } = setup(parentOrSiblingConfigFile);
249+
openFilesForSession([commonFile2], session);
250+
251+
session.logger.log("1: When config file is deleted");
252+
// remove the tsconfig file
253+
host.deleteFile(configFile.path);
254+
host.runQueuedTimeoutCallbacks();
255+
256+
// Add a tsconfig file
257+
host.writeFile(configFile.path, configFile.content);
258+
host.runQueuedTimeoutCallbacks();
259+
260+
// Check the state after files collected
261+
openFilesForSession([{ file: "/random/random.ts", content: "export const y = 10;" }], session);
262+
263+
// Check status when all files are closed
264+
closeFilesForSession([commonFile2, "/random/random.ts"], session);
265+
openFilesForSession([{ file: "/random/random.ts", content: "export const y = 10;" }], session);
235266

236-
baselineTsserverLogs("configuredProjects", "add and then remove a config file when parent folder has config file", session);
267+
closeFilesForSession(["/random/random.ts"], session);
268+
openFilesForSession([commonFile2], session);
269+
270+
session.logger.log("2: Check when file is closed when config file is deleted");
271+
// remove the tsconfig file
272+
host.deleteFile(configFile.path);
273+
274+
// State after open files are closed
275+
closeFilesForSession([commonFile2], session);
276+
openFilesForSession([{ file: "/random/random.ts", content: "export const y = 10;" }], session);
277+
278+
baselineTsserverLogs("configuredProjects", `add and then remove a config file ${scenario} and file from first config is not open`, session);
279+
});
280+
}
281+
verify("when parent folder has config file", {
282+
path: `/user/username/projects/myproject/tsconfig.json`,
283+
content: jsonToReadableText({ files: ["folder/commonFile2.ts"] }),
284+
});
285+
verify("with sibling jsconfig file", {
286+
path: `/user/username/projects/myproject/folder/jsconfig.json`,
287+
content: jsonToReadableText({ files: ["commonFile2.ts"], typeAcquisition: { enable: false } }),
288+
});
237289
});
238290

239291
it("add new files to a configured project without file list", () => {

src/testRunner/unittests/tsserver/libraryResolution.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import {
66
TestSession,
77
} from "../helpers/tsserver.js";
88

9-
describe("unittests:: tsserver:: libraryResolution", () => {
9+
describe("unittests:: tsserver:: libraryResolution::", () => {
1010
it("with config", () => {
1111
const host = getServerHostForLibResolution();
1212
const session = new TestSession(host);
@@ -45,6 +45,7 @@ describe("unittests:: tsserver:: libraryResolution", () => {
4545
);
4646
host.ensureFileOrFolder({ path: "/home/src/projects/node_modules/@typescript/lib-dom/index.d.ts", content: "interface DOMInterface { }" });
4747
host.runQueuedTimeoutCallbacks();
48+
host.runQueuedTimeoutCallbacks();
4849
host.ensureFileOrFolder({ path: "/home/src/projects/node_modules/@typescript/lib-webworker/index.d.ts", content: "interface WebWorkerInterface { }" });
4950
host.runQueuedTimeoutCallbacks();
5051
host.runQueuedTimeoutCallbacks();

0 commit comments

Comments
 (0)