Skip to content

Commit 2fb1363

Browse files
authored
Make "/home/src/workspaces/project" as default current directory without having to specify it for tsc tests (#59875)
1 parent f39fe7d commit 2fb1363

29 files changed

+88
-88
lines changed

src/testRunner/unittests/helpers/declarationEmit.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ function getSysForDeclarationEmitWithErrors(options: CompilerOptions, incrementa
3434
type: "module",
3535
main: "./distribution/index.js",
3636
}),
37-
}, { currentDirectory: "/home/src/workspaces/project" });
37+
});
3838
}
3939

4040
function getSysForDeclarationEmitWithErrorsWithOutFile(options: CompilerOptions, incremental: true | undefined) {
@@ -61,7 +61,7 @@ function getSysForDeclarationEmitWithErrorsWithOutFile(options: CompilerOptions,
6161
declare const ky: KyInstance;
6262
export default ky;
6363
`,
64-
}, { currentDirectory: "/home/src/workspaces/project" });
64+
});
6565
}
6666

6767
export function forEachDeclarationEmitWithErrorsScenario(

src/testRunner/unittests/helpers/noCheck.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ export function forEachTscScenarioWithNoCheck(buildType: "-b" | "-p") {
5353
...options,
5454
},
5555
}),
56-
}, { currentDirectory: "/home/src/workspaces/project" }),
56+
}),
5757
commandLineArgs: [...commandLineArgs, "--noCheck"],
5858
edits: [
5959
noChangeRun, // Should be no op

src/testRunner/unittests/helpers/noEmit.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ function forEachNoEmitChangesWorker(commandType: string[], compilerOptions: Comp
139139
"/home/src/workspaces/project/tsconfig.json": jsonToReadableText({
140140
compilerOptions: compilerOptionsToConfigJson(compilerOptions),
141141
}),
142-
}, { currentDirectory: "/home/src/workspaces/project" });
142+
});
143143
}
144144
}
145145

src/testRunner/unittests/helpers/virtualFileSystemWithWatch.ts

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -535,12 +535,20 @@ export class TestServerHost implements server.ServerHost, FormatDiagnosticsHost,
535535

536536
static createWatchedSystem(
537537
fileOrFolderList: FileOrFolderOrSymLinkMap | readonly FileOrFolderOrSymLink[],
538-
params:
539-
& Omit<TestServerHostCreationParameters, "typingsInstallerGlobalCacheLocation" | "typingsInstallerTypesRegistry">
540-
& { currentDirectory: string; },
538+
params?: Omit<TestServerHostCreationParameters, "typingsInstallerGlobalCacheLocation" | "typingsInstallerTypesRegistry">,
541539
): TestServerHost {
542-
ensureWatchablePath(params.currentDirectory, `currentDirectory: ${params.currentDirectory}`);
543-
return new TestServerHost(fileOrFolderList, params);
540+
const useDefaultCurrentDirectory = !params?.currentDirectory;
541+
if (useDefaultCurrentDirectory) (params ??= {}).currentDirectory = "/home/src/workspaces/project";
542+
else ensureWatchablePath(params!.currentDirectory!, `currentDirectory: ${params!.currentDirectory}`);
543+
const host = new TestServerHost(fileOrFolderList, params);
544+
if (useDefaultCurrentDirectory && fileOrFolderList !== emptyArray) {
545+
const folder = host.getRealFolder(host.toPath(host.currentDirectory))!;
546+
Debug.assert(
547+
folder.entries.length,
548+
`currentDirectory: Not specified, using default as "/home/src/workspaces/project". The files specified do not belong to it.`,
549+
);
550+
}
551+
return host;
544552
}
545553

546554
static createServerHost(

src/testRunner/unittests/tsbuild/commandLine.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ describe("unittests:: tsbuild:: commandLine::", () => {
5454
"/home/src/workspaces/project/b.ts": `export const b = 10;const bLocal = 10;`,
5555
"/home/src/workspaces/project/c.ts": `import { a } from "./a";export const c = a;`,
5656
"/home/src/workspaces/project/d.ts": `import { b } from "./b";export const d = b;`,
57-
}, { currentDirectory: "/home/src/workspaces/project" });
57+
});
5858
}
5959
function verify(options: ts.CompilerOptions) {
6060
verifyTsc({

src/testRunner/unittests/tsbuild/configFileErrors.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ describe("unittests:: tsbuild:: configFileErrors:: when tsconfig extends the mis
3333
{ path: "./tsconfig.second.json" },
3434
],
3535
}),
36-
}, { currentDirectory: "/home/src/workspaces/project" }),
36+
}),
3737
commandLineArgs: ["--b"],
3838
});
3939
});
@@ -57,7 +57,7 @@ describe("unittests:: tsbuild:: configFileErrors:: reports syntax errors in conf
5757
"b.ts"
5858
]
5959
}`,
60-
}, { currentDirectory: "/home/src/workspaces/project" }),
60+
}),
6161
commandLineArgs: ["--b"],
6262
edits: [
6363
{

src/testRunner/unittests/tsbuild/declarationEmit.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ export function fn4() {
124124
include: ["src"],
125125
references: [{ path: "../pkg1" }],
126126
}),
127-
}, { currentDirectory: "/home/src/workspaces/project" }),
127+
}),
128128
commandLineArgs: ["--b", "packages/pkg2/tsconfig.json", "--verbose"],
129129
});
130130

src/testRunner/unittests/tsbuild/emitDeclarationOnly.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ describe("unittests:: tsbuild:: on project with emitDeclarationOnly:: set to tru
4949
emitDeclarationOnly: true,
5050
},
5151
}),
52-
}, { currentDirectory: "/home/src/workspaces/project" });
52+
});
5353
}
5454

5555
function verifyEmitDeclarationOnly(disableMap?: true) {

src/testRunner/unittests/tsbuild/exitCodeOnBogusFile.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ describe("unittests:: tsbuild:: exitCodeOnBogusFile:: test exit code", () => {
77
verifyTsc({
88
scenario: "exitCodeOnBogusFile",
99
subScenario: `test exit code`,
10-
sys: () => TestServerHost.createWatchedSystem(emptyArray, { currentDirectory: "/home/src/workspaces/project" }),
10+
sys: () => TestServerHost.createWatchedSystem(emptyArray),
1111
commandLineArgs: ["-b", "bogus.json"],
1212
});
1313
});

src/testRunner/unittests/tsbuild/graphOrdering.ts

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,7 @@ describe("unittests:: tsbuild:: graphOrdering::", () => {
1919
];
2020

2121
before(() => {
22-
const sys = TestServerHost.createWatchedSystem(ts.emptyArray, {
23-
useCaseSensitiveFileNames: true,
24-
currentDirectory: "/home/src/workspaces/project",
25-
});
22+
const sys = TestServerHost.createWatchedSystem(ts.emptyArray, { useCaseSensitiveFileNames: true });
2623
host = ts.createSolutionBuilderHost(sys);
2724
writeProjects(sys, ["A", "B", "C", "D", "E", "F", "G", "H", "I", "J"], deps);
2825
});

0 commit comments

Comments
 (0)