Skip to content

Commit 5b8d26b

Browse files
committed
More refactor for failed lookup baselines
1 parent 82b1d7d commit 5b8d26b

13 files changed

+21506
-20100
lines changed

src/testRunner/unittests/canWatch.ts

Lines changed: 42 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -51,41 +51,43 @@ describe("unittests:: canWatch::", () => {
5151
},
5252
);
5353

54-
baselineCanWatch(
55-
"getDirectoryToWatchFailedLookupLocation",
56-
() => `Determines whether to watch given failed lookup location (file that didnt exist) when resolving module.\r\nIt also determines the directory to watch and whether to watch it recursively or not.`,
57-
({ paths, longestPathLength }, baseline) => {
58-
const recursive = "Recursive";
59-
const maxLength = longestPathLength + "/node_modules/@types/dir/subdir/somefile.d.ts".length;
60-
const maxLengths = [maxLength, maxLength, recursive.length] as const;
61-
baselineCanWatchForRoot(paths, baseline, baselineForRoot);
62-
function baselineForRoot(root: string | undefined) {
63-
pushHeader(baseline, ["Location", "getDirectoryToWatchFailedLookupLocation", recursive], maxLengths);
64-
paths.forEach(path => {
65-
baselineGetDirectoryToWatchFailedLookupLocation(ts.combinePaths(path, "node_modules/dir/somefile.d.ts"), root, maxLengths);
66-
baselineGetDirectoryToWatchFailedLookupLocation(ts.combinePaths(path, "node_modules/@types/dir/somefile.d.ts"), root, maxLengths);
67-
baselineGetDirectoryToWatchFailedLookupLocation(ts.combinePaths(path, "node_modules/dir/subdir/somefile.d.ts"), root, maxLengths);
68-
baselineGetDirectoryToWatchFailedLookupLocation(ts.combinePaths(path, "node_modules/@types/dir/subdir/somefile.d.ts"), root, maxLengths);
69-
baselineGetDirectoryToWatchFailedLookupLocation(ts.combinePaths(path, "node_modules/somefile.d.ts"), root, maxLengths);
70-
baselineGetDirectoryToWatchFailedLookupLocation(ts.combinePaths(path, "node_modules/@types/somefile.d.ts"), root, maxLengths);
71-
baselineGetDirectoryToWatchFailedLookupLocation(ts.combinePaths(path, "somefile.d.ts"), root, maxLengths);
72-
baselineGetDirectoryToWatchFailedLookupLocation(ts.combinePaths(path, "dir/somefile.d.ts"), root, maxLengths);
73-
baselineGetDirectoryToWatchFailedLookupLocation(ts.combinePaths(path, "dir/subdir/somefile.d.ts"), root, maxLengths);
74-
});
75-
}
76-
function baselineGetDirectoryToWatchFailedLookupLocation(path: string, root: string | undefined, maxLengths: readonly number[]) {
77-
const result = ts.getDirectoryToWatchFailedLookupLocation(
78-
path,
79-
path as ts.Path,
80-
root,
81-
root as ts.Path | undefined,
82-
root !== undefined ? root.split(ts.directorySeparator).length : 0,
83-
ts.returnUndefined,
84-
);
85-
pushRow(baseline, [path, result ? result.dir : "", result ? `${!result.nonRecursive}` : ""], maxLengths);
86-
}
87-
},
88-
);
54+
baselineGetDirectoryToWatchOfFailedLookup("getDirectoryToWatchFailedLookupLocationNodeModules", "node_modules");
55+
baselineGetDirectoryToWatchOfFailedLookup("getDirectoryToWatchFailedLookupLocationAtTypes", "node_modules/@types");
56+
baselineGetDirectoryToWatchOfFailedLookup("getDirectoryToWatchFailedLookupLocation", "");
57+
function baselineGetDirectoryToWatchOfFailedLookup(
58+
scenario: string,
59+
forPath: "node_modules" | "node_modules/@types" | "",
60+
) {
61+
baselineCanWatch(
62+
scenario,
63+
() => `Determines whether to watch given failed lookup location (file that didnt exist) when resolving module.\r\nIt also determines the directory to watch and whether to watch it recursively or not.`,
64+
({ paths, longestPathLength }, baseline) => {
65+
const recursive = "Recursive";
66+
const maxLength = longestPathLength + ts.combinePaths(forPath, "dir/subdir/somefile.d.ts").length;
67+
const maxLengths = [maxLength, maxLength, recursive.length] as const;
68+
baselineCanWatchForRoot(paths, baseline, baselineForRoot);
69+
function baselineForRoot(root: string | undefined) {
70+
pushHeader(baseline, ["Location", "getDirectoryToWatchFailedLookupLocation", recursive], maxLengths);
71+
paths.forEach(path => {
72+
baselineGetDirectoryToWatchFailedLookupLocation(ts.combinePaths(path, forPath, "somefile.d.ts"), root, maxLengths);
73+
baselineGetDirectoryToWatchFailedLookupLocation(ts.combinePaths(path, forPath, "dir/somefile.d.ts"), root, maxLengths);
74+
baselineGetDirectoryToWatchFailedLookupLocation(ts.combinePaths(path, forPath, "dir/subdir/somefile.d.ts"), root, maxLengths);
75+
});
76+
}
77+
function baselineGetDirectoryToWatchFailedLookupLocation(path: string, root: string | undefined, maxLengths: readonly number[]) {
78+
const result = ts.getDirectoryToWatchFailedLookupLocation(
79+
path,
80+
path as ts.Path,
81+
root,
82+
root as ts.Path | undefined,
83+
root !== undefined ? root.split(ts.directorySeparator).length : 0,
84+
ts.returnUndefined,
85+
);
86+
pushRow(baseline, [path, result ? result.dir : "", result ? `${!result.nonRecursive}` : ""], maxLengths);
87+
}
88+
},
89+
);
90+
}
8991

9092
baselineCanWatch(
9193
"getDirectoryToWatchFailedLookupLocationFromTypeRoot",
@@ -124,7 +126,11 @@ describe("unittests:: canWatch::", () => {
124126
}
125127
}
126128

127-
function baselineCanWatch(scenario: string, info: () => string, baselineOsRoot: (pathsAtRoot: PathAndLongPathLength, baseline: string[]) => void) {
129+
function baselineCanWatch(
130+
scenario: string,
131+
info: () => string,
132+
baselineOsRoot: (pathsAtRoot: PathAndLongPathLength, baseline: string[]) => void,
133+
) {
128134
it(`${scenario}Unix`, () => {
129135
baselineCanWatchForOsRoot(scenario, "Unix", "/", info, baselineOsRoot);
130136
});

0 commit comments

Comments
 (0)