Skip to content

Commit 7e65cd3

Browse files
committed
Baseline getModifiedTime, setModifiedTime, fileExits and directoryExits for experiment
1 parent 16cef4a commit 7e65cd3

File tree

495 files changed

+37181
-12
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

495 files changed

+37181
-12
lines changed

src/harness/virtualFileSystemWithWatch.ts

+33-2
Original file line numberDiff line numberDiff line change
@@ -856,18 +856,26 @@ interface Array<T> { length: number; [n: number]: T; }`
856856
}
857857

858858
fileExists(s: string) {
859+
const path = this.toFullPath(s);
860+
this.fileExistsCalls[path] = (getProperty(this.fileExistsCalls, path) || 0) + 1;
861+
return !!this.getRealFile(path);
862+
}
863+
864+
fileExistsWithoutTracking(s: string) {
859865
const path = this.toFullPath(s);
860866
return !!this.getRealFile(path);
861867
}
862868

863869
getModifiedTime(s: string) {
864870
const path = this.toFullPath(s);
871+
this.getModifiedCalls[path] = (getProperty(this.getModifiedCalls, path) || 0) + 1;
865872
const fsEntry = this.fs.get(path);
866873
return (fsEntry && fsEntry.modifiedTime)!; // TODO: GH#18217
867874
}
868875

869876
setModifiedTime(s: string, date: Date) {
870877
const path = this.toFullPath(s);
878+
this.setModifiedCalls[path] = (getProperty(this.setModifiedCalls, path) || 0) + 1;
871879
const fsEntry = this.fs.get(path);
872880
if (fsEntry) {
873881
fsEntry.modifiedTime = date;
@@ -891,6 +899,7 @@ interface Array<T> { length: number; [n: number]: T; }`
891899

892900
directoryExists(s: string) {
893901
const path = this.toFullPath(s);
902+
this.directoryExistsCalls[path] = (getProperty(this.directoryExistsCalls, path) || 0) + 1;
894903
return !!this.getRealFolder(path);
895904
}
896905

@@ -1064,11 +1073,14 @@ interface Array<T> { length: number; [n: number]: T; }`
10641073
}
10651074
result.set(key, cloneValue);
10661075
});
1067-
10681076
return result;
10691077
}
10701078

10711079
writtenFiles?: ESMap<Path, number>;
1080+
getModifiedCalls: MapLike<number> = {};
1081+
fileExistsCalls: MapLike<number> = {};
1082+
directoryExistsCalls: MapLike<number> = {};
1083+
setModifiedCalls: MapLike<number> = {};
10721084
diff(baseline: string[], base: ESMap<string, FSEntry> = new Map()) {
10731085
this.fs.forEach(newFsEntry => {
10741086
diffFsEntry(baseline, base.get(newFsEntry.path), newFsEntry, this.writtenFiles);
@@ -1080,6 +1092,18 @@ interface Array<T> { length: number; [n: number]: T; }`
10801092
}
10811093
});
10821094
baseline.push("");
1095+
baseline.push(`fileExists:: ${JSON.stringify(this.fileExistsCalls, /*replacer*/ undefined, " ")} `);
1096+
baseline.push("");
1097+
baseline.push(`directoryExists:: ${JSON.stringify(this.directoryExistsCalls, /*replacer*/ undefined, " ")} `);
1098+
baseline.push("");
1099+
baseline.push(`getModifiedTimes:: ${JSON.stringify(this.getModifiedCalls, /*replacer*/ undefined, " ")} `);
1100+
baseline.push("");
1101+
baseline.push(`setModifiedTimes:: ${JSON.stringify(this.setModifiedCalls, /*replacer*/ undefined, " ")} `);
1102+
baseline.push("");
1103+
this.fileExistsCalls = {};
1104+
this.directoryExistsCalls = {};
1105+
this.getModifiedCalls = {};
1106+
this.setModifiedCalls = {};
10831107
}
10841108

10851109
serializeWatches(baseline: string[]) {
@@ -1224,7 +1248,13 @@ interface Array<T> { length: number; [n: number]: T; }`
12241248
if (baselinedOutput) baseline.push(baselinedOutput.join(""));
12251249
}
12261250

1227-
export type TestServerHostTrackingWrittenFiles = TestServerHost & { writtenFiles: ESMap<Path, number>; };
1251+
export type TestServerHostTrackingWrittenFiles = TestServerHost & {
1252+
writtenFiles: ESMap<Path, number>;
1253+
getModifiedCalls: MapLike<number>;
1254+
fileExistsCalls: MapLike<number>;
1255+
directoryExistsCalls: MapLike<number>;
1256+
setModifiedCalls: MapLike<number>;
1257+
};
12281258

12291259
export function changeToHostTrackingWrittenFiles(inputHost: TestServerHost) {
12301260
const host = inputHost as TestServerHostTrackingWrittenFiles;
@@ -1235,6 +1265,7 @@ interface Array<T> { length: number; [n: number]: T; }`
12351265
const path = host.toFullPath(fileName);
12361266
host.writtenFiles.set(path, (host.writtenFiles.get(path) || 0) + 1);
12371267
};
1268+
12381269
return host;
12391270
}
12401271
export const tsbuildProjectsLocation = "/user/username/projects";

