Skip to content

Commit 3fd8a6e

Browse files
authored
Some refactoring for baselining for easy update (#48516)
* Some refactoring for baselining for easy update * Set modified time in baseline * Some renames per feedback
1 parent 16b6f0f commit 3fd8a6e

File tree

120 files changed

+12955
-1213
lines changed

Some content is hidden

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

120 files changed

+12955
-1213
lines changed

src/executeCommandLine/executeCommandLine.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -649,7 +649,7 @@ namespace ts {
649649
return false;
650650
}
651651

652-
export type ExecuteCommandLineCallbacks = (program: Program | EmitAndSemanticDiagnosticsBuilderProgram | ParsedCommandLine) => void;
652+
export type ExecuteCommandLineCallbacks = (program: Program | BuilderProgram | ParsedCommandLine) => void;
653653
export function executeCommandLine(
654654
system: System,
655655
cb: ExecuteCommandLineCallbacks,

src/harness/fakesHosts.ts

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -511,18 +511,19 @@ ${indentText}${text}`;
511511
buildInfo.version = ts.version;
512512
return ts.getBuildInfoText(buildInfo);
513513
};
514+
return patchHostForBuildInfoWrite(sys, version);
515+
}
516+
517+
export function patchHostForBuildInfoWrite<T extends ts.System>(sys: T, version: string) {
514518
const originalWrite = sys.write;
515519
sys.write = msg => originalWrite.call(sys, msg.replace(ts.version, version));
516-
517-
if (sys.writeFile) {
518-
const originalWriteFile = sys.writeFile;
519-
sys.writeFile = (fileName: string, content: string, writeByteOrderMark: boolean) => {
520-
if (!ts.isBuildInfoFile(fileName)) return originalWriteFile.call(sys, fileName, content, writeByteOrderMark);
521-
const buildInfo = ts.getBuildInfo(content);
522-
buildInfo.version = version;
523-
originalWriteFile.call(sys, fileName, ts.getBuildInfoText(buildInfo), writeByteOrderMark);
524-
};
525-
}
520+
const originalWriteFile = sys.writeFile;
521+
sys.writeFile = (fileName: string, content: string, writeByteOrderMark: boolean) => {
522+
if (!ts.isBuildInfoFile(fileName)) return originalWriteFile.call(sys, fileName, content, writeByteOrderMark);
523+
const buildInfo = ts.getBuildInfo(content);
524+
buildInfo.version = version;
525+
originalWriteFile.call(sys, fileName, ts.getBuildInfoText(buildInfo), writeByteOrderMark);
526+
};
526527
return sys;
527528
}
528529

src/harness/vfsUtil.ts

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -809,7 +809,11 @@ namespace vfs {
809809
const baseBuffer = base._getBuffer(baseNode);
810810

811811
// no difference if both buffers are the same reference
812-
if (changedBuffer === baseBuffer) return false;
812+
if (changedBuffer === baseBuffer) {
813+
if (!options.includeChangedFileWithSameContent || changedNode.mtimeMs === baseNode.mtimeMs) return false;
814+
container[basename] = new SameFileWithModifiedTime(changedBuffer);
815+
return true;
816+
}
813817

814818
// no difference if both buffers are identical
815819
if (Buffer.compare(changedBuffer, baseBuffer) === 0) {
@@ -1391,6 +1395,12 @@ namespace vfs {
13911395
}
13921396
}
13931397

1398+
export class SameFileWithModifiedTime extends File {
1399+
constructor(data: Buffer | string, metaAndEncoding?: { encoding?: string, meta?: Record<string, any> }) {
1400+
super(data, metaAndEncoding);
1401+
}
1402+
}
1403+
13941404
/** Extended options for a hard link in a `FileSet` */
13951405
export class Link {
13961406
public readonly path: string;
@@ -1579,6 +1589,9 @@ namespace vfs {
15791589
else if (entry instanceof Directory) {
15801590
text += formatPatchWorker(file, entry.files);
15811591
}
1592+
else if (entry instanceof SameFileWithModifiedTime) {
1593+
text += `//// [${file}] file changed its modified time\r\n`;
1594+
}
15821595
else if (entry instanceof SameFileContentFile) {
15831596
text += `//// [${file}] file written with same contents\r\n`;
15841597
}

src/testRunner/unittests/tsbuild/amdModulesWithOut.ts

Lines changed: 15 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,6 @@
11
namespace ts {
22
describe("unittests:: tsbuild:: outFile:: on amd modules with --out", () => {
33
let outFileFs: vfs.FileSystem;
4-
const enum Project { lib, app }
5-
function relName(path: string) {
6-
return path.slice(1);
7-
}
8-
type Sources = [string, readonly string[]];
9-
const enum Source { config, ts }
10-
const sources: [Sources, Sources] = [
11-
[
12-
"/src/lib/tsconfig.json",
13-
[
14-
"/src/lib/file0.ts",
15-
"/src/lib/file1.ts",
16-
"/src/lib/file2.ts",
17-
"/src/lib/global.ts",
18-
]
19-
],
20-
[
21-
"/src/app/tsconfig.json",
22-
[
23-
"/src/app/file3.ts",
24-
"/src/app/file4.ts"
25-
]
26-
]
27-
];
284
before(() => {
295
outFileFs = loadProjectFromDisk("tests/projects/amdModulesWithOut");
306
});
@@ -53,7 +29,7 @@ namespace ts {
5329
incrementalScenarios: [
5430
{
5531
buildKind: BuildKind.IncrementalDtsUnchanged,
56-
modifyFs: fs => appendText(fs, relName(sources[Project.lib][Source.ts][1]), "console.log(x);")
32+
modifyFs: fs => appendText(fs, "/src/lib/file1.ts", "console.log(x);")
5733
},
5834
...(modifyAgainFs ? [{
5935
buildKind: BuildKind.IncrementalHeadersChange,
@@ -73,15 +49,15 @@ namespace ts {
7349
verifyOutFileScenario({
7450
subScenario: "multiple prologues in all projects",
7551
modifyFs: fs => {
76-
enableStrict(fs, sources[Project.lib][Source.config]);
77-
addTestPrologue(fs, sources[Project.lib][Source.ts][0], `"myPrologue"`);
78-
addTestPrologue(fs, sources[Project.lib][Source.ts][2], `"myPrologueFile"`);
79-
addTestPrologue(fs, sources[Project.lib][Source.ts][3], `"myPrologue3"`);
80-
enableStrict(fs, sources[Project.app][Source.config]);
81-
addTestPrologue(fs, sources[Project.app][Source.ts][0], `"myPrologue"`);
82-
addTestPrologue(fs, sources[Project.app][Source.ts][1], `"myPrologue2";`);
52+
enableStrict(fs, "/src/lib/tsconfig.json");
53+
addTestPrologue(fs, "/src/lib/file0.ts", `"myPrologue"`);
54+
addTestPrologue(fs, "/src/lib/file2.ts", `"myPrologueFile"`);
55+
addTestPrologue(fs, "/src/lib/global.ts", `"myPrologue3"`);
56+
enableStrict(fs, "/src/app/tsconfig.json");
57+
addTestPrologue(fs, "/src/app/file3.ts", `"myPrologue"`);
58+
addTestPrologue(fs, "/src/app/file4.ts", `"myPrologue2";`);
8359
},
84-
modifyAgainFs: fs => addTestPrologue(fs, relName(sources[Project.lib][Source.ts][1]), `"myPrologue5"`)
60+
modifyAgainFs: fs => addTestPrologue(fs, "/src/lib/file1.ts", `"myPrologue5"`)
8561
});
8662
});
8763

@@ -127,10 +103,10 @@ namespace ts {
127103
describe("stripInternal", () => {
128104
function stripInternalScenario(fs: vfs.FileSystem) {
129105
const internal = "/*@internal*/";
130-
replaceText(fs, sources[Project.app][Source.config], `"composite": true,`, `"composite": true,
106+
replaceText(fs, "/src/app/tsconfig.json", `"composite": true,`, `"composite": true,
131107
"stripInternal": true,`);
132-
replaceText(fs, sources[Project.lib][Source.ts][0], "const", `${internal} const`);
133-
appendText(fs, sources[Project.lib][Source.ts][1], `
108+
replaceText(fs, "/src/lib/file0.ts", "const", `${internal} const`);
109+
appendText(fs, "/src/lib/file1.ts", `
134110
export class normalC {
135111
${internal} constructor() { }
136112
${internal} prop: string;
@@ -162,16 +138,16 @@ ${internal} export enum internalEnum { a, b, c }`);
162138
verifyOutFileScenario({
163139
subScenario: "stripInternal",
164140
modifyFs: stripInternalScenario,
165-
modifyAgainFs: fs => replaceText(fs, sources[Project.lib][Source.ts][1], `export const`, `/*@internal*/ export const`),
141+
modifyAgainFs: fs => replaceText(fs, "/src/lib/file1.ts", `export const`, `/*@internal*/ export const`),
166142
});
167143
});
168144

169145
describe("when the module resolution finds original source file", () => {
170146
function modifyFs(fs: vfs.FileSystem) {
171147
// Make lib to output to parent dir
172-
replaceText(fs, sources[Project.lib][Source.config], `"outFile": "module.js"`, `"outFile": "../module.js", "rootDir": "../"`);
148+
replaceText(fs, "/src/lib/tsconfig.json", `"outFile": "module.js"`, `"outFile": "../module.js", "rootDir": "../"`);
173149
// Change reference to file1 module to resolve to lib/file1
174-
replaceText(fs, sources[Project.app][Source.ts][0], "file1", "lib/file1");
150+
replaceText(fs, "/src/app/file3.ts", "file1", "lib/file1");
175151
}
176152

177153
verifyTsc({

src/testRunner/unittests/tsbuild/helpers.ts

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -332,23 +332,23 @@ interface Symbol {
332332
}
333333

334334
interface VerifyIncrementalCorrectness {
335-
scenario: TscCompile["scenario"];
336-
commandLineArgs: TscCompile["commandLineArgs"];
337-
modifyFs: TscCompile["modifyFs"];
335+
scenario: TestTscCompile["scenario"];
336+
commandLineArgs: TestTscCompile["commandLineArgs"];
337+
modifyFs: TestTscCompile["modifyFs"];
338338
incrementalModifyFs: TscIncremental["modifyFs"];
339339
tick: () => void;
340340
baseFs: vfs.FileSystem;
341341
newSys: TscCompileSystem;
342342
cleanBuildDiscrepancies: TscIncremental["cleanBuildDiscrepancies"];
343343
}
344-
function verifyIncrementalCorrectness(input: () => VerifyIncrementalCorrectness, index: number, subScenario: TscCompile["subScenario"]) {
344+
function verifyIncrementalCorrectness(input: () => VerifyIncrementalCorrectness, index: number, subScenario: TestTscCompile["subScenario"]) {
345345
it(`Verify emit output file text is same when built clean for incremental scenario at:: ${index} ${subScenario}`, () => {
346346
const {
347347
scenario, commandLineArgs, cleanBuildDiscrepancies,
348348
modifyFs, incrementalModifyFs,
349349
tick, baseFs, newSys
350350
} = input();
351-
const sys = tscCompile({
351+
const sys = testTscCompile({
352352
scenario,
353353
subScenario,
354354
fs: () => baseFs.makeReadonly(),
@@ -521,7 +521,7 @@ interface Symbol {
521521
}
522522
}
523523

524-
export interface VerifyTsBuildInputWorker extends TscCompile {
524+
export interface VerifyTsBuildInputWorker extends TestTscCompile {
525525
incrementalScenarios: TscIncremental[];
526526
}
527527
function verifyTscIncrementalEditsWorker({
@@ -535,7 +535,7 @@ interface Symbol {
535535
let baseFs: vfs.FileSystem;
536536
before(() => {
537537
({ fs: baseFs, tick } = getFsWithTime(fs()));
538-
sys = tscCompile({
538+
sys = testTscCompile({
539539
scenario,
540540
subScenario,
541541
fs: () => baseFs.makeReadonly(),
@@ -571,7 +571,7 @@ interface Symbol {
571571
before(() => {
572572
Debug.assert(buildKind !== BuildKind.Initial, "Incremental edit cannot be initial compilation");
573573
tick();
574-
newSys = tscCompile({
574+
newSys = testTscCompile({
575575
scenario,
576576
subScenario: incrementalSubScenario || subScenario,
577577
buildKind,
@@ -629,7 +629,7 @@ interface Symbol {
629629
let incrementalSys: TscCompileSystem[];
630630
before(() => {
631631
({ fs: baseFs, tick } = getFsWithTime(fs()));
632-
sys = tscCompile({
632+
sys = testTscCompile({
633633
scenario,
634634
subScenario,
635635
fs: () => baseFs.makeReadonly(),
@@ -648,7 +648,7 @@ interface Symbol {
648648
) => {
649649
Debug.assert(buildKind !== BuildKind.Initial, "Incremental edit cannot be initial compilation");
650650
tick();
651-
(incrementalSys || (incrementalSys = [])).push(tscCompile({
651+
(incrementalSys || (incrementalSys = [])).push(testTscCompile({
652652
scenario,
653653
subScenario: incrementalSubScenario || subScenario,
654654
buildKind,

0 commit comments

Comments
 (0)