Skip to content

Commit ab2523b

Browse files
authored
Handles time on vfs and write non empty shadowed files in baseline even if they were not read (#48703)
* Use fixed time for vfs so baselining is consistent * Baseline buildinfos * Write new file text in baseline even if the file wasnt read on the shadow * Remove unnecessary debugger statement
1 parent 7a59e45 commit ab2523b

File tree

130 files changed

+5568
-1663
lines changed

Some content is hidden

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

130 files changed

+5568
-1663
lines changed

src/harness/vfsUtil.ts

+11-13
Original file line numberDiff line numberDiff line change
@@ -55,12 +55,12 @@ namespace vfs {
5555
} = {};
5656

5757
private _cwd: string; // current working directory
58-
private _time: number | Date | (() => number | Date);
58+
private _time: number;
5959
private _shadowRoot: FileSystem | undefined;
6060
private _dirStack: string[] | undefined;
6161

6262
constructor(ignoreCase: boolean, options: FileSystemOptions = {}) {
63-
const { time = -1, files, meta } = options;
63+
const { time = ts.TestFSWithWatch.timeIncrements, files, meta } = options;
6464
this.ignoreCase = ignoreCase;
6565
this.stringComparer = this.ignoreCase ? vpath.compareCaseInsensitive : vpath.compareCaseSensitive;
6666
this._time = time;
@@ -167,16 +167,15 @@ namespace vfs {
167167
*
168168
* @link http://pubs.opengroup.org/onlinepubs/9699919799/functions/time.html
169169
*/
170-
public time(value?: number | Date | (() => number | Date)): number {
171-
if (value !== undefined && this.isReadonly) throw createIOError("EPERM");
172-
let result = this._time;
173-
if (typeof result === "function") result = result();
174-
if (typeof result === "object") result = result.getTime();
175-
if (result === -1) result = Date.now();
170+
public time(value?: number): number {
176171
if (value !== undefined) {
172+
if (this.isReadonly) throw createIOError("EPERM");
177173
this._time = value;
178174
}
179-
return result;
175+
else if (!this.isReadonly) {
176+
this._time += ts.TestFSWithWatch.timeIncrements;
177+
}
178+
return this._time;
180179
}
181180

182181
/**
@@ -843,7 +842,7 @@ namespace vfs {
843842
container[basename] = new Symlink(node.symlink);
844843
}
845844
else {
846-
container[basename] = new File(node.buffer || "");
845+
container[basename] = new File(changed._getBuffer(node));
847846
}
848847
return true;
849848
}
@@ -1172,9 +1171,8 @@ namespace vfs {
11721171
}
11731172

11741173
export interface FileSystemOptions {
1175-
// Sets the initial timestamp for new files and directories, or the function used
1176-
// to calculate timestamps.
1177-
time?: number | Date | (() => number | Date);
1174+
// Sets the initial timestamp for new files and directories
1175+
time?: number;
11781176

11791177
// A set of file system entries to initially add to the file system.
11801178
files?: FileSet;

src/harness/virtualFileSystemWithWatch.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -360,7 +360,7 @@ interface Array<T> { length: number; [n: number]: T; }`
360360
DynamicPolling = "RecursiveDirectoryUsingDynamicPriorityPolling"
361361
}
362362

363-
const timeIncrements = 1000;
363+
export const timeIncrements = 1000;
364364
export interface TestServerHostOptions {
365365
useCaseSensitiveFileNames: boolean;
366366
executingFilePath: string;

src/testRunner/unittests/tsbuild/helpers.ts

+5-58
Original file line numberDiff line numberDiff line change
@@ -78,26 +78,6 @@ namespace ts {
7878
};
7979
}
8080

81-
export function getTime() {
82-
let currentTime = 100;
83-
return { tick, time, touch };
84-
85-
function tick() {
86-
currentTime += 60_000;
87-
}
88-
89-
function time() {
90-
return currentTime;
91-
}
92-
93-
function touch(fs: vfs.FileSystem, path: string) {
94-
if (!fs.statSync(path).isFile()) {
95-
throw new Error(`File ${path} does not exist`);
96-
}
97-
fs.utimesSync(path, new Date(time()), new Date(time()));
98-
}
99-
}
100-
10181
export const libContent = `${TestFSWithWatch.libFile.content}
10282
interface ReadonlyArray<T> {}
10383
declare const console: { log(msg: any): void; };`;
@@ -154,26 +134,6 @@ interface Symbol {
154134
fs.makeReadonly();
155135
}
156136

157-
/**
158-
* Gets the FS mountuing existing fs's /src and /lib folder
159-
*/
160-
export function getFsWithTime(baseFs: vfs.FileSystem) {
161-
const { time, tick } = getTime();
162-
const host = new fakes.System(baseFs) as any as vfs.FileSystemResolverHost;
163-
host.getWorkspaceRoot = notImplemented;
164-
const resolver = vfs.createResolver(host);
165-
const fs = new vfs.FileSystem(/*ignoreCase*/ true, {
166-
files: {
167-
["/src"]: new vfs.Mount("/src", resolver),
168-
["/lib"]: new vfs.Mount("/lib", resolver)
169-
},
170-
cwd: "/",
171-
meta: { defaultLibLocation: "/lib" },
172-
time
173-
});
174-
return { fs, time, tick };
175-
}
176-
177137
export function verifyOutputsPresent(fs: vfs.FileSystem, outputs: readonly string[]) {
178138
for (const output of outputs) {
179139
assert(fs.existsSync(output), `Expect file ${output} to exist`);
@@ -336,7 +296,6 @@ interface Symbol {
336296
commandLineArgs: TestTscCompile["commandLineArgs"];
337297
modifyFs: TestTscCompile["modifyFs"];
338298
editFs: TestTscEdit["modifyFs"];
339-
tick: () => void;
340299
baseFs: vfs.FileSystem;
341300
newSys: TscCompileSystem;
342301
cleanBuildDiscrepancies: TestTscEdit["cleanBuildDiscrepancies"];
@@ -347,15 +306,14 @@ interface Symbol {
347306
const {
348307
scenario, commandLineArgs, cleanBuildDiscrepancies,
349308
modifyFs, editFs,
350-
tick, baseFs, newSys
309+
baseFs, newSys
351310
} = input();
352311
const sys = testTscCompile({
353312
scenario,
354313
subScenario,
355314
fs: () => baseFs.makeReadonly(),
356315
commandLineArgs,
357316
modifyFs: fs => {
358-
tick();
359317
if (modifyFs) modifyFs(fs);
360318
editFs(fs);
361319
},
@@ -532,22 +490,18 @@ interface Symbol {
532490
edits
533491
}: VerifyTscWithEditsWorkerInput) {
534492
describe(`tsc ${commandLineArgs.join(" ")} ${scenario}:: ${subScenario} serializedEdits`, () => {
535-
let tick: () => void;
536493
let sys: TscCompileSystem;
537494
let baseFs: vfs.FileSystem;
538495
let editsSys: TscCompileSystem[];
539496
before(() => {
540497
Debug.assert(!!edits.length, `${scenario}/${subScenario}:: No incremental scenarios, you probably want to use verifyTsc instead.`);
541-
({ fs: baseFs, tick } = getFsWithTime(fs()));
498+
baseFs = fs().makeReadonly();
542499
sys = testTscCompile({
543500
scenario,
544501
subScenario,
545-
fs: () => baseFs.makeReadonly(),
502+
fs: () => baseFs,
546503
commandLineArgs,
547-
modifyFs: fs => {
548-
if (modifyFs) modifyFs(fs);
549-
tick();
550-
},
504+
modifyFs,
551505
baselineSourceMap,
552506
baselineReadFileCalls,
553507
baselinePrograms
@@ -556,18 +510,13 @@ interface Symbol {
556510
{ modifyFs, subScenario: editScenario, commandLineArgs: editCommandLineArgs },
557511
index
558512
) => {
559-
tick();
560513
(editsSys || (editsSys = [])).push(testTscCompile({
561514
scenario,
562515
subScenario: editScenario || subScenario,
563516
diffWithInitial: true,
564517
fs: () => index === 0 ? sys.vfs : editsSys[index - 1].vfs,
565518
commandLineArgs: editCommandLineArgs || commandLineArgs,
566-
modifyFs: fs => {
567-
tick();
568-
modifyFs(fs);
569-
tick();
570-
},
519+
modifyFs,
571520
baselineSourceMap,
572521
baselineReadFileCalls,
573522
baselinePrograms
@@ -577,7 +526,6 @@ interface Symbol {
577526
after(() => {
578527
baseFs = undefined!;
579528
sys = undefined!;
580-
tick = undefined!;
581529
editsSys = undefined!;
582530
});
583531
describe("tsc invocation after edit", () => {
@@ -608,7 +556,6 @@ interface Symbol {
608556
}
609557
},
610558
modifyFs,
611-
tick
612559
}), index, subScenario));
613560
});
614561
});

src/testRunner/unittests/tsbuild/outFile.ts

+6-9
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,6 @@ namespace ts {
1010
outFileWithBuildFs = undefined!;
1111
});
1212

13-
function createSolutionBuilder(host: fakes.SolutionBuilderHost, baseOptions?: BuildOptions) {
14-
return ts.createSolutionBuilder(host, ["/src/third"], { dry: false, force: false, verbose: true, ...(baseOptions || {}) });
15-
}
16-
1713
interface VerifyOutFileScenarioInput {
1814
subScenario: string;
1915
modifyFs?: (fs: vfs.FileSystem) => void;
@@ -108,8 +104,9 @@ namespace ts {
108104
function getOutFileFsAfterBuild() {
109105
if (outFileWithBuildFs) return outFileWithBuildFs;
110106
const fs = outFileFs.shadow();
111-
const host = fakes.SolutionBuilderHost.create(fs);
112-
const builder = createSolutionBuilder(host);
107+
const sys = new fakes.System(fs, { executingFilePath: "/lib/tsc" });
108+
const host = createSolutionBuilderHostForBaseline(sys as TscCompileSystem);
109+
const builder = createSolutionBuilder(host, ["/src/third"], { dry: false, force: false, verbose: true });
113110
builder.build();
114111
fs.makeReadonly();
115112
return outFileWithBuildFs = fs;
@@ -147,7 +144,7 @@ namespace ts {
147144
compile: sys => {
148145
// Buildinfo will have version which does not match with current ts version
149146
const buildHost = createSolutionBuilderHostForBaseline(sys, "FakeTSCurrentVersion");
150-
const builder = ts.createSolutionBuilder(buildHost, ["/src/third"], { verbose: true });
147+
const builder = createSolutionBuilder(buildHost, ["/src/third"], { verbose: true });
151148
sys.exit(builder.build());
152149
}
153150
});
@@ -181,7 +178,7 @@ namespace ts {
181178
commandLineArgs: ["--build", "/src/second/tsconfig.json"],
182179
compile: sys => {
183180
const buildHost = createSolutionBuilderHostForBaseline(sys);
184-
const builder = ts.createSolutionBuilder(buildHost, ["/src/third/tsconfig.json"], {});
181+
const builder = createSolutionBuilder(buildHost, ["/src/third/tsconfig.json"], {});
185182
sys.exit(builder.build("/src/second/tsconfig.json"));
186183
}
187184
});
@@ -193,7 +190,7 @@ namespace ts {
193190
commandLineArgs: ["--build", "--clean", "/src/second/tsconfig.json"],
194191
compile: sys => {
195192
const buildHost = createSolutionBuilderHostForBaseline(sys);
196-
const builder = ts.createSolutionBuilder(buildHost, ["/src/third/tsconfig.json"], { verbose: true });
193+
const builder = createSolutionBuilder(buildHost, ["/src/third/tsconfig.json"], { verbose: true });
197194
sys.exit(builder.clean("/src/second/tsconfig.json"));
198195
}
199196
});

src/testRunner/unittests/tsbuild/publicApi.ts

+2-4
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ namespace ts {
22
describe("unittests:: tsbuild:: Public API with custom transformers when passed to build", () => {
33
let sys: TscCompileSystem;
44
before(() => {
5-
const initialFs = getFsWithTime(loadProjectFromFiles({
5+
const inputFs = loadProjectFromFiles({
66
"/src/tsconfig.json": JSON.stringify({
77
references: [
88
{ path: "./shared/tsconfig.json" },
@@ -29,9 +29,7 @@ export class c2 { }
2929
export enum e2 { }
3030
// leading
3131
export function f22() { } // trailing`,
32-
})).fs.makeReadonly();
33-
const inputFs = initialFs.shadow();
34-
inputFs.makeReadonly();
32+
}).makeReadonly();
3533
const fs = inputFs.shadow();
3634

3735
// Create system

src/testRunner/unittests/tsbuild/sample.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,8 @@ namespace ts {
2121
function getSampleFsAfterBuild() {
2222
if (projFsWithBuild) return projFsWithBuild;
2323
const fs = projFs.shadow();
24-
const host = fakes.SolutionBuilderHost.create(fs);
24+
const sys = new fakes.System(fs, { executingFilePath: "/lib/tsc" });
25+
const host = createSolutionBuilderHostForBaseline(sys as TscCompileSystem);
2526
const builder = createSolutionBuilder(host, ["/src/tests"], {});
2627
builder.build();
2728
fs.makeReadonly();

src/testRunner/unittests/tsc/helpers.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -214,7 +214,7 @@ ${patch ? vfs.formatPatch(patch) : ""}`
214214
describe(input.subScenario, () => {
215215
verifyTscBaseline(() => verifier({
216216
...input,
217-
fs: () => getFsWithTime(input.fs()).fs.makeReadonly()
217+
fs: () => input.fs().makeReadonly()
218218
}));
219219
});
220220
});

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

+11-11
Original file line numberDiff line numberDiff line change
@@ -69,17 +69,17 @@ const globalConst = 10;
6969

7070
Output::
7171
/lib/tsc --b /src/app --verbose
72-
[[90m12:01:00 AM[0m] Projects in this build:
72+
[[90m12:00:06 AM[0m] Projects in this build:
7373
* src/lib/tsconfig.json
7474
* src/app/tsconfig.json
7575

76-
[[90m12:01:00 AM[0m] Project 'src/lib/tsconfig.json' is out of date because output file 'src/lib/module.js' does not exist
76+
[[90m12:00:07 AM[0m] Project 'src/lib/tsconfig.json' is out of date because output file 'src/lib/module.js' does not exist
7777

78-
[[90m12:01:00 AM[0m] Building project '/src/lib/tsconfig.json'...
78+
[[90m12:00:08 AM[0m] Building project '/src/lib/tsconfig.json'...
7979

80-
[[90m12:01:00 AM[0m] Project 'src/app/tsconfig.json' is out of date because output file 'src/app/module.js' does not exist
80+
[[90m12:00:16 AM[0m] Project 'src/app/tsconfig.json' is out of date because output file 'src/app/module.js' does not exist
8181

82-
[[90m12:01:00 AM[0m] Building project '/src/app/tsconfig.json'...
82+
[[90m12:00:17 AM[0m] Building project '/src/app/tsconfig.json'...
8383

8484
exitCode:: ExitStatus.Success
8585

@@ -936,19 +936,19 @@ export const x = 10;console.log(x);
936936

937937
Output::
938938
/lib/tsc --b /src/app --verbose
939-
[[90m12:04:00 AM[0m] Projects in this build:
939+
[[90m12:00:30 AM[0m] Projects in this build:
940940
* src/lib/tsconfig.json
941941
* src/app/tsconfig.json
942942

943-
[[90m12:04:00 AM[0m] Project 'src/lib/tsconfig.json' is out of date because oldest output 'src/lib/module.js' is older than newest input 'src/lib/file1.ts'
943+
[[90m12:00:31 AM[0m] Project 'src/lib/tsconfig.json' is out of date because oldest output 'src/lib/module.js' is older than newest input 'src/lib/file1.ts'
944944

945-
[[90m12:04:00 AM[0m] Building project '/src/lib/tsconfig.json'...
945+
[[90m12:00:32 AM[0m] Building project '/src/lib/tsconfig.json'...
946946

947-
[[90m12:04:00 AM[0m] Project 'src/app/tsconfig.json' is out of date because output of its dependency 'src/lib' has changed
947+
[[90m12:00:40 AM[0m] Project 'src/app/tsconfig.json' is out of date because output of its dependency 'src/lib' has changed
948948

949-
[[90m12:04:00 AM[0m] Updating output of project '/src/app/tsconfig.json'...
949+
[[90m12:00:41 AM[0m] Updating output of project '/src/app/tsconfig.json'...
950950

951-
[[90m12:04:00 AM[0m] Updating unchanged output timestamps of project '/src/app/tsconfig.json'...
951+
[[90m12:00:46 AM[0m] Updating unchanged output timestamps of project '/src/app/tsconfig.json'...
952952

953953
exitCode:: ExitStatus.Success
954954

0 commit comments

Comments
 (0)