Skip to content

Commit ecb2ce4

Browse files
committed
Add tests that will verify that all rebuilding with new compiler version builds again
1 parent 409d6c9 commit ecb2ce4

File tree

3 files changed

+59
-24
lines changed

3 files changed

+59
-24
lines changed

src/testRunner/unittests/tsbuild/helpers.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,17 @@ namespace ts {
33
return [Diagnostics.Projects_in_this_build_Colon_0, projects.map(p => "\r\n * " + p).join("")];
44
}
55

6+
export function changeCompilerVersion(host: fakes.SolutionBuilderHost) {
7+
const originalReadFile = host.readFile;
8+
host.readFile = path => {
9+
const value = originalReadFile.call(host, path);
10+
if (!value || !isBuildInfoFile(path)) return value;
11+
const buildInfo = JSON.parse(value) as BuildInfo;
12+
buildInfo.version = fakes.version;
13+
return getBuildInfoText(buildInfo);
14+
};
15+
}
16+
617
export function replaceText(fs: vfs.FileSystem, path: string, oldText: string, newText: string) {
718
if (!fs.statSync(path).isFile()) {
819
throw new Error(`File ${path} does not exist`);

src/testRunner/unittests/tsbuild/outFile.ts

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -438,6 +438,25 @@ namespace ts {
438438
assert.isFalse(fs.existsSync(outputFiles[project.third][ext.buildinfo]), `Expect file ${outputFiles[project.third][ext.buildinfo]} to not exist`);
439439
});
440440

441+
it("rebuilds completely when version in tsbuildinfo doesnt match ts version", () => {
442+
const fs = outFileFs.shadow();
443+
const host = new fakes.SolutionBuilderHost(fs);
444+
const builder = createSolutionBuilder(host);
445+
builder.buildAllProjects();
446+
host.assertDiagnosticMessages(...initialExpectedDiagnostics);
447+
host.clearDiagnostics();
448+
builder.resetBuildContext();
449+
changeCompilerVersion(host);
450+
builder.buildAllProjects();
451+
host.assertDiagnosticMessages(
452+
// TODO:: This should build all instead
453+
getExpectedDiagnosticForProjectsInBuild(relSources[project.first][source.config], relSources[project.second][source.config], relSources[project.third][source.config]),
454+
[Diagnostics.Project_0_is_up_to_date_because_newest_input_1_is_older_than_oldest_output_2, relSources[project.first][source.config], relSources[project.first][source.ts][part.one], relOutputFiles[project.first][ext.js]],
455+
[Diagnostics.Project_0_is_up_to_date_because_newest_input_1_is_older_than_oldest_output_2, relSources[project.second][source.config], relSources[project.second][source.ts][part.one], relOutputFiles[project.second][ext.js]],
456+
[Diagnostics.Project_0_is_up_to_date_because_newest_input_1_is_older_than_oldest_output_2, relSources[project.third][source.config], relSources[project.third][source.ts][part.one], relOutputFiles[project.third][ext.js]],
457+
);
458+
});
459+
441460
describe("Prepend output with .tsbuildinfo", () => {
442461
// Prologues
443462
describe("Prologues", () => {

src/testRunner/unittests/tsbuild/sample.ts

Lines changed: 29 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -168,22 +168,21 @@ namespace ts {
168168
});
169169

170170
describe("can detect when and what to rebuild", () => {
171-
let fs: vfs.FileSystem;
172-
let host: fakes.SolutionBuilderHost;
173-
let builder: SolutionBuilder;
174-
before(() => {
175-
fs = projFs.shadow();
176-
host = new fakes.SolutionBuilderHost(fs);
177-
builder = createSolutionBuilder(host, ["/src/tests"], { dry: false, force: false, verbose: true });
178-
});
179-
after(() => {
180-
fs = undefined!;
181-
host = undefined!;
182-
builder = undefined!;
183-
});
171+
function initializeWithBuild() {
172+
const fs = projFs.shadow();
173+
const host = new fakes.SolutionBuilderHost(fs);
174+
const builder = createSolutionBuilder(host, ["/src/tests"], { verbose: true });
175+
builder.buildAllProjects();
176+
host.clearDiagnostics();
177+
tick();
178+
builder.resetBuildContext();
179+
return { fs, host, builder };
180+
}
184181

185182
it("Builds the project", () => {
186-
host.clearDiagnostics();
183+
const fs = projFs.shadow();
184+
const host = new fakes.SolutionBuilderHost(fs);
185+
const builder = createSolutionBuilder(host, ["/src/tests"], { verbose: true });
187186
builder.resetBuildContext();
188187
builder.buildAllProjects();
189188
host.assertDiagnosticMessages(
@@ -195,45 +194,38 @@ namespace ts {
195194
[Diagnostics.Project_0_is_out_of_date_because_output_file_1_does_not_exist, "src/tests/tsconfig.json", "src/tests/index.js"],
196195
[Diagnostics.Building_project_0, "/src/tests/tsconfig.json"]
197196
);
198-
tick();
199197
});
200198

201199
// All three projects are up to date
202200
it("Detects that all projects are up to date", () => {
203-
host.clearDiagnostics();
204-
builder.resetBuildContext();
201+
const { host, builder } = initializeWithBuild();
205202
builder.buildAllProjects();
206203
host.assertDiagnosticMessages(
207204
getExpectedDiagnosticForProjectsInBuild("src/core/tsconfig.json", "src/logic/tsconfig.json", "src/tests/tsconfig.json"),
208205
[Diagnostics.Project_0_is_up_to_date_because_newest_input_1_is_older_than_oldest_output_2, "src/core/tsconfig.json", "src/core/anotherModule.ts", "src/core/anotherModule.js"],
209206
[Diagnostics.Project_0_is_up_to_date_because_newest_input_1_is_older_than_oldest_output_2, "src/logic/tsconfig.json", "src/logic/index.ts", "src/logic/index.js"],
210207
[Diagnostics.Project_0_is_up_to_date_because_newest_input_1_is_older_than_oldest_output_2, "src/tests/tsconfig.json", "src/tests/index.ts", "src/tests/index.js"]
211208
);
212-
tick();
213209
});
214210

215211
// Update a file in the leaf node (tests), only it should rebuild the last one
216212
it("Only builds the leaf node project", () => {
217-
host.clearDiagnostics();
213+
const { fs, host, builder } = initializeWithBuild();
218214
fs.writeFileSync("/src/tests/index.ts", "const m = 10;");
219-
builder.resetBuildContext();
220215
builder.buildAllProjects();
221-
222216
host.assertDiagnosticMessages(
223217
getExpectedDiagnosticForProjectsInBuild("src/core/tsconfig.json", "src/logic/tsconfig.json", "src/tests/tsconfig.json"),
224218
[Diagnostics.Project_0_is_up_to_date_because_newest_input_1_is_older_than_oldest_output_2, "src/core/tsconfig.json", "src/core/anotherModule.ts", "src/core/anotherModule.js"],
225219
[Diagnostics.Project_0_is_up_to_date_because_newest_input_1_is_older_than_oldest_output_2, "src/logic/tsconfig.json", "src/logic/index.ts", "src/logic/index.js"],
226220
[Diagnostics.Project_0_is_out_of_date_because_oldest_output_1_is_older_than_newest_input_2, "src/tests/tsconfig.json", "src/tests/index.js", "src/tests/index.ts"],
227221
[Diagnostics.Building_project_0, "/src/tests/tsconfig.json"]
228222
);
229-
tick();
230223
});
231224

232225
// Update a file in the parent (without affecting types), should get fast downstream builds
233226
it("Detects type-only changes in upstream projects", () => {
234-
host.clearDiagnostics();
227+
const { fs, host, builder } = initializeWithBuild();
235228
replaceText(fs, "/src/core/index.ts", "HELLO WORLD", "WELCOME PLANET");
236-
builder.resetBuildContext();
237229
builder.buildAllProjects();
238230

239231
host.assertDiagnosticMessages(
@@ -247,6 +239,19 @@ namespace ts {
247239
[Diagnostics.Updating_output_timestamps_of_project_0, "/src/tests/tsconfig.json"]
248240
);
249241
});
242+
243+
it("rebuilds completely when version in tsbuildinfo doesnt match ts version", () => {
244+
const { host, builder } = initializeWithBuild();
245+
changeCompilerVersion(host);
246+
builder.buildAllProjects();
247+
host.assertDiagnosticMessages(
248+
// TODO:: This should build all instead
249+
getExpectedDiagnosticForProjectsInBuild("src/core/tsconfig.json", "src/logic/tsconfig.json", "src/tests/tsconfig.json"),
250+
[Diagnostics.Project_0_is_up_to_date_because_newest_input_1_is_older_than_oldest_output_2, "src/core/tsconfig.json", "src/core/anotherModule.ts", "src/core/anotherModule.js"],
251+
[Diagnostics.Project_0_is_up_to_date_because_newest_input_1_is_older_than_oldest_output_2, "src/logic/tsconfig.json", "src/logic/index.ts", "src/logic/index.js"],
252+
[Diagnostics.Project_0_is_up_to_date_because_newest_input_1_is_older_than_oldest_output_2, "src/tests/tsconfig.json", "src/tests/index.ts", "src/tests/index.js"]
253+
);
254+
});
250255
});
251256

252257
describe("downstream-blocked compilations", () => {

0 commit comments

Comments
 (0)