8000 Tests for unresolved imports from multiple places · microsoft/TypeScript@feb3220 · GitHub
[go: up one dir, main page]

Skip to content

Commit feb3220

Browse files
committed
Tests for unresolved imports from multiple places
1 parent 4d127fa commit feb3220

File tree

17 files changed

+255180
-5775
lines changed

17 files changed

+255180
-5775
lines changed

src/testRunner/unittests/tsbuild/cacheResolutions.ts

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,33 @@ describe("unittests:: tsbuild:: cacheResolutions::", () => {
156156
caption: "modify e/ea/eaa/eaaa/x/y/z/randomFileForImport by adding import",
157157
edit: fs => prependText(fs, "/src/project/e/ea/eaa/eaaa/x/y/z/randomFileForImport.ts", `import type { ImportInterface0 } from "pkg0";\n`),
158158
},
159+
{
160+
caption: "modify randomFileForImport by adding unresolved import",
161+
edit: fs => prependText(fs, "/src/project/randomFileForImport.ts", `import type { ImportInterface1 } from "pkg1";\n`),
162+
},
163+
{
164+
caption: "modify b/randomFileForImport by adding unresolved import",
165+
edit: fs => prependText(fs, "/src/project/b/randomFileForImport.ts", `import type { ImportInterface1 } from "pkg1";\n`),
166+
},
167+
{
168+
caption: "modify c/ca/caa/randomFileForImport by adding unresolved import",
169+
edit: fs => prependText(fs, "/src/project/c/ca/caa/randomFileForImport.ts", `import type { ImportInterface1 } from "pkg1";\n`),
170+
},
171+
{
172+
caption: "modify d/da/daa/daaa/x/y/z/randomFileForImport by adding unresolved import",
173+
edit: fs => prependText(fs, "/src/project/d/da/daa/daaa/x/y/z/randomFileForImport.ts", `import type { ImportInterface1 } from "pkg1";\n`),
174+
},
175+
{
176+
caption: "modify e/ea/eaa/eaaa/x/y/z/randomFileForImport by adding unresolved import",
177+
edit: fs => prependText(fs, "/src/project/e/ea/eaa/eaaa/x/y/z/randomFileForImport.ts", `import type { ImportInterface1 } from "pkg1";\n`),
178+
},
179+
{
180+
caption: "add file for unresolved import",
181+
edit: fs => {
182+
fs.mkdirpSync("/src/project/node_modules/pkg1");
183+
fs.writeFileSync("/src/project/node_modules/pkg1/index.d.ts", getPkgImportContent("Import", 1));
184+
},
185+
},
159186
]
160187
});
161188
});

src/testRunner/unittests/tsbuild/cacheResolutionsHelper.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -273,43 +273,55 @@ function getFsMapWithSameResolutionFromMultiplePlaces(): { [path: string]: strin
273273
}),
274274
"/src/project/fileWithImports.ts": Utils.dedent`
275275
import type { ImportInterface0 } from "pkg0";
276+
import type { ImportInterface1 } from "pkg1";
276277
`,
277278
"/src/project/randomFileForImport.ts": getRandomFileContent(),
278279
"/src/project/a/fileWithImports.ts": Utils.dedent`
279280
import type { ImportInterface0 } from "pkg0";
281+
import type { ImportInterface1 } from "pkg1";
280282
`,
281283
"/src/project/b/ba/fileWithImports.ts": Utils.dedent`
282284
import type { ImportInterface0 } from "pkg0";
285+
import type { ImportInterface1 } from "pkg1";
283286
`,
284287
"/src/project/b/randomFileForImport.ts": getRandomFileContent(),
285288
"/src/project/c/ca/fileWithImports.ts": Utils.dedent`
286289
import type { ImportInterface0 } from "pkg0";
290+
import type { ImportInterface1 } from "pkg1";
287291
`,
288292
"/src/project/c/ca/caa/randomFileForImport.ts": getRandomFileContent(),
289293
"/src/project/c/ca/caa/caaa/fileWithImports.ts": Utils.dedent`
290294
import type { ImportInterface0 } from "pkg0";
295+
import type { ImportInterface1 } from "pkg1";
291296
`,
292297
"/src/project/c/cb/fileWithImports.ts": Utils.dedent`
293298
import type { ImportInterface0 } from "pkg0";
299+
import type { ImportInterface1 } from "pkg1";
294300
`,
295301
"/src/project/d/da/daa/daaa/x/y/z/randomFileForImport.ts": getRandomFileContent(),
296302
"/src/project/d/da/daa/daaa/fileWithImports.ts": Utils.dedent`
297303
import type { ImportInterface0 } from "pkg0";
304+
import type { ImportInterface1 } from "pkg1";
298305
`,
299306
"/src/project/d/da/daa/fileWithImports.ts": Utils.dedent`
300307
import type { ImportInterface0 } from "pkg0";
308+
import type { ImportInterface1 } from "pkg1";
301309
`,
302310
"/src/project/d/da/fileWithImports.ts": Utils.dedent`
303311
import type { ImportInterface0 } from "pkg0";
312+
import type { ImportInterface1 } from "pkg1";
304313
`,
305314
"/src/project/e/ea/fileWithImports.ts": Utils.dedent`
306315
import type { ImportInterface0 } from "pkg0";
316+
import type { ImportInterface1 } from "pkg1";
307317
`,
308318
"/src/project/e/ea/eaa/fileWithImports.ts": Utils.dedent`
309319
import type { ImportInterface0 } from "pkg0";
320+
import type { ImportInterface1 } from "pkg1";
310321
`,
311322
"/src/project/e/ea/eaa/eaaa/fileWithImports.ts": Utils.dedent`
312323
import type { ImportInterface0 } from "pkg0";
324+
import type { ImportInterface1 } from "pkg1";
313325
`,
314326
"/src/project/e/ea/eaa/eaaa/x/y/z/randomFileForImport.ts": getRandomFileContent(),
315327
"/src/project/node_modules/pkg0/index.d.ts": getPkgImportContent("Import", 0),

