Skip to content

Commit 4468d88

Browse files
authored
Merge pull request #33566 from microsoft/baselining
PR to baseline `tsc` output rather than just baselining `tsc --b`
2 parents 992c211 + 382ff17 commit 4468d88

File tree

141 files changed

+3955
-1618
lines changed

Some content is hidden

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

141 files changed

+3955
-1618
lines changed

src/compiler/sys.ts

+2
Original file line numberDiff line numberDiff line change
@@ -678,6 +678,8 @@ namespace ts {
678678
base64decode?(input: string): string;
679679
base64encode?(input: string): string;
680680
/*@internal*/ bufferFrom?(input: string, encoding?: string): Buffer;
681+
// For testing
682+
/*@internal*/ now?(): Date;
681683
}
682684

683685
export interface FileWatcher {

src/compiler/tsbuild.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -316,7 +316,7 @@ namespace ts {
316316
*/
317317
export function createBuilderStatusReporter(system: System, pretty?: boolean): DiagnosticReporter {
318318
return diagnostic => {
319-
let output = pretty ? `[${formatColorAndReset(new Date().toLocaleTimeString(), ForegroundColorEscapeSequences.Grey)}] ` : `${new Date().toLocaleTimeString()} - `;
319+
let output = pretty ? `[${formatColorAndReset(getLocaleTimeString(system), ForegroundColorEscapeSequences.Grey)}] ` : `${getLocaleTimeString(system)} - `;
320320
output += `${flattenDiagnosticMessageText(diagnostic.messageText, system.newLine)}${system.newLine + system.newLine}`;
321321
system.write(output);
322322
};

src/compiler/watch.ts

+11-2
Original file line numberDiff line numberDiff line change
@@ -54,14 +54,23 @@ namespace ts {
5454
: newLine;
5555
}
5656

57+
/**
58+
* Get locale specific time based on whether we are in test mode
59+
*/
60+
export function getLocaleTimeString(system: System) {
61+
return !system.now ?
62+
new Date().toLocaleTimeString() :
63+
system.now().toLocaleTimeString("en-US", { timeZone: "UTC" });
64+
}
65+
5766
/**
5867
* Create a function that reports watch status by writing to the system and handles the formating of the diagnostic
5968
*/
6069
export function createWatchStatusReporter(system: System, pretty?: boolean): WatchStatusReporter {
6170
return pretty ?
6271
(diagnostic, newLine, options) => {
6372
clearScreenIfNotWatchingForFileChanges(system, diagnostic, options);
64-
let output = `[${formatColorAndReset(new Date().toLocaleTimeString(), ForegroundColorEscapeSequences.Grey)}] `;
73+
let output = `[${formatColorAndReset(getLocaleTimeString(system), ForegroundColorEscapeSequences.Grey)}] `;
6574
output += `${flattenDiagnosticMessageText(diagnostic.messageText, system.newLine)}${newLine + newLine}`;
6675
system.write(output);
6776
} :
@@ -72,7 +81,7 @@ namespace ts {
7281
output += newLine;
7382
}
7483

75-
output += `${new Date().toLocaleTimeString()} - `;
84+
output += `${getLocaleTimeString(system)} - `;
7685
output += `${flattenDiagnosticMessageText(diagnostic.messageText, system.newLine)}${getPlainDiagnosticFollowingNewLines(diagnostic, newLine)}`;
7786

7887
system.write(output);

src/harness/fakes.ts

+37-21
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ namespace fakes {
140140
}
141141

142142
public createHash(data: string): string {
143-
return data;
143+
return `${ts.generateDjb2Hash(data)}-${data}`;
144144
}
145145

146146
public realpath(path: string) {
@@ -164,6 +164,10 @@ namespace fakes {
164164
return undefined;
165165
}
166166
}
167+
168+
now() {
169+
return new Date(this.vfs.time());
170+
}
167171
}
168172

169173
/**
@@ -520,39 +524,51 @@ ${indentText}${text}`;
520524

521525
export const version = "FakeTSVersion";
522526

523-
export class SolutionBuilderHost extends CompilerHost implements ts.SolutionBuilderHost<ts.BuilderProgram> {
524-
createProgram: ts.CreateProgram<ts.BuilderProgram>;
525-
526-
constructor(sys: System | vfs.FileSystem, options?: ts.CompilerOptions, setParentNodes?: boolean, createProgram?: ts.CreateProgram<ts.BuilderProgram>) {
527-
super(sys, options, setParentNodes);
528-
this.createProgram = createProgram || ts.createEmitAndSemanticDiagnosticsBuilderProgram;
529-
}
530-
531-
readFile(path: string) {
532-
const value = super.readFile(path);
527+
export function patchSolutionBuilderHost(host: ts.SolutionBuilderHost<ts.BuilderProgram>, sys: System) {
528+
const originalReadFile = host.readFile;
529+
host.readFile = (path, encoding) => {
530+
const value = originalReadFile.call(host, path, encoding);
533531
if (!value || !ts.isBuildInfoFile(path)) return value;
534532
const buildInfo = ts.getBuildInfo(value);
535533
ts.Debug.assert(buildInfo.version === version);
536534
buildInfo.version = ts.version;
537535
return ts.getBuildInfoText(buildInfo);
536+
};
537+
538+
if (host.writeFile) {
539+
const originalWriteFile = host.writeFile;
540+
host.writeFile = (fileName, content, writeByteOrderMark) => {
541+
if (!ts.isBuildInfoFile(fileName)) return originalWriteFile.call(host, fileName, content, writeByteOrderMark);
542+
const buildInfo = ts.getBuildInfo(content);
543+
sanitizeBuildInfoProgram(buildInfo);
544+
buildInfo.version = version;
545+
originalWriteFile.call(host, fileName, ts.getBuildInfoText(buildInfo), writeByteOrderMark);
546+
};
547+
}
548+
549+
ts.Debug.assert(host.now === undefined);
550+
host.now = () => new Date(sys.vfs.time());
551+
ts.Debug.assertDefined(host.createHash);
552+
}
553+
554+
export class SolutionBuilderHost extends CompilerHost implements ts.SolutionBuilderHost<ts.BuilderProgram> {
555+
createProgram: ts.CreateProgram<ts.BuilderProgram>;
556+
557+
private constructor(sys: System | vfs.FileSystem, options?: ts.CompilerOptions, setParentNodes?: boolean, createProgram?: ts.CreateProgram<ts.BuilderProgram>) {
558+
super(sys, options, setParentNodes);
559+
this.createProgram = createProgram || ts.createEmitAndSemanticDiagnosticsBuilderProgram;
538560
}
539561

540-
public writeFile(fileName: string, content: string, writeByteOrderMark: boolean) {
541-
if (!ts.isBuildInfoFile(fileName)) return super.writeFile(fileName, content, writeByteOrderMark);
542-
const buildInfo = ts.getBuildInfo(content);
543-
sanitizeBuildInfoProgram(buildInfo);
544-
buildInfo.version = version;
545-
super.writeFile(fileName, ts.getBuildInfoText(buildInfo), writeByteOrderMark);
562+
static create(sys: System | vfs.FileSystem, options?: ts.CompilerOptions, setParentNodes?: boolean, createProgram?: ts.CreateProgram<ts.BuilderProgram>) {
563+
const host = new SolutionBuilderHost(sys, options, setParentNodes, createProgram);
564+
patchSolutionBuilderHost(host, host.sys);
565+
return host;
546566
}
547567

548568
createHash(data: string) {
549569
return `${ts.generateDjb2Hash(data)}-${data}`;
550570
}
551571

552-
now() {
553-
return new Date(this.sys.vfs.time());
554-
}
555-
556572
diagnostics: SolutionBuilderDiagnostic[] = [];
557573

558574
reportDiagnostic(diagnostic: ts.Diagnostic) {

src/testRunner/tsconfig.json

+1
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838

3939
"unittests/services/extract/helpers.ts",
4040
"unittests/tsbuild/helpers.ts",
41+
"unittests/tsc/helpers.ts",
4142
"unittests/tscWatch/helpers.ts",
4243
"unittests/tsserver/helpers.ts",
4344

src/testRunner/unittests/tsbuild/amdModulesWithOut.ts

+32-48
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
namespace ts {
22
describe("unittests:: tsbuild:: outFile:: on amd modules with --out", () => {
33
let outFileFs: vfs.FileSystem;
4-
const { time, tick } = getTime();
54
const enum project { lib, app }
65
function relName(path: string) { return path.slice(1); }
76
type Sources = [string, readonly string[]];
@@ -25,54 +24,52 @@ namespace ts {
2524
]
2625
];
2726
before(() => {
28-
outFileFs = loadProjectFromDisk("tests/projects/amdModulesWithOut", time);
27+
outFileFs = loadProjectFromDisk("tests/projects/amdModulesWithOut");
2928
});
3029
after(() => {
3130
outFileFs = undefined!;
3231
});
3332

3433
interface VerifyOutFileScenarioInput {
35-
scenario: string;
36-
modifyFs: (fs: vfs.FileSystem) => void;
34+
subScenario: string;
35+
modifyFs?: (fs: vfs.FileSystem) => void;
3736
modifyAgainFs?: (fs: vfs.FileSystem) => void;
3837
}
3938

4039
function verifyOutFileScenario({
41-
scenario,
40+
subScenario,
4241
modifyFs,
4342
modifyAgainFs
4443
}: VerifyOutFileScenarioInput) {
45-
verifyTsbuildOutput({
46-
scenario,
47-
projFs: () => outFileFs,
48-
time,
49-
tick,
50-
proj: "amdModulesWithOut",
51-
rootNames: ["/src/app"],
44+
verifyTscIncrementalEdits({
45+
scenario: "amdModulesWithOut",
46+
subScenario,
47+
fs: () => outFileFs,
48+
commandLineArgs: ["--b", "/src/app", "--verbose"],
5249
baselineSourceMap: true,
53-
initialBuild: {
54-
modifyFs
55-
},
56-
incrementalDtsUnchangedBuild: {
57-
modifyFs: fs => appendText(fs, relName(sources[project.lib][source.ts][1]), "console.log(x);")
58-
},
59-
incrementalHeaderChangedBuild: modifyAgainFs ? {
60-
modifyFs: modifyAgainFs
61-
} : undefined,
62-
baselineOnly: true
50+
modifyFs,
51+
incrementalScenarios: [
52+
{
53+
buildKind: BuildKind.IncrementalDtsUnchanged,
54+
modifyFs: fs => appendText(fs, relName(sources[project.lib][source.ts][1]), "console.log(x);")
55+
},
56+
...(modifyAgainFs ? [{
57+
buildKind: BuildKind.IncrementalHeadersChange,
58+
modifyFs: modifyAgainFs
59+
}] : emptyArray),
60+
]
6361
});
6462
}
6563

6664
describe("Prepend output with .tsbuildinfo", () => {
6765
verifyOutFileScenario({
68-
scenario: "modules and globals mixed in amd",
69-
modifyFs: noop
66+
subScenario: "modules and globals mixed in amd",
7067
});
7168

7269
// Prologues
7370
describe("Prologues", () => {
7471
verifyOutFileScenario({
75-
scenario: "multiple prologues in all projects",
72+
subScenario: "multiple prologues in all projects",
7673
modifyFs: fs => {
7774
enableStrict(fs, sources[project.lib][source.config]);
7875
addTestPrologue(fs, sources[project.lib][source.ts][0], `"myPrologue"`);
@@ -90,7 +87,7 @@ namespace ts {
9087
describe("Shebang", () => {
9188
// changes declaration because its emitted in .d.ts file
9289
verifyOutFileScenario({
93-
scenario: "shebang in all projects",
90+
subScenario: "shebang in all projects",
9491
modifyFs: fs => {
9592
addShebang(fs, "lib", "file0");
9693
addShebang(fs, "lib", "file1");
@@ -102,7 +99,7 @@ namespace ts {
10299
// emitHelpers
103100
describe("emitHelpers", () => {
104101
verifyOutFileScenario({
105-
scenario: "multiple emitHelpers in all projects",
102+
subScenario: "multiple emitHelpers in all projects",
106103
modifyFs: fs => {
107104
addSpread(fs, "lib", "file0");
108105
addRest(fs, "lib", "file1");
@@ -117,7 +114,7 @@ namespace ts {
117114
describe("triple slash refs", () => {
118115
// changes declaration because its emitted in .d.ts file
119116
verifyOutFileScenario({
120-
scenario: "triple slash refs in all projects",
117+
subScenario: "triple slash refs in all projects",
121118
modifyFs: fs => {
122119
addTripleSlashRef(fs, "lib", "file0");
123120
addTripleSlashRef(fs, "app", "file4");
@@ -161,7 +158,7 @@ ${internal} export enum internalEnum { a, b, c }`);
161158

162159
// Verify initial + incremental edits
163160
verifyOutFileScenario({
164-
scenario: "stripInternal",
161+
subScenario: "stripInternal",
165162
modifyFs: stripInternalScenario,
166163
modifyAgainFs: fs => replaceText(fs, sources[project.lib][source.ts][1], `export const`, `/*@internal*/ export const`),
167164
});
@@ -175,26 +172,13 @@ ${internal} export enum internalEnum { a, b, c }`);
175172
replaceText(fs, sources[project.app][source.ts][0], "file1", "lib/file1");
176173
}
177174

178-
verifyTsbuildOutput({
179-
scenario: "when the module resolution finds original source file",
180-
projFs: () => outFileFs,
181-
time,
182-
tick,
183-
proj: "amdModulesWithOut",
184-
rootNames: ["/src/app"],
175+
verifyTsc({
176+
scenario: "amdModulesWithOut",
177+
subScenario: "when the module resolution finds original source file",
178+
fs: () => outFileFs,
179+
commandLineArgs: ["-b", "/src/app", "--verbose"],
180+
modifyFs,
185181
baselineSourceMap: true,
186-
initialBuild: {
187-
modifyFs,
188-
expectedDiagnostics: [
189-
getExpectedDiagnosticForProjectsInBuild("src/lib/tsconfig.json", "src/app/tsconfig.json"),
190-
[Diagnostics.Project_0_is_out_of_date_because_output_file_1_does_not_exist, "src/lib/tsconfig.json", "src/module.js"],
191-
[Diagnostics.Building_project_0, sources[project.lib][source.config]],
192-
[Diagnostics.Project_0_is_out_of_date_because_output_file_1_does_not_exist, "src/app/tsconfig.json", "src/app/module.js"],
193-
[Diagnostics.Building_project_0, sources[project.app][source.config]],
194-
]
195-
},
196-
baselineOnly: true,
197-
verifyDiagnostics: true
198182
});
199183
});
200184
});

