mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-02-16 05:58:32 -06:00
Improve test to verify the count of callbacks for the watched directories through watchFile
This commit is contained in:
parent
c3db9fadb0
commit
ab17600e86
@ -2210,7 +2210,7 @@ declare module "fs" {
|
||||
checkWatchedDirectories(host, emptyArray, /*recursive*/ true);
|
||||
|
||||
// Watching config file, file, lib file and directories
|
||||
checkWatchedFiles(host, expectedWatchedFiles);
|
||||
ts.TestFSWithWatch.checkMultiMapEachKeyWithCount("watchedFiles", host.watchedFiles, expectedWatchedFiles, 1);
|
||||
|
||||
checkProgramActualFiles(watch(), programFiles.map(f => f.path));
|
||||
checkOutputErrors(host, emptyArray);
|
||||
|
||||
@ -5322,16 +5322,11 @@ namespace ts.projectSystem {
|
||||
}
|
||||
|
||||
function verifyCalledOnEachEntry(callback: CalledMaps, expectedKeys: Map<number>) {
|
||||
const calledMap = calledMaps[callback];
|
||||
ts.TestFSWithWatch.verifyMapSize(callback, calledMap, arrayFrom(expectedKeys.keys()));
|
||||
expectedKeys.forEach((called, name) => {
|
||||
assert.isTrue(calledMap.has(name), `${callback} is expected to contain ${name}, actual keys: ${arrayFrom(calledMap.keys())}`);
|
||||
assert.equal(calledMap.get(name).length, called, `${callback} is expected to be called ${called} times with ${name}. Actual entry: ${calledMap.get(name)}`);
|
||||
});
|
||||
ts.TestFSWithWatch.checkMultiMapKeyCount(callback, calledMaps[callback], expectedKeys);
|
||||
}
|
||||
|
||||
function verifyCalledOnEachEntryNTimes(callback: CalledMaps, expectedKeys: string[], nTimes: number) {
|
||||
return verifyCalledOnEachEntry(callback, zipToMap(expectedKeys, expectedKeys.map(() => nTimes)));
|
||||
ts.TestFSWithWatch.checkMultiMapEachKeyWithCount(callback, calledMaps[callback], expectedKeys, nTimes);
|
||||
}
|
||||
|
||||
function verifyNoHostCalls() {
|
||||
@ -6605,7 +6600,11 @@ namespace ts.projectSystem {
|
||||
const files = [index, file1, configFile, libFile];
|
||||
const fileNames = files.map(file => file.path);
|
||||
// All closed files(files other than index), project folder, project/src folder and project/node_modules/@types folder
|
||||
const expectedWatchedFiles = fileNames.slice(1).concat(projectFolder, projectSrcFolder, `${projectFolder}/${nodeModulesAtTypes}`);
|
||||
const expectedWatchedFiles = arrayToMap(fileNames.slice(1).concat(`${projectFolder}/${nodeModulesAtTypes}`), s => s, () => 1);
|
||||
// For failed resolution lookup and tsconfig files
|
||||
expectedWatchedFiles.set(projectFolder, 2);
|
||||
// Through above recursive watches
|
||||
expectedWatchedFiles.set(projectSrcFolder, 2);
|
||||
const expectedCompletions = ["file1"];
|
||||
const completionPosition = index.content.lastIndexOf('"');
|
||||
const environmentVariables = createMap<string>();
|
||||
@ -6625,7 +6624,7 @@ namespace ts.projectSystem {
|
||||
};
|
||||
files.push(file2);
|
||||
fileNames.push(file2.path);
|
||||
expectedWatchedFiles.push(file2.path);
|
||||
expectedWatchedFiles.set(file2.path, 1);
|
||||
expectedCompletions.push("file2");
|
||||
host.reloadFS(files);
|
||||
host.runQueuedTimeoutCallbacks();
|
||||
@ -6635,7 +6634,8 @@ namespace ts.projectSystem {
|
||||
function verifyProjectAndCompletions() {
|
||||
checkWatchedDirectories(host, emptyArray, /*recursive*/ false);
|
||||
checkWatchedDirectories(host, emptyArray, /*recursive*/ true);
|
||||
checkWatchedFiles(host, expectedWatchedFiles);
|
||||
|
||||
ts.TestFSWithWatch.checkMultiMapKeyCount("watchedFiles", host.watchedFiles, expectedWatchedFiles);
|
||||
checkProjectActualFiles(project, fileNames);
|
||||
|
||||
const completions = project.getLanguageService().getCompletionsAtPosition(index.path, completionPosition, { includeExternalModuleExports: false, includeInsertTextCompletions: false });
|
||||
|
||||
@ -147,6 +147,18 @@ interface Array<T> {}`
|
||||
}
|
||||
}
|
||||
|
||||
export function checkMultiMapKeyCount(caption: string, actual: MultiMap<any>, expectedKeys: Map<number>) {
|
||||
verifyMapSize(caption, actual, arrayFrom(expectedKeys.keys()));
|
||||
expectedKeys.forEach((count, name) => {
|
||||
assert.isTrue(actual.has(name), `${caption}: expected to contain ${name}, actual keys: ${arrayFrom(actual.keys())}`);
|
||||
assert.equal(actual.get(name).length, count, `${caption}: Expected to be have ${count} entries for ${name}. Actual entry: ${JSON.stringify(actual.get(name))}`);
|
||||
});
|
||||
}
|
||||
|
||||
export function checkMultiMapEachKeyWithCount(caption: string, actual: MultiMap<any>, expectedKeys: ReadonlyArray<string>, count: number) {
|
||||
return checkMultiMapKeyCount(caption, actual, arrayToMap(expectedKeys, s => s, () => count));
|
||||
}
|
||||
|
||||
export function checkArray(caption: string, actual: ReadonlyArray<string>, expected: ReadonlyArray<string>) {
|
||||
assert.equal(actual.length, expected.length, `${caption}: incorrect actual number of files, expected:\r\n${expected.join("\r\n")}\r\ngot: ${actual.join("\r\n")}`);
|
||||
for (const f of expected) {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user