src/testRunner/unittests/tsbuildWatch/cacheResolutions.ts

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -202,6 +202,39 @@ describe("unittests:: tsbuildWatch:: watchMode:: cacheResolutions::", () => {
202202
edit: sys => sys.prependFile("/src/project/e/ea/eaa/eaaa/x/y/z/randomFileForImport.ts", `import type { ImportInterface0 } from "pkg0";\n`),
203203
timeouts: sys => sys.runQueuedTimeoutCallbacks(),
204204
},
205+
{
206+
caption: "modify randomFileForImport by adding unresolved import",
207+
edit: sys => sys.prependFile("/src/project/randomFileForImport.ts", `import type { ImportInterface1 } from "pkg1";\n`),
208+
timeouts: sys => sys.runQueuedTimeoutCallbacks(),
209+
},
210+
{
211+
caption: "modify b/randomFileForImport by adding unresolved import",
212+
edit: sys => sys.prependFile("/src/project/b/randomFileForImport.ts", `import type { ImportInterface1 } from "pkg1";\n`),
213+
timeouts: sys => sys.runQueuedTimeoutCallbacks(),
214+
},
215+
{
216+
caption: "modify c/ca/caa/randomFileForImport by adding unresolved import",
217+
edit: sys => sys.prependFile("/src/project/c/ca/caa/randomFileForImport.ts", `import type { ImportInterface1 } from "pkg1";\n`),
218+
timeouts: sys => sys.runQueuedTimeoutCallbacks(),
219+
},
220+
{
221+
caption: "modify d/da/daa/daaa/x/y/z/randomFileForImport by adding unresolved import",
222+
edit: sys => sys.prependFile("/src/project/d/da/daa/daaa/x/y/z/randomFileForImport.ts", `import type { ImportInterface1 } from "pkg1";\n`),
223+
timeouts: sys => sys.runQueuedTimeoutCallbacks(),
224+
},
225+
{
226+
caption: "modify e/ea/eaa/eaaa/x/y/z/randomFileForImport by adding unresolved import",
227+
edit: sys => sys.prependFile("/src/project/e/ea/eaa/eaaa/x/y/z/randomFileForImport.ts", `import type { ImportInterface1 } from "pkg1";\n`),
228+
timeouts: sys => sys.runQueuedTimeoutCallbacks(),
229+
},
230+
{
231+
caption: "add file for unresolved import and random edit",
232+
edit: sys => {
233+
sys.ensureFileOrFolder({ path: "/src/project/node_modules/pkg1/index.d.ts", content: getPkgImportContent("Import", 1) });
234+
sys.appendFile("/src/project/randomFileForImport.ts", `export const y = 10;`);
235+
},
236+
timeouts: sys => sys.runQueuedTimeoutCallbacks(),
237+
},
205238
]
206239
});
207240
}