src/testRunner/unittests/tsbuild/containerOnlyReferenced.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ namespace ts {
1919

2020
it("verify that subsequent builds after initial build doesnt build anything", () => {
2121
const fs = projFs.shadow();
22-
const host = new fakes.SolutionBuilderHost(fs);
22+
const host = fakes.SolutionBuilderHost.create(fs);
2323
createSolutionBuilder(host, ["/src"], { verbose: true }).build();
2424
host.assertDiagnosticMessages(
2525
getExpectedDiagnosticForProjectsInBuild("src/src/folder/tsconfig.json", "src/src/folder2/tsconfig.json", "src/src/tsconfig.json", "src/tests/tsconfig.json", "src/tsconfig.json"),

src/testRunner/unittests/tsbuild/demo.ts

+2-4
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,8 @@
11
namespace ts {
22
describe("unittests:: tsbuild:: on demo project", () => {
33
let projFs: vfs.FileSystem;
4-
const { time } = getTime();
5-
64
before(() => {
7-
projFs = loadProjectFromDisk("tests/projects/demo", time);
5+
projFs = loadProjectFromDisk("tests/projects/demo");
86
});
97

108
after(() => {
@@ -49,7 +47,7 @@ namespace ts {
4947

5048
function verifyBuild({ modifyDiskLayout, expectedExitStatus, expectedDiagnostics, expectedOutputs, notExpectedOutputs }: VerifyBuild) {
5149
const fs = projFs.shadow();
52-
const host = new fakes.SolutionBuilderHost(fs);
50+
const host = fakes.SolutionBuilderHost.create(fs);
5351
modifyDiskLayout(fs);
5452
const builder = createSolutionBuilder(host, ["/src/tsconfig.json"], { verbose: true });
5553
const exitStatus = builder.build();

0 commit comments

Comments
 (0)