Skip to content

Commit c7bbb97

Browse files
committed
Accept map of file content or file or symlink or folder
1 parent 460f2a8 commit c7bbb97

File tree

4 files changed

+45
-45
lines changed

4 files changed

+45
-45
lines changed

src/harness/virtualFileSystemWithWatch.ts

+26-13
Original file line numberDiff line numberDiff line change
@@ -30,11 +30,11 @@ interface Array<T> { length: number; [n: number]: T; }`
3030
inodeWatching?: boolean;
3131
}
3232

33-
export function createWatchedSystem(fileOrFolderList: readonly FileOrFolderOrSymLink[], params?: TestServerHostCreationParameters): TestServerHost {
33+
export function createWatchedSystem(fileOrFolderList: FileOrFolderOrSymLinkMap | readonly FileOrFolderOrSymLink[], params?: TestServerHostCreationParameters): TestServerHost {
3434
return new TestServerHost(fileOrFolderList, params);
3535
}
3636

37-
export function createServerHost(fileOrFolderList: readonly FileOrFolderOrSymLink[], params?: TestServerHostCreationParameters): TestServerHost {
37+
export function createServerHost(fileOrFolderList: FileOrFolderOrSymLinkMap | readonly FileOrFolderOrSymLink[], params?: TestServerHostCreationParameters): TestServerHost {
3838
const host = new TestServerHost(fileOrFolderList, params);
3939
// Just like sys, patch the host to use writeFile
4040
patchWriteFileEnsuringDirectory(host);
@@ -59,6 +59,9 @@ interface Array<T> { length: number; [n: number]: T; }`
5959
}
6060

