Skip to content

Deprecate reloadFs so the tests are more clear in what they are achieving and its easier to track changed behaviour #38954

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 5, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 2 additions & 16 deletions src/harness/virtualFileSystemWithWatch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -474,9 +474,8 @@ interface Array<T> { length: number; [n: number]: T; }`
return new Date(this.time);
}

reloadFS(fileOrFolderOrSymLinkList: readonly FileOrFolderOrSymLink[], options?: Partial<ReloadWatchInvokeOptions>) {
const mapNewLeaves = createMap<true>();
const isNewFs = this.fs.size === 0;
private reloadFS(fileOrFolderOrSymLinkList: readonly FileOrFolderOrSymLink[], options?: Partial<ReloadWatchInvokeOptions>) {
Debug.assert(this.fs.size === 0);
fileOrFolderOrSymLinkList = fileOrFolderOrSymLinkList.concat(this.withSafeList ? safeList : []);
const filesOrFoldersToLoad: readonly FileOrFolderOrSymLink[] = !this.windowsStyleRoot ? fileOrFolderOrSymLinkList :
fileOrFolderOrSymLinkList.map<FileOrFolderOrSymLink>(f => {
Expand All @@ -486,7 +485,6 @@ interface Array<T> { length: number; [n: number]: T; }`
});
for (const fileOrDirectory of filesOrFoldersToLoad) {
const path = this.toFullPath(fileOrDirectory.path);
mapNewLeaves.set(path, true);
// If its a change
const currentEntry = this.fs.get(path);
if (currentEntry) {
Expand Down Expand Up @@ -520,18 +518,6 @@ interface Array<T> { length: number; [n: number]: T; }`
this.ensureFileOrFolder(fileOrDirectory, options && options.ignoreWatchInvokedWithTriggerAsFileCreate);
}
}

if (!isNewFs) {
this.fs.forEach((fileOrDirectory, path) => {
// If this entry is not from the new file or folder
if (!mapNewLeaves.get(path)) {
// Leaf entries that arent in new list => remove these
if (isFsFile(fileOrDirectory) || isFsSymLink(fileOrDirectory) || isFsFolder(fileOrDirectory) && fileOrDirectory.entries.length === 0) {
this.removeFileOrFolder(fileOrDirectory, folder => !mapNewLeaves.get(folder.path));
}
}
});
}
}

modifyFile(filePath: string, content: string, options?: Partial<ReloadWatchInvokeOptions>) {
Expand Down
17 changes: 8 additions & 9 deletions src/testRunner/unittests/tscWatch/resolutionCache.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ namespace ts.tscWatch {
const newContent = `import {x} from "f1"
var x: string = 1;`;
root.content = newContent;
host.reloadFS(files);
host.writeFile(root.path, root.content);

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

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

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

host.reloadFS(files);
host.writeFile(root.path, root.content);
host.runQueuedTimeoutCallbacks();

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

fileExistsCalledForBar = false;
root.content = `import {y} from "bar"`;
host.reloadFS(files.concat(imported));
host.writeFile(root.path, root.content);
host.writeFile(imported.path, imported.content);

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

const files = [root, libFile];
const filesWithImported = files.concat(imported);
const host = createWatchedSystem(filesWithImported);
const host = createWatchedSystem([root, libFile, imported]);
const originalFileExists = host.fileExists;
let fileExistsCalledForBar = false;
host.fileExists = fileName => {
Expand All @@ -162,15 +161,15 @@ namespace ts.tscWatch {
checkOutputErrorsInitial(host, emptyArray);

fileExistsCalledForBar = false;
host.reloadFS(files);
host.deleteFile(imported.path);
host.runQueuedTimeoutCallbacks();
assert.isTrue(fileExistsCalledForBar, "'fileExists' should be called.");
checkOutputErrorsIncremental(host, [
getDiagnosticModuleNotFoundOfFile(watch.getCurrentProgram().getProgram(), root, "bar")
]);

fileExistsCalledForBar = false;
host.reloadFS(filesWithImported);
host.writeFile(imported.path, imported.content);
host.checkTimeoutQueueLengthAndRun(1);
checkOutputErrorsIncremental(host, emptyArray);
assert.isTrue(fileExistsCalledForBar, "'fileExists' should be called.");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,7 @@ namespace ts.projectSystem {


callsTrackingHost.clear();
host.reloadFS([root, imported]);
host.writeFile(imported.path, imported.content);
host.runQueuedTimeoutCallbacks();
diags = project.getLanguageService().getSemanticDiagnostics(root.path);
assert.equal(diags.length, 0);
Expand Down Expand Up @@ -400,7 +400,7 @@ namespace ts.projectSystem {

// Create file cookie.ts
projectFiles.push(file3);
host.reloadFS(projectFiles);
host.writeFile(file3.path, file3.content);
host.runQueuedTimeoutCallbacks();

const canonicalFile3Path = useCaseSensitiveFileNames ? file3.path : file3.path.toLocaleLowerCase();
Expand Down Expand Up @@ -482,7 +482,7 @@ namespace ts.projectSystem {
content: "export {}"
};
files.push(debugTypesFile);
host.reloadFS(files);
host.writeFile(debugTypesFile.path, debugTypesFile.content);
host.runQueuedTimeoutCallbacks();
checkProjectActualFiles(project, files.map(f => f.path));
assert.deepEqual(project.getLanguageService().getSemanticDiagnostics(file1.path).map(diag => diag.messageText), []);
Expand Down Expand Up @@ -575,12 +575,13 @@ namespace ts.projectSystem {
{ path: "/a/b/node_modules/.staging/rxjs-22375c61/add/operator" },
{ 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}" },
{ path: "/a/b/node_modules/.staging/lodash-b0733faa/index.js", content: "module.exports = require('./lodash');" },
{ path: "/a/b/node_modules/.staging/typescript-8493ea5d/package.json.3017591594" }
{ path: "/a/b/node_modules/.staging/typescript-8493ea5d/package.json.3017591594", content: "" }
].map(getRootedFileOrFolder));
// Since we added/removed in .staging no timeout
verifyAfterPartialOrCompleteNpmInstall(0);

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

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

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

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

function verifyAfterPartialOrCompleteNpmInstall(timeoutQueueLengthWhenRunningTimeouts: number) {
host.reloadFS(projectFiles.concat(otherFiles, filesAndFoldersToAdd));
filesAndFoldersToAdd.forEach(f => host.ensureFileOrFolder(f));
if (npmInstallComplete || timeoutDuringPartialInstallation) {
host.checkTimeoutQueueLengthAndRun(timeoutQueueLengthWhenRunningTimeouts);
}
Expand Down Expand Up @@ -696,7 +699,7 @@ namespace ts.projectSystem {
invoker.call(host, fullPath, eventName, entryFullPath);
}
};
host.reloadFS(files);
host.writeFile(debugTypesFile.path, debugTypesFile.content);
host.runQueuedTimeoutCallbacks();
checkProjectActualFiles(project, files.map(f => f.path));
assert.deepEqual(project.getLanguageService().getSemanticDiagnostics(app.path).map(diag => diag.messageText), []);
Expand Down
9 changes: 4 additions & 5 deletions src/testRunner/unittests/tsserver/compileOnSave.ts
Original file line number Diff line number Diff line change
Expand Up @@ -192,8 +192,7 @@ namespace ts.projectSystem {
// Send an initial compileOnSave request
sendAffectedFileRequestAndCheckResult(session, moduleFile1FileListRequest, [{ projectFileName: configFile.path, files: [moduleFile1, file1Consumer1, file1Consumer2] }]);

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

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

session.executeCommand(changeModuleFile1ShapeRequest1);
// Delete file1Consumer2
host.reloadFS([moduleFile1, file1Consumer1, configFile, libFile]);
host.deleteFile(file1Consumer2.path);
sendAffectedFileRequestAndCheckResult(session, moduleFile1FileListRequest, [{ projectFileName: configFile.path, files: [moduleFile1, file1Consumer1] }]);
});

Expand All @@ -225,7 +224,7 @@ namespace ts.projectSystem {
path: "/a/b/file1Consumer3.ts",
content: `import {Foo} from "./moduleFile1"; let y = Foo();`
};
host.reloadFS([moduleFile1, file1Consumer1, file1Consumer2, file1Consumer3, globalFile3, configFile, libFile]);
host.writeFile(file1Consumer3.path, file1Consumer3.content);
host.runQueuedTimeoutCallbacks();
session.executeCommand(changeModuleFile1ShapeRequest1);
sendAffectedFileRequestAndCheckResult(session, moduleFile1FileListRequest, [{ projectFileName: configFile.path, files: [moduleFile1, file1Consumer1, file1Consumer2, file1Consumer3] }]);
Expand Down Expand Up @@ -475,7 +474,7 @@ namespace ts.projectSystem {
const session = createSession(host);

openFilesForSession([referenceFile1], session);
host.reloadFS([referenceFile1, configFile]);
host.deleteFile(moduleFile1.path);

const request = makeSessionRequest<server.protocol.FileRequestArgs>(CommandNames.CompileOnSaveAffectedFileList, { file: referenceFile1.path });
sendAffectedFileRequestAndCheckResult(session, request, [
Expand Down
18 changes: 8 additions & 10 deletions src/testRunner/unittests/tsserver/configFileSearch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ namespace ts.projectSystem {
checkWatchedDirectories(host, typeRootLocations.concat(configFileLocation), /*recursive*/ true);

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

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

function openClientFile(files: File[]) {
Expand Down Expand Up @@ -141,27 +139,27 @@ namespace ts.projectSystem {
}

it("tsconfig for the file exists", () => {
const { host, projectService } = openClientFile(filesWithConfig);
const { host, projectService } = openClientFile([file, libFile, tsconfig]);
verifyConfiguredProject(host, projectService);

host.reloadFS(files);
host.deleteFile(tsconfig.path);
host.runQueuedTimeoutCallbacks();
verifyInferredProject(host, projectService);

host.reloadFS(filesWithConfig);
host.writeFile(tsconfig.path, tsconfig.content);
host.runQueuedTimeoutCallbacks();
verifyConfiguredProject(host, projectService, /*orphanInferredProject*/ true);
});

it("tsconfig for the file does not exist", () => {
const { host, projectService } = openClientFile(files);
const { host, projectService } = openClientFile([file, libFile]);
verifyInferredProject(host, projectService);

host.reloadFS(filesWithConfig);
host.writeFile(tsconfig.path, tsconfig.content);
host.runQueuedTimeoutCallbacks();
verifyConfiguredProject(host, projectService, /*orphanInferredProject*/ true);

host.reloadFS(files);
host.deleteFile(tsconfig.path);
host.runQueuedTimeoutCallbacks();
verifyInferredProject(host, projectService);
});
Expand Down
Loading