Skip to content

Commit 0dc3382

Browse files
authored
Deprecate reloadFs so the tests are more clear in what they are achieving and its easier to track changed behaviour (microsoft#38954)
1 parent 093e083 commit 0dc3382

19 files changed

+167
-224
lines changed

src/harness/virtualFileSystemWithWatch.ts

Lines changed: 2 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -474,9 +474,8 @@ interface Array<T> { length: number; [n: number]: T; }`
474474
return new Date(this.time);
475475
}
476476

477-
reloadFS(fileOrFolderOrSymLinkList: readonly FileOrFolderOrSymLink[], options?: Partial<ReloadWatchInvokeOptions>) {
478-
const mapNewLeaves = createMap<true>();
479-
const isNewFs = this.fs.size === 0;
477+
private reloadFS(fileOrFolderOrSymLinkList: readonly FileOrFolderOrSymLink[], options?: Partial<ReloadWatchInvokeOptions>) {
478+
Debug.assert(this.fs.size === 0);
480479
fileOrFolderOrSymLinkList = fileOrFolderOrSymLinkList.concat(this.withSafeList ? safeList : []);
481480
const filesOrFoldersToLoad: readonly FileOrFolderOrSymLink[] = !this.windowsStyleRoot ? fileOrFolderOrSymLinkList :
482481
fileOrFolderOrSymLinkList.map<FileOrFolderOrSymLink>(f => {
@@ -486,7 +485,6 @@ interface Array<T> { length: number; [n: number]: T; }`
486485
});
487486
for (const fileOrDirectory of filesOrFoldersToLoad) {
488487
const path = this.toFullPath(fileOrDirectory.path);
489-
mapNewLeaves.set(path, true);
490488
// If its a change
491489
const currentEntry = this.fs.get(path);
492490
if (currentEntry) {
@@ -520,18 +518,6 @@ interface Array<T> { length: number; [n: number]: T; }`
520518
this.ensureFileOrFolder(fileOrDirectory, options && options.ignoreWatchInvokedWithTriggerAsFileCreate);
521519
}
522520
}
523-
524-
if (!isNewFs) {
525-
this.fs.forEach((fileOrDirectory, path) => {
526-
// If this entry is not from the new file or folder
527-
if (!mapNewLeaves.get(path)) {
528-
// Leaf entries that arent in new list => remove these
529-
if (isFsFile(fileOrDirectory) || isFsSymLink(fileOrDirectory) || isFsFolder(fileOrDirectory) && fileOrDirectory.entries.length === 0) {
530-
this.removeFileOrFolder(fileOrDirectory, folder => !mapNewLeaves.get(folder.path));
531-
}
532-
}
533-
});
534-
}
535521
}
536522

537523
modifyFile(filePath: string, content: string, options?: Partial<ReloadWatchInvokeOptions>) {

src/testRunner/unittests/tscWatch/resolutionCache.ts

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ namespace ts.tscWatch {
2626
const newContent = `import {x} from "f1"
2727
var x: string = 1;`;
2828
root.content = newContent;
29-
host.reloadFS(files);
29+
host.writeFile(root.path, root.content);
3030

3131
// patch fileExists to make sure that disk is not touched
3232
host.fileExists = notImplemented;
@@ -53,7 +53,7 @@ namespace ts.tscWatch {
5353
};
5454

5555
root.content = `import {x} from "f2"`;
56-
host.reloadFS(files);
56+
host.writeFile(root.path, root.content);
5757

5858
// trigger synchronization to make sure that system will try to find 'f2' module on disk
5959
host.runQueuedTimeoutCallbacks();
@@ -79,7 +79,7 @@ namespace ts.tscWatch {
7979
const newContent = `import {x} from "f1"`;
8080
root.content = newContent;
8181

82-
host.reloadFS(files);
82+
host.writeFile(root.path, root.content);
8383
host.runQueuedTimeoutCallbacks();
8484

8585
checkOutputErrorsIncremental(host, [f1IsNotModule, cannotFindFoo]);
@@ -123,7 +123,8 @@ namespace ts.tscWatch {
123123

124124
fileExistsCalledForBar = false;
125125
root.content = `import {y} from "bar"`;
126-
host.reloadFS(files.concat(imported));
126+
host.writeFile(root.path, root.content);
127+
host.writeFile(imported.path, imported.content);
127128

128129
host.runQueuedTimeoutCallbacks();
129130
checkOutputErrorsIncremental(host, emptyArray);
@@ -141,9 +142,7 @@ namespace ts.tscWatch {
141142
content: `export const y = 1;export const x = 10;`
142143
};
143144

144-
const files = [root, libFile];
145-
const filesWithImported = files.concat(imported);
146-
const host = createWatchedSystem(filesWithImported);
145+
const host = createWatchedSystem([root, libFile, imported]);
147146
const originalFileExists = host.fileExists;
148147
let fileExistsCalledForBar = false;
149148
host.fileExists = fileName => {
@@ -162,15 +161,15 @@ namespace ts.tscWatch {
162161
checkOutputErrorsInitial(host, emptyArray);
163162

164163
fileExistsCalledForBar = false;
165-
host.reloadFS(files);
164+
host.deleteFile(imported.path);
166165
host.runQueuedTimeoutCallbacks();
167166
assert.isTrue(fileExistsCalledForBar, "'fileExists' should be called.");
168167
checkOutputErrorsIncremental(host, [
169168
getDiagnosticModuleNotFoundOfFile(watch.getCurrentProgram().getProgram(), root, "bar")
170169
]);
171170

172171
fileExistsCalledForBar = false;
173-
host.reloadFS(filesWithImported);
172+
host.writeFile(imported.path, imported.content);
174173
host.checkTimeoutQueueLengthAndRun(1);
175174
checkOutputErrorsIncremental(host, emptyArray);
176175
assert.isTrue(fileExistsCalledForBar, "'fileExists' should be called.");

src/testRunner/unittests/tsserver/cachingFileSystemInformation.ts

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -246,7 +246,7 @@ namespace ts.projectSystem {
246246

247247

248248
callsTrackingHost.clear();
249-
host.reloadFS([root, imported]);
249+
host.writeFile(imported.path, imported.content);
250250
host.runQueuedTimeoutCallbacks();
251251
diags = project.getLanguageService().getSemanticDiagnostics(root.path);
252252
assert.equal(diags.length, 0);
@@ -400,7 +400,7 @@ namespace ts.projectSystem {
400400

401401
// Create file cookie.ts
402402
projectFiles.push(file3);
403-
host.reloadFS(projectFiles);
403+
host.writeFile(file3.path, file3.content);
404404
host.runQueuedTimeoutCallbacks();
405405

406406
const canonicalFile3Path = useCaseSensitiveFileNames ? file3.path : file3.path.toLocaleLowerCase();
@@ -482,7 +482,7 @@ namespace ts.projectSystem {
482482
content: "export {}"
483483
};
484484
files.push(debugTypesFile);
485-
host.reloadFS(files);
485+
host.writeFile(debugTypesFile.path, debugTypesFile.content);
486486
host.runQueuedTimeoutCallbacks();
487487
checkProjectActualFiles(project, files.map(f => f.path));
488488
assert.deepEqual(project.getLanguageService().getSemanticDiagnostics(file1.path).map(diag => diag.messageText), []);
@@ -575,12 +575,13 @@ namespace ts.projectSystem {
575575
{ path: "/a/b/node_modules/.staging/rxjs-22375c61/add/operator" },
576576
{ path: "/a/b/node_modules/.staging/@types/lodash-e56c4fe7/package.json", content: "{\n \"name\": \"@types/lodash\",\n \"version\": \"4.14.74\",\n \"description\": \"TypeScript definitions for Lo-Dash\",\n \"license\": \"MIT\",\n \"contributors\": [\n {\n \"name\": \"Brian Zengel\",\n \"url\": \"https://github.com/bczengel\"\n },\n {\n \"name\": \"Ilya Mochalov\",\n \"url\": \"https://github.com/chrootsu\"\n },\n {\n \"name\": \"Stepan Mikhaylyuk\",\n \"url\": \"https://github.com/stepancar\"\n },\n {\n \"name\": \"Eric L Anderson\",\n \"url\": \"https://github.com/ericanderson\"\n },\n {\n \"name\": \"AJ Richardson\",\n \"url\": \"https://github.com/aj-r\"\n },\n {\n \"name\": \"Junyoung Clare Jang\",\n \"url\": \"https://github.com/ailrun\"\n }\n ],\n \"main\": \"\",\n \"repository\": {\n \"type\": \"git\",\n \"url\": \"https://www.github.com/DefinitelyTyped/DefinitelyTyped.git\"\n },\n \"scripts\": {},\n \"dependencies\": {},\n \"typesPublisherContentHash\": \"12af578ffaf8d86d2df37e591857906a86b983fa9258414326544a0fe6af0de8\",\n \"typeScriptVersion\": \"2.2\"\n}" },
577577
{ path: "/a/b/node_modules/.staging/lodash-b0733faa/index.js", content: "module.exports = require('./lodash');" },
578-
{ path: "/a/b/node_modules/.staging/typescript-8493ea5d/package.json.3017591594" }
578+
{ path: "/a/b/node_modules/.staging/typescript-8493ea5d/package.json.3017591594", content: "" }
579579
].map(getRootedFileOrFolder));
580580
// Since we added/removed in .staging no timeout
581581
verifyAfterPartialOrCompleteNpmInstall(0);
582582

583583
// Remove file "/a/b/node_modules/.staging/typescript-8493ea5d/package.json.3017591594"
584+
host.deleteFile(last(filesAndFoldersToAdd).path);
584585
filesAndFoldersToAdd.length--;
585586
verifyAfterPartialOrCompleteNpmInstall(0);
586587

@@ -602,6 +603,7 @@ namespace ts.projectSystem {
602603
verifyAfterPartialOrCompleteNpmInstall(0);
603604

604605
// remove /a/b/node_modules/.staging/rxjs-22375c61/package.json.2252192041
606+
host.deleteFile(last(filesAndFoldersToAdd).path);
605607
filesAndFoldersToAdd.length--;
606608
// and add few more folders/files
607609
filesAndFoldersToAdd.push(...[
@@ -622,6 +624,7 @@ namespace ts.projectSystem {
622624
.replace(/[\-\.][\d\w][\d\w][\d\w][\d\w][\d\w][\d\w][\d\w][\d\w]/g, "");
623625
});
624626

627+
host.deleteFolder(root + "/a/b/node_modules/.staging", /*recursive*/ true);
625628
const lodashIndexPath = root + "/a/b/node_modules/@types/lodash/index.d.ts";
626629
projectFiles.push(find(filesAndFoldersToAdd, f => f.path === lodashIndexPath)!);
627630
// we would now not have failed lookup in the parent of appFolder since lodash is available
@@ -631,7 +634,7 @@ namespace ts.projectSystem {
631634
verifyAfterPartialOrCompleteNpmInstall(2);
632635

633636
function verifyAfterPartialOrCompleteNpmInstall(timeoutQueueLengthWhenRunningTimeouts: number) {
634-
host.reloadFS(projectFiles.concat(otherFiles, filesAndFoldersToAdd));
637+
filesAndFoldersToAdd.forEach(f => host.ensureFileOrFolder(f));
635638
if (npmInstallComplete || timeoutDuringPartialInstallation) {
636639
host.checkTimeoutQueueLengthAndRun(timeoutQueueLengthWhenRunningTimeouts);
637640
}
@@ -696,7 +699,7 @@ namespace ts.projectSystem {
696699
invoker.call(host, fullPath, eventName, entryFullPath);
697700
}
698701
};
699-
host.reloadFS(files);
702+
host.writeFile(debugTypesFile.path, debugTypesFile.content);
700703
host.runQueuedTimeoutCallbacks();
701704
checkProjectActualFiles(project, files.map(f => f.path));
702705
assert.deepEqual(project.getLanguageService().getSemanticDiagnostics(app.path).map(diag => diag.messageText), []);

src/testRunner/unittests/tsserver/compileOnSave.ts

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -192,8 +192,7 @@ namespace ts.projectSystem {
192192
// Send an initial compileOnSave request
193193
sendAffectedFileRequestAndCheckResult(session, moduleFile1FileListRequest, [{ projectFileName: configFile.path, files: [moduleFile1, file1Consumer1, file1Consumer2] }]);
194194

195-
file1Consumer1.content = `let y = 10;`;
196-
host.reloadFS([moduleFile1, file1Consumer1, file1Consumer2, configFile, libFile]);
195+
host.writeFile(file1Consumer1.path, `let y = 10;`);
197196

198197
session.executeCommand(changeModuleFile1ShapeRequest1);
199198
sendAffectedFileRequestAndCheckResult(session, moduleFile1FileListRequest, [{ projectFileName: configFile.path, files: [moduleFile1, file1Consumer2] }]);
@@ -209,7 +208,7 @@ namespace ts.projectSystem {
209208

210209
session.executeCommand(changeModuleFile1ShapeRequest1);
211210
// Delete file1Consumer2
212-
host.reloadFS([moduleFile1, file1Consumer1, configFile, libFile]);
211+
host.deleteFile(file1Consumer2.path);
213212
sendAffectedFileRequestAndCheckResult(session, moduleFile1FileListRequest, [{ projectFileName: configFile.path, files: [moduleFile1, file1Consumer1] }]);
214213
});
215214

@@ -225,7 +224,7 @@ namespace ts.projectSystem {
225224
path: "/a/b/file1Consumer3.ts",
226225
content: `import {Foo} from "./moduleFile1"; let y = Foo();`
227226
};
228-
host.reloadFS([moduleFile1, file1Consumer1, file1Consumer2, file1Consumer3, globalFile3, configFile, libFile]);
227+
host.writeFile(file1Consumer3.path, file1Consumer3.content);
229228
host.runQueuedTimeoutCallbacks();
230229
session.executeCommand(changeModuleFile1ShapeRequest1);
231230
sendAffectedFileRequestAndCheckResult(session, moduleFile1FileListRequest, [{ projectFileName: configFile.path, files: [moduleFile1, file1Consumer1, file1Consumer2, file1Consumer3] }]);
@@ -475,7 +474,7 @@ namespace ts.projectSystem {
475474
const session = createSession(host);
476475

477476
openFilesForSession([referenceFile1], session);
478-
host.reloadFS([referenceFile1, configFile]);
477+
host.deleteFile(moduleFile1.path);
479478

480479
const request = makeSessionRequest<server.protocol.FileRequestArgs>(CommandNames.CompileOnSaveAffectedFileList, { file: referenceFile1.path });
481480
sendAffectedFileRequestAndCheckResult(session, request, [

src/testRunner/unittests/tsserver/configFileSearch.ts

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ namespace ts.projectSystem {
4848
checkWatchedDirectories(host, typeRootLocations.concat(configFileLocation), /*recursive*/ true);
4949

5050
// Delete config file - should create inferred project and not configured project
51-
host.reloadFS([f1, libFile, configFile2]);
51+
host.deleteFile(configFile.path);
5252
host.runQueuedTimeoutCallbacks();
5353
checkNumberOfProjects(service, { inferredProjects: 1 });
5454
checkWatchedFiles(host, [libFile.path, configFile.path, `${configFileLocation}/jsconfig.json`, `${projectDir}/tsconfig.json`, `${projectDir}/jsconfig.json`]);
@@ -81,7 +81,7 @@ namespace ts.projectSystem {
8181
checkWatchedDirectories(host, getTypeRootsFromLocation(configFileLocation).concat(configFileLocation), /*recursive*/ true);
8282

8383
// Delete config file - should create inferred project with project root path set
84-
host.reloadFS([f1, libFile, configFile2]);
84+
host.deleteFile(configFile.path);
8585
host.runQueuedTimeoutCallbacks();
8686
checkNumberOfProjects(service, { inferredProjects: 1 });
8787
assert.equal(service.inferredProjects[0].projectRootPath, projectDir);
@@ -100,8 +100,6 @@ namespace ts.projectSystem {
100100
path: `${projectRoot}/tsconfig.json`,
101101
content: "{}"
102102
};
103-
const files = [file, libFile];
104-
const filesWithConfig = files.concat(tsconfig);
105103
const dirOfFile = getDirectoryPath(file.path);
106104

107105
function openClientFile(files: File[]) {
@@ -141,27 +139,27 @@ namespace ts.projectSystem {
141139
}
142140

143141
it("tsconfig for the file exists", () => {
144-
const { host, projectService } = openClientFile(filesWithConfig);
142+
const { host, projectService } = openClientFile([file, libFile, tsconfig]);
145143
verifyConfiguredProject(host, projectService);
146144

147-
host.reloadFS(files);
145+
host.deleteFile(tsconfig.path);
148146
host.runQueuedTimeoutCallbacks();
149147
verifyInferredProject(host, projectService);
150148

151-
host.reloadFS(filesWithConfig);
149+
host.writeFile(tsconfig.path, tsconfig.content);
152150
host.runQueuedTimeoutCallbacks();
153151
verifyConfiguredProject(host, projectService, /*orphanInferredProject*/ true);
154152
});
155153

156154
it("tsconfig for the file does not exist", () => {
157-
const { host, projectService } = openClientFile(files);
155+
const { host, projectService } = openClientFile([file, libFile]);
158156
verifyInferredProject(host, projectService);
159157

160-
host.reloadFS(filesWithConfig);
158+
host.writeFile(tsconfig.path, tsconfig.content);
161159
host.runQueuedTimeoutCallbacks();
162160
verifyConfiguredProject(host, projectService, /*orphanInferredProject*/ true);
163161

164-
host.reloadFS(files);
162+
host.deleteFile(tsconfig.path);
165163
host.runQueuedTimeoutCallbacks();
166164
verifyInferredProject(host, projectService);
167165
});

0 commit comments

Comments
 (0)