6161
export type FileOrFolderOrSymLink = File | Folder | SymLink;
62+
export interface FileOrFolderOrSymLinkMap {
63+
[path: string]: string | Omit<FileOrFolderOrSymLink, "path">;
64+
}
6265
export function isFile(fileOrFolderOrSymLink: FileOrFolderOrSymLink): fileOrFolderOrSymLink is File {
6366
return isString((fileOrFolderOrSymLink as File).content);
6467
}
@@ -289,7 +292,6 @@ interface Array<T> { length: number; [n: number]: T; }`
289292
useCaseSensitiveFileNames: boolean;
290293
executingFilePath: string;
291294
currentDirectory: string;
292-
fileOrFolderorSymLinkList: readonly FileOrFolderOrSymLink[];
293295
newLine?: string;
294296
useWindowsStylePaths?: boolean;
295297
environmentVariables?: ESMap<string, string>;
@@ -326,7 +328,7 @@ interface Array<T> { length: number; [n: number]: T; }`
326328
private readonly inodes?: ESMap<Path, number>;
327329
watchDirectory: HostWatchDirectory;
328330
constructor(
329-
fileOrFolderorSymLinkList: readonly FileOrFolderOrSymLink[],
331+
fileOrFolderorSymLinkList: FileOrFolderOrSymLinkMap | readonly FileOrFolderOrSymLink[],
330332
{
331333
useCaseSensitiveFileNames, executingFilePath, currentDirectory,
332334
newLine, windowsStyleRoot, environmentVariables,
@@ -415,16 +417,27 @@ interface Array<T> { length: number; [n: number]: T; }`
415417
return new Date(this.time);
416418
}
417419

418-
private reloadFS(fileOrFolderOrSymLinkList: readonly FileOrFolderOrSymLink[]) {
420+
private reloadFS(fileOrFolderOrSymLinkList: FileOrFolderOrSymLinkMap | readonly FileOrFolderOrSymLink[]) {
419421
Debug.assert(this.fs.size === 0);
420-
const filesOrFoldersToLoad: readonly FileOrFolderOrSymLink[] = !this.windowsStyleRoot ? fileOrFolderOrSymLinkList :
421-
fileOrFolderOrSymLinkList.map<FileOrFolderOrSymLink>(f => {
422-
const result = clone(f);
423-
result.path = this.getHostSpecificPath(f.path);
424-
return result;
425-
});
426-
for (const fileOrDirectory of filesOrFoldersToLoad) {
427-
this.ensureFileOrFolder(fileOrDirectory);
422+
if (isArray(fileOrFolderOrSymLinkList)) {
423+
fileOrFolderOrSymLinkList.forEach(f => this.ensureFileOrFolder(!this.windowsStyleRoot ?
424+
f :
425+
{ ...f, path: this.getHostSpecificPath(f.path) }
426+
));
427+
}
428+
else {
429+
for (const key in fileOrFolderOrSymLinkList) {
430+
if (hasProperty(fileOrFolderOrSymLinkList, key)) {
431+
const path = this.getHostSpecificPath(key);
432+
const value = fileOrFolderOrSymLinkList[key];
433+
if (isString(value)) {
434+
this.ensureFileOrFolder({ path, content: value });
435+
}
436+
else {
437+
this.ensureFileOrFolder({ path, ...value });
438+
}
439+
}
440+
}
428441
}
429442
}
430443

src/testRunner/unittests/tscWatch/emit.ts

+6-15
Original file line numberDiff line numberDiff line change
@@ -6,21 +6,12 @@ namespace ts.tscWatch {
66
scenario,
77
subScenario: `emit with outFile or out setting/${subScenario}`,
88
commandLineArgs: ["--w", "-p", "/a/tsconfig.json"],
9-
sys: () => {
10-
const config: File = {
11-
path: "/a/tsconfig.json",
12-
content: JSON.stringify({ compilerOptions: { out, outFile } })
13-
};
14-
const f1: File = {
15-
path: "/a/a.ts",
16-
content: "let x = 1"
17-
};
18-
const f2: File = {
19-
path: "/a/b.ts",
20-
content: "let y = 1"
21-
};
22-
return createWatchedSystem([f1, f2, config, libFile]);
23-
},
9+
sys: () => createWatchedSystem({
10+
"/a/a.ts": "let x = 1",
11+
"/a/b.ts": "let y = 1",
12+
"/a/tsconfig.json": JSON.stringify({ compilerOptions: { out, outFile } }),
13+
[libFile.path]: libFile.content,
14+
}),
2415
changes: [
2516
{
2617
caption: "Make change in the file",

src/testRunner/unittests/tscWatch/helpers.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -432,7 +432,7 @@ namespace ts.tscWatch {
432432
return sys;
433433
}
434434

435-
export function createSystemWithSolutionBuild(solutionRoots: readonly string[], files: readonly TestFSWithWatch.FileOrFolderOrSymLink[], params?: TestFSWithWatch.TestServerHostCreationParameters) {
435+
export function createSystemWithSolutionBuild(solutionRoots: readonly string[], files: TestFSWithWatch.FileOrFolderOrSymLinkMap | readonly TestFSWithWatch.FileOrFolderOrSymLink[], params?: TestFSWithWatch.TestServerHostCreationParameters) {
436436
return solutionBuildWithBaseline(createWatchedSystem(files, params), solutionRoots);
437437
}
438438
}

src/testRunner/unittests/tscWatch/watchEnvironment.ts

+12-16
Original file line numberDiff line numberDiff line change
@@ -587,22 +587,18 @@ namespace ts.tscWatch {
587587
scenario,
588588
subScenario: `fsWatch/when using file watching thats on inode`,
589589
commandLineArgs: ["-w", "--extendedDiagnostics"],
590-
sys: () => {
591-
const configFile: File = {
592-
path: `${projectRoot}/tsconfig.json`,
593-
content: JSON.stringify({ watchOptions: { watchFile: "useFsEvents" }, files: ["foo.d.ts", "main.ts"] })
594-
};
595-
const main: File = {
596-
path: `${projectRoot}/main.ts`,
597-
content: `import { foo } from "./foo"; foo();`
598-
};
599-
const foo: File = {
600-
path: `${projectRoot}/foo.d.ts`,
601-
content: `export function foo(): string;`
602-
};
603-
const files = [libFile, main, foo, configFile];
604-
return createWatchedSystem(files, { currentDirectory: projectRoot, inodeWatching: true });
605-
},
590+
sys: () => createWatchedSystem(
591+
{
592+
[libFile.path]: libFile.content,
593+
[`${projectRoot}/main.ts`]: `import { foo } from "./foo"; foo();`,
594+
[`${projectRoot}/foo.d.ts`]: `export function foo(): string;`,
595+
[`${projectRoot}/tsconfig.json`]: JSON.stringify({ watchOptions: { watchFile: "useFsEvents" }, files: ["foo.d.ts", "main.ts"] }),
596+
},
597+
{
598+
currentDirectory: projectRoot,
599+
inodeWatching: true
600+
}
601+
),
606602
changes: [
607603
{
608604
caption: "Replace file with rename event that introduces error",

0 commit comments

Comments
 (0)