src/testRunner/unittests/tsbuild/helpers.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -268,10 +268,11 @@ interface Symbol {
268268
options: CompilerOptions,
269269
sys: TscCompileSystem | tscWatch.WatchedSystem,
270270
originalReadCall?: System["readFile"],
271+
originalFileExists?: System["fileExists"],
271272
) {
272273
const buildInfoPath = getTsBuildInfoEmitOutputFilePath(options);
273274
if (!buildInfoPath || !sys.writtenFiles!.has(toPathWithSystem(sys, buildInfoPath))) return;
274-
if (!sys.fileExists(buildInfoPath)) return;
275+
if (!(originalFileExists || sys.fileExists).call(sys, buildInfoPath)) return;
275276

276277
const buildInfo = getBuildInfo((originalReadCall || sys.readFile).call(sys, buildInfoPath, "utf8")!);
277278
generateBuildInfoProgramBaseline(sys, buildInfoPath, buildInfo);

src/testRunner/unittests/tsc/helpers.ts

+52-4
Original file line numberDiff line numberDiff line change
@@ -39,20 +39,21 @@ namespace ts {
3939
export function commandLineCallbacks(
4040
sys: TscCompileSystem | tscWatch.WatchedSystem,
4141
originalReadCall?: System["readFile"],
42+
originalFileExists?: System["fileExists"],
4243
): CommandLineCallbacks {
4344
let programs: CommandLineProgram[] | undefined;
4445

4546
return {
4647
cb: program => {
4748
if (isAnyProgram(program)) {
48-
baselineBuildInfo(program.getCompilerOptions(), sys, originalReadCall);
49+
baselineBuildInfo(program.getCompilerOptions(), sys, originalReadCall, originalFileExists);
4950
(programs || (programs = [])).push(isBuilderProgram(program) ?
5051
[program.getProgram(), program] :
5152
[program]
5253
);
5354
}
5455
else {
55-
baselineBuildInfo(program.options, sys, originalReadCall);
56+
baselineBuildInfo(program.options, sys, originalReadCall, originalFileExists);
5657
}
5758
},
5859
getPrograms: () => {
@@ -161,6 +162,10 @@ ${patch ? vfs.formatPatch(patch) : ""}`
161162
export function testTscCompile(input: TestTscCompile) {
162163
let actualReadFileMap: MapLike<number> | undefined;
163164
let getPrograms: CommandLineCallbacks["getPrograms"] | undefined;
165+
let getModifiedCalls: MapLike<number> | undefined;
166+
let setModifiedCalls: MapLike<number> | undefined;
167+
let fileExistsCalls: MapLike<number> | undefined;
168+
let directoryExistsCalls: MapLike<number> | undefined;
164169
return testTscCompileLike({
165170
...input,
166171
compile: commandLineCompile,
@@ -178,8 +183,43 @@ ${patch ? vfs.formatPatch(patch) : ""}`
178183
}
179184
return originalReadFile.call(sys, path);
180185
};
181-
182-
const result = commandLineCallbacks(sys, originalReadFile);
186+
getModifiedCalls = {};
187+
setModifiedCalls = {};
188+
fileExistsCalls = {};
189+
directoryExistsCalls = {};
190+
const originalGetModifiedTime = sys.getModifiedTime;
191+
sys.getModifiedTime = path => {
192+
// Dont record libs
193+
if (getModifiedCalls) {
194+
getModifiedCalls[path] = (getProperty(getModifiedCalls, path) || 0) + 1;
195+
}
196+
return originalGetModifiedTime.call(sys, path);
197+
};
198+
const originalSetModifiedTime = sys.setModifiedTime;
199+
sys.setModifiedTime = (path, time) => {
200+
// Dont record libs
201+
if (setModifiedCalls) {
202+
setModifiedCalls[path] = (getProperty(setModifiedCalls, path) || 0) + 1;
203+
}
204+
return originalSetModifiedTime.call(sys, path, time);
205+
};
206+
const originalFileExists = sys.fileExists;
207+
sys.fileExists = path => {
208+
// Dont record libs
209+
if (fileExistsCalls) {
210+
fileExistsCalls[path] = (getProperty(fileExistsCalls, path) || 0) + 1;
211+
}
212+
return originalFileExists.call(sys, path);
213+
};
214+
const originalDirectoryExists = sys.directoryExists;
215+
sys.directoryExists = path => {
216+
// Dont record libs
217+
if (directoryExistsCalls) {
218+
directoryExistsCalls[path] = (getProperty(directoryExistsCalls, path) || 0) + 1;
219+
}
220+
return originalDirectoryExists.call(sys, path);
221+
};
222+
const result = commandLineCallbacks(sys, originalReadFile, originalFileExists);
183223
executeCommandLine(
184224
sys,
185225
result.cb,
@@ -199,8 +239,16 @@ ${patch ? vfs.formatPatch(patch) : ""}`
199239
if (baselineReadFileCalls) {
200240
sys.write(`readFiles:: ${JSON.stringify(actualReadFileMap, /*replacer*/ undefined, " ")} `);
201241
}
242+
sys.write(`\ngetModifiedTime:: ${JSON.stringify(getModifiedCalls, /*replacer*/ undefined, " ")}\n`);
243+
sys.write(`\nsetModifiedTime:: ${JSON.stringify(setModifiedCalls, /*replacer*/ undefined, " ")}\n`);
244+
sys.write(`\nfileExists:: ${JSON.stringify(fileExistsCalls, /*replacer*/ undefined, " ")}\n`);
245+
sys.write(`\ndirectoryExists:: ${JSON.stringify(directoryExistsCalls, /*replacer*/ undefined, " ")}\n`);
202246
if (baselineSourceMap) generateSourceMapBaselineFiles(sys);
203247
actualReadFileMap = undefined;
248+
getModifiedCalls = undefined;
249+
setModifiedCalls = undefined;
250+
fileExistsCalls = undefined;
251+
directoryExistsCalls = undefined;
204252
getPrograms = undefined;
205253
}
206254
}

src/testRunner/unittests/tscWatch/helpers.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ namespace ts.tscWatch {
140140
} = input;
141141

142142
if (!isWatch(commandLineArgs)) sys.exit = exitCode => sys.exitCode = exitCode;
143-
const { cb, getPrograms } = commandLineCallbacks(sys);
143+
const { cb, getPrograms } = commandLineCallbacks(sys, /*originalReadCall*/ undefined, sys.fileExistsWithoutTracking);
144144
const watchOrSolution = executeCommandLine(
145145
sys,
146146
cb,
@@ -179,7 +179,7 @@ namespace ts.tscWatch {
179179
const baseline: string[] = [];
180180
baseline.push("Input::");
181181
sys.diff(baseline);
182-
const { cb, getPrograms } = commandLineCallbacks(sys);
182+
const { cb, getPrograms } = commandLineCallbacks(sys, /*originalReadCall*/ undefined, sys.fileExistsWithoutTracking);
183183
return { sys, baseline, oldSnap: sys.snap(), cb, getPrograms };
184184
}
185185

src/testRunner/unittests/tscWatch/programUpdates.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -544,7 +544,7 @@ export class A {
544544
oldSnap,
545545
});
546546

547-
const {cb: cb2, getPrograms: getPrograms2 } = commandLineCallbacks(sys);
547+
const {cb: cb2, getPrograms: getPrograms2 } = commandLineCallbacks(sys, /*originalReadCall*/ undefined, sys.fileExistsWithoutTracking);
548548
const oldSnap2 = sys.snap();
549549
baseline.push("createing separate watcher");
550550
createWatchProgram(createWatchCompilerHostOfFilesAndCompilerOptionsForBaseline({

src/testRunner/unittests/tscWatch/watchApi.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -208,7 +208,7 @@ namespace ts.tscWatch {
208208
createProgram: CreateProgram<T>,
209209
optionsToExtend?: CompilerOptions,
210210
) {
211-
const { cb, getPrograms } = commandLineCallbacks(sys);
211+
const { cb, getPrograms } = commandLineCallbacks(sys, /*originalReadCall*/ undefined, sys.fileExistsWithoutTracking);
212212
baseline.push(`tsc --w${optionsToExtend?.noEmit ? " --noEmit" : ""}`);
213213
const oldSnap = sys.snap();
214214
const host = createWatchCompilerHostOfConfigFileForBaseline<T>({
@@ -384,7 +384,7 @@ namespace ts.tscWatch {
384384
// Fix error and emit
385385
applyChange(sys, baseline, sys => sys.writeFile(mainFile.path, "export const x = 10;"), "Fix error");
386386

387-
const { cb, getPrograms } = commandLineCallbacks(sys);
387+
const { cb, getPrograms } = commandLineCallbacks(sys, /*originalReadCall*/ undefined, sys.fileExistsWithoutTracking);
388388
const oldSnap = sys.snap();
389389
const reportDiagnostic = createDiagnosticReporter(sys, /*pretty*/ true);
390390
const reportWatchStatus = createWatchStatusReporter(sys, /*pretty*/ true);

tests/baselines/reference/tsbuild/amdModulesWithOut/modules-and-globals-mixed-in-amd.js

+96
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,58 @@ Output::
8383

8484
exitCode:: ExitStatus.Success
8585

86+
getModifiedTime:: {
87+
"/src/lib/file0.ts": 1,
88+
"/src/lib/file1.ts": 1,
89+
"/src/lib/file2.ts": 1,
90+
"/src/lib/global.ts": 1,
91+
"/src/app/file3.ts": 1,
92+
"/src/app/file4.ts": 1
93+
}
94+
95+
setModifiedTime:: {}
96+
97+
fileExists:: {
98+
"/src/lib/file0.ts": 1,
99+
"/src/lib/file1.ts": 1,
100+
"/src/lib/file2.ts": 1,
101+
"/src/lib/global.ts": 1,
102+
"/src/lib/module.js": 3,
103+
"/src/lib/module.d.ts": 2,
104+
"/src/app/file3.ts": 1,
105+
"/src/app/file4.ts": 1,
106+
"/src/app/module.js": 2,
107+
"/src/app/file1.ts": 1,
108+
"/src/app/file1.tsx": 1,
109+
"/src/app/file1.d.ts": 1,
110+
"/src/file1.ts": 1,
111+
"/src/file1.tsx": 1,
112+
"/src/file1.d.ts": 1,
113+
"/file1.ts": 1,
114+
"/file1.tsx": 1,
115+
"/file1.d.ts": 1,
116+
"/src/app/file1.js": 1,
117+
"/src/app/file1.jsx": 1,
118+
"/src/file1.js": 1,
119+
"/src/file1.jsx": 1,
120+
"/file1.js": 1,
121+
"/file1.jsx": 1,
122+
"/src/app/module.d.ts": 2
123+
}
124+
125+
directoryExists:: {
126+
"/src/lib/node_modules/@types": 1,
127+
"/src/node_modules/@types": 2,
128+
"/node_modules/@types": 2,
129+
"/src/app": 2,
130+
"/src": 2,
131+
"/": 2,
132+
"/src/app/node_modules": 1,
133+
"/src/node_modules": 1,
134+
"/node_modules": 1,
135+
"/src/app/node_modules/@types": 1
136+
}
137+
86138

87139
//// [/src/app/module.d.ts]
88140
declare const myGlob = 20;
@@ -952,6 +1004,50 @@ Output::
9521004

9531005
exitCode:: ExitStatus.Success
9541006

1007+
getModifiedTime:: {
1008+
"/src/lib/file0.ts": 1,
1009+
"/src/lib/file1.ts": 1,
1010+
"/src/lib/file2.ts": 1,
1011+
"/src/lib/global.ts": 1,
1012+
"/src/lib/module.js": 1,
1013+
"/src/lib/module.d.ts": 1,
1014+
"/src/app/file3.ts": 1,
1015+
"/src/app/file4.ts": 1,
1016+
"/src/app/module.js": 1,
1017+
"/src/app/module.js.map": 1,
1018+
"/src/app/module.d.ts": 3,
1019+
"/src/app/module.d.ts.map": 1,
1020+
"/src/app/module.tsbuildinfo": 1,
1021+
"/src/app/tsconfig.json": 1
1022+
}
1023+
1024+
setModifiedTime:: {
1025+
"/src/app/module.d.ts": 1,
1026+
"/src/app/module.d.ts.map": 1
1027+
}
1028+
1029+
fileExists:: {
1030+
"/src/lib/file0.ts": 1,
1031+
"/src/lib/file1.ts": 1,
1032+
"/src/lib/file2.ts": 1,
1033+
"/src/lib/global.ts": 1,
1034+
"/src/lib/module.js": 2,
1035+
"/src/lib/module.d.ts": 2,
1036+
"/src/app/file3.ts": 1,
1037+
"/src/app/file4.ts": 1,
1038+
"/src/app/module.js": 2,
1039+
"/src/app/module.js.map": 1,
1040+
"/src/app/module.d.ts": 2,
1041+
"/src/app/module.d.ts.map": 1,
1042+
"/src/app/module.tsbuildinfo": 1
1043+
}
1044+
1045+
directoryExists:: {
1046+
"/src/lib/node_modules/@types": 1,
1047+
"/src/node_modules/@types": 1,
1048+
"/node_modules/@types": 1
1049+
}
1050+
9551051

9561052
//// [/src/app/module.d.ts] file changed its modified time
9571053
//// [/src/app/module.d.ts.map] file changed its modified time

0 commit comments

Comments
 (0)