Updates to type reference directive resolution and module resolution when failed (#51715)

This commit is contained in:
Sheetal Nandi
2023-03-01 10:57:47 -08:00
committed by GitHub
parent d8ba799f89
commit 9c5b09cd21
79 changed files with 870 additions and 288 deletions

View File

@@ -970,28 +970,36 @@ declare const eval: any`
]
});
verifyTscWatch({
scenario,
subScenario: "types should load from config file path if config exists",
commandLineArgs: ["-w", "-p", configFilePath],
sys: () => {
const f1 = {
path: "/a/b/app.ts",
content: "let x = 1"
};
const config = {
path: configFilePath,
content: JSON.stringify({ compilerOptions: { types: ["node"], typeRoots: [] } })
};
const node = {
path: "/a/b/node_modules/@types/node/index.d.ts",
content: "declare var process: any"
};
const cwd = {
path: "/a/c"
};
return createWatchedSystem([f1, config, node, cwd, libFile], { currentDirectory: cwd.path });
},
describe("types from config file", () => {
function verifyTypesLoad(includeTypeRoots: boolean) {
verifyTscWatch({
scenario,
subScenario: includeTypeRoots ?
"types should not load from config file path if config exists but does not specifies typeRoots" :
"types should load from config file path if config exists",
commandLineArgs: ["-w", "-p", configFilePath],
sys: () => {
const f1 = {
path: "/a/b/app.ts",
content: "let x = 1"
};
const config = {
path: configFilePath,
content: JSON.stringify({ compilerOptions: { types: ["node"], typeRoots: includeTypeRoots ? [] : undefined } })
};
const node = {
path: "/a/b/node_modules/@types/node/index.d.ts",
content: "declare var process: any"
};
const cwd = {
path: "/a/c"
};
return createWatchedSystem([f1, config, node, cwd, libFile], { currentDirectory: cwd.path });
},
});
}
verifyTypesLoad(/*includeTypeRoots*/ false);
verifyTypesLoad(/*includeTypeRoots*/ true);
});
verifyTscWatch({

View File

@@ -345,27 +345,32 @@ describe("unittests:: tsserver:: resolutionCache:: tsserverProjectSystem rename
projectService.checkNumberOfProjects({ configuredProjects: 1 });
});
it("types should load from config file path if config exists", () => {
const f1 = {
path: "/a/b/app.ts",
content: "let x = 1"
};
const config = {
path: "/a/b/tsconfig.json",
content: JSON.stringify({ compilerOptions: { types: ["node"], typeRoots: [] } })
};
const node = {
path: "/a/b/node_modules/@types/node/index.d.ts",
content: "declare var process: any"
};
const cwd = {
path: "/a/c"
};
const host = createServerHost([f1, config, node, cwd], { currentDirectory: cwd.path });
const projectService = createProjectService(host);
projectService.openClientFile(f1.path);
projectService.checkNumberOfProjects({ configuredProjects: 1 });
checkProjectActualFiles(configuredProjectAt(projectService, 0), [f1.path, node.path, config.path]);
describe("types from config file", () => {
function verifyTypesLoad(subScenario: string, includeTypeRoots: boolean) {
it(subScenario, () => {
const f1 = {
path: "/a/b/app.ts",
content: "let x = 1"
};
const config = {
path: "/a/b/tsconfig.json",
content: JSON.stringify({ compilerOptions: { types: ["node"], typeRoots: includeTypeRoots ? [] : undefined } })
};
const node = {
path: "/a/b/node_modules/@types/node/index.d.ts",
content: "declare var process: any"
};
const cwd = {
path: "/a/c"
};
const host = createServerHost([f1, config, node, cwd], { currentDirectory: cwd.path });
const projectService = createProjectService(host, { logger: createLoggerWithInMemoryLogs(host) });
projectService.openClientFile(f1.path);
baselineTsserverLogs("resolutionCache", subScenario, projectService);
});
}
verifyTypesLoad("types should load from config file path if config exists", /*includeTypeRoots*/ false);
verifyTypesLoad("types should not load from config file path if config exists but does not specifies typeRoots", /*includeTypeRoots*/ true);
});
});