Test for module resolutions from different directories

This commit is contained in:
Sheetal Nandi
2022-12-09 14:49:22 -08:00
parent 0132dc0b1d
commit d55ab98d59
16 changed files with 166263 additions and 0 deletions
@@ -8,6 +8,7 @@ import {
getFsWithMultipleProjects,
getFsWithNode16,
getFsWithOut,
getFsWithSameResolutionFromMultiplePlaces,
getPkgImportContent,
getPkgTypeRefContent,
} from "./cacheResolutionsHelper";
@@ -127,4 +128,32 @@ describe("unittests:: tsbuild:: cacheResolutions::", () => {
},
]
});
verifyTsc({
scenario: "cacheResolutions",
subScenario: "multiple places",
fs: getFsWithSameResolutionFromMultiplePlaces,
commandLineArgs: ["-b", "/src/project", "--explainFiles"],
baselineModulesAndTypeRefs: true,
edits: [
{
caption: "modify randomFileForImport by adding import",
edit: fs => prependText(fs, "/src/project/randomFileForImport.ts", `import type { ImportInterface0 } from "pkg0";\n`),
},
{
caption: "modify b/randomFileForImport by adding import",
edit: fs => prependText(fs, "/src/project/b/randomFileForImport.ts", `import type { ImportInterface0 } from "pkg0";\n`),
discrepancyExplanation: () => [
"Resolution is not reused in incremental which is TODO (shkamat)"
]
},
{
caption: "modify c/ca/caa/randomFileForImport by adding import",
edit: fs => prependText(fs, "/src/project/c/ca/caa/randomFileForImport.ts", `import type { ImportInterface0 } from "pkg0";\n`),
discrepancyExplanation: () => [
"Resolution is not reused in incremental which is TODO (shkamat)"
]
},
]
});
});
@@ -241,4 +241,101 @@ export function getServerHostWithMultipleProjectsWithBuild() {
const system = getServerHostWithMultipleProjects();
solutionBuildWithBaseline(system, ["/src/project"]);
return system;
}
function getFsMapWithSameResolutionFromMultiplePlaces(): { [path: string]: string; } {
return {
"/src/project/tsconfig.json": JSON.stringify({
compilerOptions: {
composite: true,
cacheResolutions: true,
traceResolution: true,
},
files: [
"fileWithImports.ts",
"randomFileForImport.ts",
"a/fileWithImports.ts",
"b/ba/fileWithImports.ts",
"b/randomFileForImport.ts",
"c/ca/fileWithImports.ts",
"c/ca/caa/randomFileForImport.ts",
"c/ca/caa/caaa/fileWithImports.ts",
"c/cb/fileWithImports.ts",
"d/da/daa/daaa/fileWithImports.ts",
"d/da/daa/fileWithImports.ts",
"d/da/fileWithImports.ts",
"e/ea/fileWithImports.ts",
"e/ea/eaa/fileWithImports.ts",
"e/ea/eaa/eaaa/fileWithImports.ts",
],
}),
"/src/project/fileWithImports.ts": Utils.dedent`
import type { ImportInterface0 } from "pkg0";
`,
"/src/project/randomFileForImport.ts": getRandomFileContent(),
"/src/project/a/fileWithImports.ts": Utils.dedent`
import type { ImportInterface0 } from "pkg0";
`,
"/src/project/b/ba/fileWithImports.ts": Utils.dedent`
import type { ImportInterface0 } from "pkg0";
`,
"/src/project/b/randomFileForImport.ts": getRandomFileContent(),
"/src/project/c/ca/fileWithImports.ts": Utils.dedent`
import type { ImportInterface0 } from "pkg0";
`,
"/src/project/c/ca/caa/randomFileForImport.ts": getRandomFileContent(),
"/src/project/c/ca/caa/caaa/fileWithImports.ts": Utils.dedent`
import type { ImportInterface0 } from "pkg0";
`,
"/src/project/c/cb/fileWithImports.ts": Utils.dedent`
import type { ImportInterface0 } from "pkg0";
`,
"/src/project/d/da/daa/daaa/fileWithImports.ts": Utils.dedent`
import type { ImportInterface0 } from "pkg0";
`,
"/src/project/d/da/daa/fileWithImports.ts": Utils.dedent`
import type { ImportInterface0 } from "pkg0";
`,
"/src/project/d/da/fileWithImports.ts": Utils.dedent`
import type { ImportInterface0 } from "pkg0";
`,
"/src/project/e/ea/fileWithImports.ts": Utils.dedent`
import type { ImportInterface0 } from "pkg0";
`,
"/src/project/e/ea/eaa/fileWithImports.ts": Utils.dedent`
import type { ImportInterface0 } from "pkg0";
`,
"/src/project/e/ea/eaa/eaaa/fileWithImports.ts": Utils.dedent`
import type { ImportInterface0 } from "pkg0";
`,
"/src/project/node_modules/pkg0/index.d.ts": getPkgImportContent("Import", 0),
};
}
export function getFsWithSameResolutionFromMultiplePlaces() {
return loadProjectFromFiles(getFsMapWithSameResolutionFromMultiplePlaces());
}
export function getWatchSystemWithSameResolutionFromMultiplePlaces() {
const system = createWatchedSystem(getFsMapWithSameResolutionFromMultiplePlaces(), { currentDirectory: "/src/project" });
system.ensureFileOrFolder(libFile);
return system;
}
export function getServerHostWithSameResolutionFromMultiplePlaces() {
const system = createServerHost(getFsMapWithSameResolutionFromMultiplePlaces(), { currentDirectory: "/src/project" });
system.writeFile(libFile.path, libFile.content);
return system;
}
export function getWatchSystemWithSameResolutionFromMultiplePlacesWithBuild() {
const system = getWatchSystemWithSameResolutionFromMultiplePlaces();
solutionBuildWithBaseline(system, ["/src/project"]);
return system;
}
export function getServerHostWithSameResolutionFromMultiplePlacesWithBuild() {
const system = getServerHostWithSameResolutionFromMultiplePlaces();
solutionBuildWithBaseline(system, ["/src/project"]);
return system;
}
@@ -10,6 +10,8 @@ import {
getWatchSystemWithNode16WithBuild,
getWatchSystemWithOut,
getWatchSystemWithOutWithBuild,
getWatchSystemWithSameResolutionFromMultiplePlaces,
getWatchSystemWithSameResolutionFromMultiplePlacesWithBuild,
} from "../tsbuild/cacheResolutionsHelper";
import {
verifyTscWatch,
@@ -152,4 +154,35 @@ describe("unittests:: tsbuildWatch:: watchMode:: cacheResolutions::", () => {
});
}
});
describe("resolution reuse from multiple places", () => {
verifyTscWatchMultiPlaces("multiple places", getWatchSystemWithSameResolutionFromMultiplePlaces);
verifyTscWatchMultiPlaces("multiple places already built", getWatchSystemWithSameResolutionFromMultiplePlacesWithBuild);
function verifyTscWatchMultiPlaces(subScenario: string, sys: () => TestServerHost) {
verifyTscWatch({
scenario: "cacheResolutions",
subScenario,
sys,
commandLineArgs: ["-b", "-w", "--explainFiles"],
baselineModulesAndTypeRefs: true,
edits: [
{
caption: "modify randomFileForImport by adding import",
edit: sys => sys.prependFile("/src/project/randomFileForImport.ts", `import type { ImportInterface0 } from "pkg0";\n`),
timeouts: sys => sys.runQueuedTimeoutCallbacks(),
},
{
caption: "modify b/randomFileForImport by adding import",
edit: sys => sys.prependFile("/src/project/b/randomFileForImport.ts", `import type { ImportInterface0 } from "pkg0";\n`),
timeouts: sys => sys.runQueuedTimeoutCallbacks(),
},
{
caption: "modify c/ca/caa/randomFileForImport by adding import",
edit: sys => sys.prependFile("/src/project/c/ca/caa/randomFileForImport.ts", `import type { ImportInterface0 } from "pkg0";\n`),
timeouts: sys => sys.runQueuedTimeoutCallbacks(),
},
]
});
}
});
});
@@ -6,6 +6,7 @@ import {
import {
getFsWithNode16,
getFsWithOut,
getFsWithSameResolutionFromMultiplePlaces,
getPkgImportContent,
getPkgTypeRefContent,
} from "../tsbuild/cacheResolutionsHelper";
@@ -223,4 +224,32 @@ describe("unittests:: tsc:: cacheResolutions::", () => {
edit: fs => prependText(fs, "/src/project/randomFileForImport.ts", `import * as me from "@this/package";\n`),
}],
});
verifyTsc({
scenario: "cacheResolutions",
subScenario: "multiple places",
fs: getFsWithSameResolutionFromMultiplePlaces,
commandLineArgs: ["-p", "/src/project", "--explainFiles"],
baselineModulesAndTypeRefs: true,
edits: [
{
caption: "modify randomFileForImport by adding import",
edit: fs => prependText(fs, "/src/project/randomFileForImport.ts", `import type { ImportInterface0 } from "pkg0";\n`),
},
{
caption: "modify b/randomFileForImport by adding import",
edit: fs => prependText(fs, "/src/project/b/randomFileForImport.ts", `import type { ImportInterface0 } from "pkg0";\n`),
discrepancyExplanation: () => [
"Resolution is not reused in incremental which is TODO (shkamat)"
]
},
{
caption: "modify c/ca/caa/randomFileForImport by adding import",
edit: fs => prependText(fs, "/src/project/c/ca/caa/randomFileForImport.ts", `import type { ImportInterface0 } from "pkg0";\n`),
discrepancyExplanation: () => [
"Resolution is not reused in incremental which is TODO (shkamat)"
]
},
]
});
});
@@ -6,6 +6,8 @@ import {
getWatchSystemWithNode16WithBuild,
getWatchSystemWithOut,
getWatchSystemWithOutWithBuild,
getWatchSystemWithSameResolutionFromMultiplePlaces,
getWatchSystemWithSameResolutionFromMultiplePlacesWithBuild,
} from "../tsbuild/cacheResolutionsHelper";
import {
TestServerHost,
@@ -162,4 +164,35 @@ describe("unittests:: tsc-watch:: cacheResolutions::", () => {
});
}
});
describe("resolution reuse from multiple places", () => {
verifyTscWatchMultiPlaces("multiple places", getWatchSystemWithSameResolutionFromMultiplePlaces);
verifyTscWatchMultiPlaces("multiple places already built", getWatchSystemWithSameResolutionFromMultiplePlacesWithBuild);
function verifyTscWatchMultiPlaces(subScenario: string, sys: () => TestServerHost) {
verifyTscWatch({
scenario: "cacheResolutions",
subScenario,
sys,
commandLineArgs: ["-w", "--explainFiles"],
baselineModulesAndTypeRefs: true,
edits: [
{
caption: "modify randomFileForImport by adding import",
edit: sys => sys.prependFile("/src/project/randomFileForImport.ts", `import type { ImportInterface0 } from "pkg0";\n`),
timeouts: sys => sys.runQueuedTimeoutCallbacks(),
},
{
caption: "modify b/randomFileForImport by adding import",
edit: sys => sys.prependFile("/src/project/b/randomFileForImport.ts", `import type { ImportInterface0 } from "pkg0";\n`),
timeouts: sys => sys.runQueuedTimeoutCallbacks(),
},
{
caption: "modify c/ca/caa/randomFileForImport by adding import",
edit: sys => sys.prependFile("/src/project/c/ca/caa/randomFileForImport.ts", `import type { ImportInterface0 } from "pkg0";\n`),
timeouts: sys => sys.runQueuedTimeoutCallbacks(),
},
]
});
}
});
});
@@ -25,6 +25,8 @@ import {
getServerHostWithNode16WithBuild,
getServerHostWithOut,
getServerHostWithOutWithBuild,
getServerHostWithSameResolutionFromMultiplePlaces,
getServerHostWithSameResolutionFromMultiplePlacesWithBuild,
} from "../tsbuild/cacheResolutionsHelper";
describe("unittests:: tsserver:: cacheResolutions:: tsserverProjectSystem caching module resolutions option", () => {
@@ -197,6 +199,62 @@ describe("unittests:: tsserver:: cacheResolutions:: tsserverProjectSystem cachin
}
});
describe("resolution reuse from multiple places", () => {
verifyTsserverMultiPlaces("multiple places not built", getServerHostWithSameResolutionFromMultiplePlaces);
verifyTsserverMultiPlaces("multiple places", getServerHostWithSameResolutionFromMultiplePlacesWithBuild);
function verifyTsserverMultiPlaces(scenario: string, createHost: () => TestServerHost) {
it(scenario, () => {
const host = fakes.patchHostForBuildInfoReadWrite(createHost());
const session = createSession(host, { logger: createLoggerWithInMemoryLogs(host) });
openFilesForSession(["/src/project/randomFileForImport.ts", "/src/project/b/randomFileForImport.ts", "/src/project/c/ca/caa/randomFileForImport.ts"], session);
session.logger.info("modify randomFileForImport by adding import");
session.executeCommandSeq<ts.server.protocol.ChangeRequest>({
command: ts.server.protocol.CommandTypes.Change,
arguments: {
file: "/src/project/randomFileForImport.ts",
line: 1,
offset: 1,
endLine: 1,
endOffset: 1,
insertString: `import type { ImportInterface0 } from "pkg0";\n`,
}
});
ts.server.updateProjectIfDirty(session.getProjectService().configuredProjects.get("/src/project/tsconfig.json")!);
session.logger.info("modify b/randomFileForImport by adding import");
session.executeCommandSeq<ts.server.protocol.ChangeRequest>({
command: ts.server.protocol.CommandTypes.Change,
arguments: {
file: "/src/project/b/randomFileForImport.ts",
line: 1,
offset: 1,
endLine: 1,
endOffset: 1,
insertString: `import type { ImportInterface0 } from "pkg0";\n`,
}
});
ts.server.updateProjectIfDirty(session.getProjectService().configuredProjects.get("/src/project/tsconfig.json")!);
session.logger.info("modify c/ca/caa/randomFileForImport by adding import");
session.executeCommandSeq<ts.server.protocol.ChangeRequest>({
command: ts.server.protocol.CommandTypes.Change,
arguments: {
file: "/src/project/c/ca/caa/randomFileForImport.ts",
line: 1,
offset: 1,
endLine: 1,
endOffset: 1,
insertString: `import type { ImportInterface0 } from "pkg0";\n`,
}
});
ts.server.updateProjectIfDirty(session.getProjectService().configuredProjects.get("/src/project/tsconfig.json")!);
baselineTsserverLogs("cacheResolutions", scenario, session);
});
}
});
describe("different projects", () => {
describe("on sample project", () => {
function cacheResolutions(file: File) {
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because it is too large Load Diff
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because it is too large Load Diff
File diff suppressed because one or more lines are too long