src/testRunner/unittests/tsc/cacheResolutions.ts

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -252,6 +252,33 @@ describe("unittests:: tsc:: cacheResolutions::", () => {
252252
caption: "modify e/ea/eaa/eaaa/x/y/z/randomFileForImport by adding import",
253253
edit: fs => prependText(fs, "/src/project/e/ea/eaa/eaaa/x/y/z/randomFileForImport.ts", `import type { ImportInterface0 } from "pkg0";\n`),
254254
},
255+
{
256+
caption: "modify randomFileForImport by adding unresolved import",
257+
edit: fs => prependText(fs, "/src/project/randomFileForImport.ts", `import type { ImportInterface1 } from "pkg1";\n`),
258+
},
259+
{
260+
caption: "modify b/randomFileForImport by adding unresolved import",
261+
edit: fs => prependText(fs, "/src/project/b/randomFileForImport.ts", `import type { ImportInterface1 } from "pkg1";\n`),
262+
},
263+
{
264+
caption: "modify c/ca/caa/randomFileForImport by adding unresolved import",
265+
edit: fs => prependText(fs, "/src/project/c/ca/caa/randomFileForImport.ts", `import type { ImportInterface1 } from "pkg1";\n`),
266+
},
267+
{
268+
caption: "modify d/da/daa/daaa/x/y/z/randomFileForImport by adding unresolved import",
269+
edit: fs => prependText(fs, "/src/project/d/da/daa/daaa/x/y/z/randomFileForImport.ts", `import type { ImportInterface1 } from "pkg1";\n`),
270+
},
271+
{
272+
caption: "modify e/ea/eaa/eaaa/x/y/z/randomFileForImport by adding unresolved import",
273+
edit: fs => prependText(fs, "/src/project/e/ea/eaa/eaaa/x/y/z/randomFileForImport.ts", `import type { ImportInterface1 } from "pkg1";\n`),
274+
},
275+
{
276+
caption: "add file for unresolved import",
277+
edit: fs => {
278+
fs.mkdirpSync("/src/project/node_modules/pkg1");
279+
fs.writeFileSync("/src/project/node_modules/pkg1/index.d.ts", getPkgImportContent("Import", 1));
280+
},
281+
},
255282
]
256283
});
257284
});

src/testRunner/unittests/tscWatch/cacheResolutions.ts

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -212,6 +212,42 @@ describe("unittests:: tsc-watch:: cacheResolutions::", () => {
212212
edit: sys => sys.prependFile("/src/project/e/ea/eaa/eaaa/x/y/z/randomFileForImport.ts", `import type { ImportInterface0 } from "pkg0";\n`),
213213
timeouts: sys => sys.runQueuedTimeoutCallbacks(),
214214
},
215+
{
216+
caption: "modify randomFileForImport by adding unresolved import",
217+
edit: sys => sys.prependFile("/src/project/randomFileForImport.ts", `import type { ImportInterface1 } from "pkg1";\n`),
218+
timeouts: sys => sys.runQueuedTimeoutCallbacks(),
219+
},
220+
{
221+
caption: "modify b/randomFileForImport by adding unresolved import",
222+
edit: sys => sys.prependFile("/src/project/b/randomFileForImport.ts", `import type { ImportInterface1 } from "pkg1";\n`),
223+
timeouts: sys => sys.runQueuedTimeoutCallbacks(),
224+
},
225+
{
226+
caption: "modify c/ca/caa/randomFileForImport by adding unresolved import",
227+
edit: sys => sys.prependFile("/src/project/c/ca/caa/randomFileForImport.ts", `import type { ImportInterface1 } from "pkg1";\n`),
228+
timeouts: sys => sys.runQueuedTimeoutCallbacks(),
229+
},
230+
{
231+
caption: "modify d/da/daa/daaa/x/y/z/randomFileForImport by adding unresolved import",
232+
edit: sys => sys.prependFile("/src/project/d/da/daa/daaa/x/y/z/randomFileForImport.ts", `import type { ImportInterface1 } from "pkg1";\n`),
233+
timeouts: sys => sys.runQueuedTimeoutCallbacks(),
234+
},
235+
{
236+
caption: "modify e/ea/eaa/eaaa/x/y/z/randomFileForImport by adding unresolved import",
237+
edit: sys => sys.prependFile("/src/project/e/ea/eaa/eaaa/x/y/z/randomFileForImport.ts", `import type { ImportInterface1 } from "pkg1";\n`),
238+
timeouts: sys => sys.runQueuedTimeoutCallbacks(),
239+
},
240+
{
241+
caption: "add file for unresolved import and random edit",
242+
edit: sys => {
243+
sys.ensureFileOrFolder({ path: "/src/project/node_modules/pkg1/index.d.ts", content: getPkgImportContent("Import", 1) });
244+
sys.appendFile("/src/project/randomFileForImport.ts", `export const y = 10;`);
245+
},
246+
timeouts: sys => {
247+
sys.runQueuedTimeoutCallbacks(); // Failed lookups
248+
sys.runQueuedTimeoutCallbacks(); // actual update
249+
},
250+
},
215251
]
216252
});
217253
}

