Test transitive references in folders side by side so that later we can add tsserver tests as well
This commit is contained in:
parent
3e67cf43b0
commit
2fb11d8530
|
@ -780,7 +780,7 @@ namespace ts {
|
|||
(hostSourceFileInfo as FilePresentOnHost).fileWatcher.close();
|
||||
}
|
||||
sourceFilesCache.delete(oldSourceFile.resolvedPath);
|
||||
if (oldSourceFile.resolvedPath === oldSourceFile.path || !hasSourceFileByPath) {
|
||||
if (!hasSourceFileByPath) {
|
||||
resolutionCache.removeResolutionsOfFile(oldSourceFile.path);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -925,8 +925,8 @@ namespace ts.server {
|
|||
const newFile = this.program.getSourceFileByPath(f.resolvedPath);
|
||||
if (!newFile || (f.resolvedPath === f.path && newFile.resolvedPath !== f.path)) {
|
||||
// new program does not contain this file - detach it from the project
|
||||
// - remove resolutions only if this is undirected file or doesnt have source file with the path in new program
|
||||
this.detachScriptInfoFromProject(f.fileName, f.path !== f.resolvedPath && !!this.program.getSourceFileByPath(f.path));
|
||||
// - remove resolutions only if the new program doesnt contain source file by the path (not resolvedPath since path is used for resolution)
|
||||
this.detachScriptInfoFromProject(f.fileName, !!this.program.getSourceFileByPath(f.path));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -408,9 +408,9 @@ let x: string = 10;`);
|
|||
|
||||
describe("tsc-watch works with project references", () => {
|
||||
describe("invoking when references are already built", () => {
|
||||
function verifyWatchesOfProject(host: WatchedSystem, expectedWatchedFiles: ReadonlyArray<string>, expectedWatchedDirectoriesRecursive: ReadonlyArray<string>) {
|
||||
function verifyWatchesOfProject(host: WatchedSystem, expectedWatchedFiles: ReadonlyArray<string>, expectedWatchedDirectoriesRecursive: ReadonlyArray<string>, expectedWatchedDirectories?: ReadonlyArray<string>) {
|
||||
checkWatchedFilesDetailed(host, expectedWatchedFiles, 1);
|
||||
checkWatchedDirectories(host, emptyArray, /*recursive*/ false);
|
||||
checkWatchedDirectoriesDetailed(host, expectedWatchedDirectories || emptyArray, 1, /*recursive*/ false);
|
||||
checkWatchedDirectoriesDetailed(host, expectedWatchedDirectoriesRecursive, 1, /*recursive*/ true);
|
||||
}
|
||||
|
||||
|
@ -508,23 +508,80 @@ export function gfoo() {
|
|||
|
||||
describe("on transitive references", () => {
|
||||
const project = "transitiveReferences";
|
||||
const aTs = getFileFromProject(project, "a.ts");
|
||||
const bTs = getFileFromProject(project, "b.ts");
|
||||
const cTs = getFileFromProject(project, "c.ts");
|
||||
|
||||
const configToBuild = "tsconfig.c.json";
|
||||
const aTsconfig = getFileFromProject(project, "tsconfig.a.json");
|
||||
const bTsconfig = getFileFromProject(project, "tsconfig.b.json");
|
||||
const cTsconfig = getFileFromProject(project, configToBuild);
|
||||
const aTsFile = getFileFromProject(project, "a.ts");
|
||||
const bTsFile = getFileFromProject(project, "b.ts");
|
||||
const cTsFile = getFileFromProject(project, "c.ts");
|
||||
const aTsconfigFile = getFileFromProject(project, "tsconfig.a.json");
|
||||
const bTsconfigFile = getFileFromProject(project, "tsconfig.b.json");
|
||||
const cTsconfigFile = getFileFromProject(project, "tsconfig.c.json");
|
||||
const refs = getFileFromProject(project, "refs/a.d.ts");
|
||||
|
||||
function getRootFile(multiFolder: boolean, fileFromDisk: File, multiFolderPath: string): File {
|
||||
return multiFolder ? {
|
||||
path: getFilePathInProject(project, multiFolderPath),
|
||||
content: fileFromDisk.content
|
||||
// Replace the relative imports
|
||||
.replace("./", "../")
|
||||
} : fileFromDisk;
|
||||
}
|
||||
|
||||
function getTsConfigFile(multiFolder: boolean, fileFromDisk: File, folder: string): File {
|
||||
if (!multiFolder) return fileFromDisk;
|
||||
|
||||
return {
|
||||
path: getFilePathInProject(project, `${folder}/tsconfig.json`),
|
||||
content: fileFromDisk.content
|
||||
// Replace files array
|
||||
.replace(`${folder}.ts`, "index.ts")
|
||||
// Replace path mappings
|
||||
.replace("./*", "../*")
|
||||
.replace("./refs", "../refs")
|
||||
// Replace references
|
||||
.replace("tsconfig.a.json", "../a")
|
||||
.replace("tsconfig.b.json", "../b")
|
||||
};
|
||||
}
|
||||
|
||||
// function writeFile(file: File) {
|
||||
// Harness.IO.writeFile(file.path.replace(projectsLocation, "c:/temp"), file.content);
|
||||
// }
|
||||
|
||||
function verifyTransitiveReferences(multiFolder: boolean) {
|
||||
const aTs = getRootFile(multiFolder, aTsFile, "a/index.ts");
|
||||
const bTs = getRootFile(multiFolder, bTsFile, "b/index.ts");
|
||||
const cTs = getRootFile(multiFolder, cTsFile, "c/index.ts");
|
||||
|
||||
const configToBuild = multiFolder ? "c/tsconfig.json" : "tsconfig.c.json";
|
||||
const aTsconfig = getTsConfigFile(multiFolder, aTsconfigFile, "a");
|
||||
const bTsconfig = getTsConfigFile(multiFolder, bTsconfigFile, "b");
|
||||
const cTsconfig = getTsConfigFile(multiFolder, cTsconfigFile, "c");
|
||||
|
||||
// if (multiFolder) {
|
||||
// writeFile(aTs);
|
||||
// writeFile(bTs);
|
||||
// writeFile(cTs);
|
||||
// writeFile(aTsconfig);
|
||||
// writeFile(bTsconfig);
|
||||
// writeFile(cTsconfig);
|
||||
// }
|
||||
|
||||
const allFiles = [libFile, aTs, bTs, cTs, aTsconfig, bTsconfig, cTsconfig, refs];
|
||||
const aDts = dtsFile("a"), bDts = dtsFile("b");
|
||||
const expectedFiles = [jsFile("a"), aDts, jsFile("b"), bDts, jsFile("c")];
|
||||
const aDts = dtsFile(multiFolder ? "a/index" : "a"), bDts = dtsFile(multiFolder ? "b/index" : "b");
|
||||
const expectedFiles = [jsFile(multiFolder ? "a/index" : "a"), aDts, jsFile(multiFolder ? "b/index" : "b"), bDts, jsFile(multiFolder ? "c/index" : "c")];
|
||||
const expectedProgramFiles = [cTs.path, libFile.path, aDts, refs.path, bDts];
|
||||
const expectedWatchedFiles = expectedProgramFiles.concat(cTsconfig.path, bTsconfig.path, aTsconfig.path).map(s => s.toLowerCase());
|
||||
const expectedWatchedDirectories = multiFolder ? [
|
||||
getProjectPath(project).toLowerCase() // watches for directories created for resolution of b
|
||||
] : emptyArray;
|
||||
const nrefsPath = multiFolder ? ["../nrefs/*"] : ["./nrefs/*"];
|
||||
const expectedWatchedDirectoriesRecursive = [
|
||||
getFilePathInProject(project, "refs").toLowerCase(), // Failed lookup since refs/a.ts does not exist
|
||||
...projectSystem.getTypeRootsFromLocation(getProjectPath(project).toLowerCase())];
|
||||
...(multiFolder ? [
|
||||
getFilePathInProject(project, "a"), // Failed to package json
|
||||
getFilePathInProject(project, "b"), // Failed to package json
|
||||
] : []),
|
||||
getFilePathInProject(project, "refs"), // Failed lookup since refs/a.ts does not exist
|
||||
...projectSystem.getTypeRootsFromLocation(multiFolder ? getFilePathInProject(project, "c") : getProjectPath(project))
|
||||
].map(s => s.toLowerCase());
|
||||
|
||||
function jsFile(extensionLessFile: string) {
|
||||
return getFilePathInProject(project, `${extensionLessFile}.js`);
|
||||
|
@ -544,7 +601,7 @@ export function gfoo() {
|
|||
|
||||
function verifyProgram(host: WatchedSystem, watch: () => BuilderProgram) {
|
||||
checkProgramActualFiles(watch().getProgram(), expectedProgramFiles);
|
||||
verifyWatchesOfProject(host, expectedWatchedFiles, expectedWatchedDirectoriesRecursive);
|
||||
verifyWatchesOfProject(host, expectedWatchedFiles, expectedWatchedDirectoriesRecursive, expectedWatchedDirectories);
|
||||
verifyDependencies(watch, aDts, [aDts]);
|
||||
verifyDependencies(watch, bDts, [bDts, aDts]);
|
||||
verifyDependencies(watch, refs.path, [refs.path]);
|
||||
|
@ -581,7 +638,7 @@ export function gfoo() {
|
|||
};
|
||||
const cTsConfigJson = JSON.parse(cTsconfig.content);
|
||||
host.ensureFileOrFolder(nrefs);
|
||||
cTsConfigJson.compilerOptions.paths = { "@ref/*": ["./nrefs/*"] };
|
||||
cTsConfigJson.compilerOptions.paths = { "@ref/*": nrefsPath };
|
||||
host.writeFile(cTsconfig.path, JSON.stringify(cTsConfigJson));
|
||||
|
||||
host.checkTimeoutQueueLengthAndRun(1);
|
||||
|
@ -589,7 +646,7 @@ export function gfoo() {
|
|||
|
||||
const nrefReplacer = (f: string) => f.replace("refs", "nrefs");
|
||||
checkProgramActualFiles(watch().getProgram(), expectedProgramFiles.map(nrefReplacer));
|
||||
verifyWatchesOfProject(host, expectedWatchedFiles.map(nrefReplacer), expectedWatchedDirectoriesRecursive.map(nrefReplacer));
|
||||
verifyWatchesOfProject(host, expectedWatchedFiles.map(nrefReplacer), expectedWatchedDirectoriesRecursive.map(nrefReplacer), expectedWatchedDirectories);
|
||||
verifyDependencies(watch, aDts, [aDts]);
|
||||
verifyDependencies(watch, bDts, [bDts, aDts]);
|
||||
verifyDependencies(watch, nrefs.path, [nrefs.path]);
|
||||
|
@ -611,7 +668,7 @@ export function gfoo() {
|
|||
};
|
||||
const bTsConfigJson = JSON.parse(bTsconfig.content);
|
||||
host.ensureFileOrFolder(nrefs);
|
||||
bTsConfigJson.compilerOptions.paths = { "@ref/*": ["./nrefs/*"] };
|
||||
bTsConfigJson.compilerOptions.paths = { "@ref/*": nrefsPath };
|
||||
host.writeFile(bTsconfig.path, JSON.stringify(bTsConfigJson));
|
||||
|
||||
host.checkTimeoutQueueLengthAndRun(1);
|
||||
|
@ -619,7 +676,11 @@ export function gfoo() {
|
|||
|
||||
const expectedProgramFiles = [cTs.path, bDts, nrefs.path, refs.path, libFile.path];
|
||||
checkProgramActualFiles(watch().getProgram(), expectedProgramFiles);
|
||||
verifyWatchesOfProject(host, expectedProgramFiles.concat(cTsconfig.path, bTsconfig.path, aTsconfig.path).map(s => s.toLowerCase()), expectedWatchedDirectoriesRecursive.concat(getFilePathInProject(project, "nrefs").toLowerCase()));
|
||||
const [, ...expectedWatchedDirectoriesRecursiveWithoutA] = expectedWatchedDirectoriesRecursive; // Not looking in a folder for resolution in multi folder scenario
|
||||
verifyWatchesOfProject(host,
|
||||
expectedProgramFiles.concat(cTsconfig.path, bTsconfig.path, aTsconfig.path).map(s => s.toLowerCase()),
|
||||
(multiFolder ? expectedWatchedDirectoriesRecursiveWithoutA : expectedWatchedDirectoriesRecursive).concat(getFilePathInProject(project, "nrefs").toLowerCase()),
|
||||
expectedWatchedDirectories);
|
||||
verifyDependencies(watch, nrefs.path, [nrefs.path]);
|
||||
verifyDependencies(watch, bDts, [bDts, nrefs.path]);
|
||||
verifyDependencies(watch, refs.path, [refs.path]);
|
||||
|
@ -641,12 +702,16 @@ export function gfoo() {
|
|||
|
||||
host.checkTimeoutQueueLengthAndRun(1);
|
||||
checkOutputErrorsIncremental(host, [
|
||||
"tsconfig.c.json(9,21): error TS6053: File '/user/username/projects/transitiveReferences/tsconfig.b.json' not found.\n"
|
||||
`${multiFolder ? "c/tsconfig.json" : "tsconfig.c.json"}(9,21): error TS6053: File '/user/username/projects/transitiveReferences/${multiFolder ? "b" : "tsconfig.b.json"}' not found.\n`
|
||||
]);
|
||||
|
||||
const expectedProgramFiles = [cTs.path, bTs.path, refs.path, libFile.path];
|
||||
checkProgramActualFiles(watch().getProgram(), expectedProgramFiles);
|
||||
verifyWatchesOfProject(host, expectedProgramFiles.concat(cTsconfig.path, bTsconfig.path).map(s => s.toLowerCase()), expectedWatchedDirectoriesRecursive);
|
||||
const [, ...expectedWatchedDirectoriesRecursiveWithoutA] = expectedWatchedDirectoriesRecursive; // Not looking in a folder for resolution in multi folder scenario
|
||||
verifyWatchesOfProject(host,
|
||||
expectedProgramFiles.concat(cTsconfig.path, bTsconfig.path).map(s => s.toLowerCase()),
|
||||
multiFolder ? expectedWatchedDirectoriesRecursiveWithoutA : expectedWatchedDirectoriesRecursive,
|
||||
expectedWatchedDirectories);
|
||||
verifyDependencies(watch, bTs.path, [bTs.path, refs.path]);
|
||||
verifyDependencies(watch, refs.path, [refs.path]);
|
||||
verifyDependencies(watch, cTs.path, [cTs.path, refs.path, bTs.path]);
|
||||
|
@ -664,11 +729,11 @@ export function gfoo() {
|
|||
|
||||
host.checkTimeoutQueueLengthAndRun(1);
|
||||
checkOutputErrorsIncremental(host, [
|
||||
"tsconfig.b.json(10,21): error TS6053: File '/user/username/projects/transitiveReferences/tsconfig.a.json' not found.\n"
|
||||
`${multiFolder ? "b/tsconfig.json" : "tsconfig.b.json"}(10,21): error TS6053: File '/user/username/projects/transitiveReferences/${ multiFolder ? "a" : "tsconfig.a.json"}' not found.\n`
|
||||
]);
|
||||
|
||||
checkProgramActualFiles(watch().getProgram(), expectedProgramFiles.map(s => s.replace(aDts, aTs.path)));
|
||||
verifyWatchesOfProject(host, expectedWatchedFiles.map(s => s.replace(aDts.toLowerCase(), aTs.path.toLocaleLowerCase())), expectedWatchedDirectoriesRecursive);
|
||||
verifyWatchesOfProject(host, expectedWatchedFiles.map(s => s.replace(aDts.toLowerCase(), aTs.path.toLocaleLowerCase())), expectedWatchedDirectoriesRecursive, expectedWatchedDirectories);
|
||||
verifyDependencies(watch, aTs.path, [aTs.path]);
|
||||
verifyDependencies(watch, bDts, [bDts, aTs.path]);
|
||||
verifyDependencies(watch, refs.path, [refs.path]);
|
||||
|
@ -680,6 +745,14 @@ export function gfoo() {
|
|||
checkOutputErrorsIncremental(host, emptyArray);
|
||||
verifyProgram(host, watch);
|
||||
});
|
||||
}
|
||||
|
||||
describe("when config files are side by side", () => {
|
||||
verifyTransitiveReferences(/*multiFolder*/ false);
|
||||
});
|
||||
describe("when config files are in side by side folders", () => {
|
||||
verifyTransitiveReferences(/*multiFolder*/ true);
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
|
Loading…
Reference in a new issue