src/testRunner/unittests/tsserver/cacheResolutions.ts

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -292,6 +292,82 @@ describe("unittests:: tsserver:: cacheResolutions:: tsserverProjectSystem cachin
292292
});
293293
ts.server.updateProjectIfDirty(session.getProjectService().configuredProjects.get("/src/project/tsconfig.json")!);
294294

295+
session.logger.info("modify randomFileForImport by adding unresolved import");
296+
session.executeCommandSeq<ts.server.protocol.ChangeRequest>({
297+
command: ts.server.protocol.CommandTypes.Change,
298+
arguments: {
299+
file: "/src/project/randomFileForImport.ts",
300+
line: 1,
301+
offset: 1,
302+
endLine: 1,
303+
endOffset: 1,
304+
insertString: `import type { ImportInterface1 } from "pkg1";\n`,
305+
}
306+
});
307+
ts.server.updateProjectIfDirty(session.getProjectService().configuredProjects.get("/src/project/tsconfig.json")!);
308+
309+
session.logger.info("modify b/randomFileForImport by adding unresolved import");
310+
session.executeCommandSeq<ts.server.protocol.ChangeRequest>({
311+
command: ts.server.protocol.CommandTypes.Change,
312+
arguments: {
313+
file: "/src/project/b/randomFileForImport.ts",
314+
line: 1,
315+
offset: 1,
316+
endLine: 1,
317+
endOffset: 1,
318+
insertString: `import type { ImportInterface1 } from "pkg1";\n`,
319+
}
320+
});
321+
ts.server.updateProjectIfDirty(session.getProjectService().configuredProjects.get("/src/project/tsconfig.json")!);
322+
323+
session.logger.info("modify c/ca/caa/randomFileForImport by adding unresolved import");
324+
session.executeCommandSeq<ts.server.protocol.ChangeRequest>({
325+
command: ts.server.protocol.CommandTypes.Change,
326+
arguments: {
327+
file: "/src/project/c/ca/caa/randomFileForImport.ts",
328+
line: 1,
329+
offset: 1,
330+
endLine: 1,
331+
endOffset: 1,
332+
insertString: `import type { ImportInterface1 } from "pkg1";\n`,
333+
}
334+
});
335+
ts.server.updateProjectIfDirty(session.getProjectService().configuredProjects.get("/src/project/tsconfig.json")!);
336+
337+
session.logger.info("modify d/da/daa/daaa/x/y/z/randomFileForImport by adding unresolved import");
338+
session.executeCommandSeq<ts.server.protocol.ChangeRequest>({
339+
command: ts.server.protocol.CommandTypes.Change,
340+
arguments: {
341+
file: "/src/project/d/da/daa/daaa/x/y/z/randomFileForImport.ts",
342+
line: 1,
343+
offset: 1,
344+
endLine: 1,
345+
endOffset: 1,
346+
insertString: `import type { ImportInterface1 } from "pkg1";\n`,
347+
}
348+
});
349+
ts.server.updateProjectIfDirty(session.getProjectService().configuredProjects.get("/src/project/tsconfig.json")!);
350+
351+
session.logger.info("modify e/ea/eaa/eaaa/x/y/z/randomFileForImport by adding unresolved import");
352+
session.executeCommandSeq<ts.server.protocol.ChangeRequest>({
353+
command: ts.server.protocol.CommandTypes.Change,
354+
arguments: {
355+
file: "/src/project/e/ea/eaa/eaaa/x/y/z/randomFileForImport.ts",
356+
line: 1,
357+
offset: 1,
358+
endLine: 1,
359+
endOffset: 1,
360+
insertString: `import type { ImportInterface1 } from "pkg1";\n`,
361+
}
362+
});
363+
ts.server.updateProjectIfDirty(session.getProjectService().configuredProjects.get("/src/project/tsconfig.json")!);
364+
365+
session.logger.info("add file for unresolved import and random edit");
366+
host.ensureFileOrFolder({ path: "/src/project/node_modules/pkg1/index.d.ts", content: getPkgImportContent("Import", 1) });
367+
host.appendFile("/src/project/randomFileForImport.ts", `export const y = 10;`);
368+
host.runQueuedTimeoutCallbacks(); // Failed lookups
369+
host.runQueuedTimeoutCallbacks(); // actual update
370+
295371
baselineTsserverLogs("cacheResolutions", scenario, session);
296372
});
297373
}

0 commit comments

Comments
 (0)
0