Skip to content

Commit 5390c64

Browse files
committed
rootDir tests are baselined
1 parent 928a4e7 commit 5390c64

File tree

5 files changed

+403
-101
lines changed

5 files changed

+403
-101
lines changed

src/testRunner/unittests/tsbuild/referencesWithRootDirInParent.ts

Lines changed: 41 additions & 101 deletions
Original file line numberDiff line numberDiff line change
@@ -9,113 +9,53 @@ namespace ts {
99
projFs = undefined!; // Release the contents
1010
});
1111

12-
it("verify that it builds correctly", () => {
13-
const allExpectedOutputs = [
14-
"/src/dist/other/other.js", "/src/dist/other/other.d.ts",
15-
"/src/dist/main/a.js", "/src/dist/main/a.d.ts",
16-
"/src/dist/main/b.js", "/src/dist/main/b.d.ts"
17-
];
18-
const fs = projFs.shadow();
19-
const host = fakes.SolutionBuilderHost.create(fs);
20-
const builder = createSolutionBuilder(host, ["/src/src/main", "/src/src/other"], {});
21-
builder.build();
22-
host.assertDiagnosticMessages(/*empty*/);
23-
verifyOutputsPresent(fs, allExpectedOutputs);
12+
verifyTsc({
13+
scenario: "projectReferenceWithRootDirInParent",
14+
subScenario: "builds correctly",
15+
fs: () => projFs,
16+
commandLineArgs: ["--b", "/src/src/main", "/src/src/other"],
2417
});
2518

26-
it("verify that it reports error for same .tsbuildinfo file because no rootDir in the base", () => {
27-
const allExpectedOutputs = [
28-
"/src/dist/other.js", "/src/dist/other.d.ts",
29-
"/src/dist/tsconfig.tsbuildinfo"
30-
];
31-
const missingOutputs = [
32-
"/src/dist/a.js", "/src/dist/a.d.ts",
33-
"/src/dist/b.js", "/src/dist/b.d.ts"
34-
];
35-
const fs = projFs.shadow();
36-
replaceText(fs, "/src/tsconfig.base.json", `"rootDir": "./src/",`, "");
37-
const host = fakes.SolutionBuilderHost.create(fs);
38-
const builder = createSolutionBuilder(host, ["/src/src/main"], { verbose: true });
39-
builder.build();
40-
host.assertDiagnosticMessages(
41-
getExpectedDiagnosticForProjectsInBuild("src/src/other/tsconfig.json", "src/src/main/tsconfig.json"),
42-
[Diagnostics.Project_0_is_out_of_date_because_output_file_1_does_not_exist, "src/src/other/tsconfig.json", "src/dist/other.js"],
43-
[Diagnostics.Building_project_0, "/src/src/other/tsconfig.json"],
44-
[Diagnostics.Project_0_is_out_of_date_because_output_file_1_does_not_exist, "src/src/main/tsconfig.json", "src/dist/a.js"],
45-
[Diagnostics.Building_project_0, "/src/src/main/tsconfig.json"],
46-
{
47-
message: [Diagnostics.Cannot_write_file_0_because_it_will_overwrite_tsbuildinfo_file_generated_by_referenced_project_1, "/src/dist/tsconfig.tsbuildinfo", "/src/src/other"],
48-
location: expectedLocationIndexOf(fs, "/src/src/main/tsconfig.json", `{ "path": "../other" }`),
49-
}
50-
);
51-
verifyOutputsPresent(fs, allExpectedOutputs);
52-
verifyOutputsAbsent(fs, missingOutputs);
19+
verifyTsc({
20+
scenario: "projectReferenceWithRootDirInParent",
21+
subScenario: "reports error for same tsbuildinfo file because no rootDir in the base",
22+
fs: () => projFs,
23+
commandLineArgs: ["--b", "/src/src/main", "--verbose"],
24+
modifyFs: fs => replaceText(fs, "/src/tsconfig.base.json", `"rootDir": "./src/",`, ""),
5325
});
5426

55-
it("verify that it reports error for same .tsbuildinfo file", () => {
56-
const allExpectedOutputs = [
57-
"/src/dist/other.js", "/src/dist/other.d.ts",
58-
"/src/dist/tsconfig.tsbuildinfo"
59-
];
60-
const missingOutputs = [
61-
"/src/dist/a.js", "/src/dist/a.d.ts",
62-
"/src/dist/b.js", "/src/dist/b.d.ts"
63-
];
64-
const fs = projFs.shadow();
65-
fs.writeFileSync("/src/src/main/tsconfig.json", JSON.stringify({
66-
compilerOptions: { composite: true, outDir: "../../dist/" },
67-
references: [{ path: "../other" }]
68-
}));
69-
fs.writeFileSync("/src/src/other/tsconfig.json", JSON.stringify({
70-
compilerOptions: { composite: true, outDir: "../../dist/" },
71-
}));
72-
const host = fakes.SolutionBuilderHost.create(fs);
73-
const builder = createSolutionBuilder(host, ["/src/src/main"], { verbose: true });
74-
builder.build();
75-
host.assertDiagnosticMessages(
76-
getExpectedDiagnosticForProjectsInBuild("src/src/other/tsconfig.json", "src/src/main/tsconfig.json"),
77-
[Diagnostics.Project_0_is_out_of_date_because_output_file_1_does_not_exist, "src/src/other/tsconfig.json", "src/dist/other.js"],
78-
[Diagnostics.Building_project_0, "/src/src/other/tsconfig.json"],
79-
[Diagnostics.Project_0_is_out_of_date_because_output_file_1_does_not_exist, "src/src/main/tsconfig.json", "src/dist/a.js"],
80-
[Diagnostics.Building_project_0, "/src/src/main/tsconfig.json"],
81-
{
82-
message: [Diagnostics.Cannot_write_file_0_because_it_will_overwrite_tsbuildinfo_file_generated_by_referenced_project_1, "/src/dist/tsconfig.tsbuildinfo", "/src/src/other"],
83-
location: expectedLocationIndexOf(fs, "/src/src/main/tsconfig.json", `{"path":"../other"}`),
84-
}
85-
);
86-
verifyOutputsPresent(fs, allExpectedOutputs);
87-
verifyOutputsAbsent(fs, missingOutputs);
27+
verifyTsc({
28+
scenario: "projectReferenceWithRootDirInParent",
29+
subScenario: "reports error for same tsbuildinfo file",
30+
fs: () => projFs,
31+
commandLineArgs: ["--b", "/src/src/main", "--verbose"],
32+
modifyFs: fs => {
33+
fs.writeFileSync("/src/src/main/tsconfig.json", JSON.stringify({
34+
compilerOptions: { composite: true, outDir: "../../dist/" },
35+
references: [{ path: "../other" }]
36+
}));
37+
fs.writeFileSync("/src/src/other/tsconfig.json", JSON.stringify({
38+
compilerOptions: { composite: true, outDir: "../../dist/" },
39+
}));
40+
},
8841
});
8942

90-
it("verify that it reports no error when .tsbuildinfo differ", () => {
91-
const allExpectedOutputs = [
92-
"/src/dist/other.js", "/src/dist/other.d.ts",
93-
"/src/dist/tsconfig.main.tsbuildinfo",
94-
"/src/dist/a.js", "/src/dist/a.d.ts",
95-
"/src/dist/b.js", "/src/dist/b.d.ts",
96-
"/src/dist/tsconfig.other.tsbuildinfo"
97-
];
98-
const fs = projFs.shadow();
99-
fs.renameSync("/src/src/main/tsconfig.json", "/src/src/main/tsconfig.main.json");
100-
fs.renameSync("/src/src/other/tsconfig.json", "/src/src/other/tsconfig.other.json");
101-
fs.writeFileSync("/src/src/main/tsconfig.main.json", JSON.stringify({
102-
compilerOptions: { composite: true, outDir: "../../dist/" },
103-
references: [{ path: "../other/tsconfig.other.json" }]
104-
}));
105-
fs.writeFileSync("/src/src/other/tsconfig.other.json", JSON.stringify({
106-
compilerOptions: { composite: true, outDir: "../../dist/" },
107-
}));
108-
const host = fakes.SolutionBuilderHost.create(fs);
109-
const builder = createSolutionBuilder(host, ["/src/src/main/tsconfig.main.json"], { verbose: true });
110-
builder.build();
111-
host.assertDiagnosticMessages(
112-
getExpectedDiagnosticForProjectsInBuild("src/src/other/tsconfig.other.json", "src/src/main/tsconfig.main.json"),
113-
[Diagnostics.Project_0_is_out_of_date_because_output_file_1_does_not_exist, "src/src/other/tsconfig.other.json", "src/dist/other.js"],
114-
[Diagnostics.Building_project_0, "/src/src/other/tsconfig.other.json"],
115-
[Diagnostics.Project_0_is_out_of_date_because_output_file_1_does_not_exist, "src/src/main/tsconfig.main.json", "src/dist/a.js"],
116-
[Diagnostics.Building_project_0, "/src/src/main/tsconfig.main.json"]
117-
);
118-
verifyOutputsPresent(fs, allExpectedOutputs);
43+
verifyTsc({
44+
scenario: "projectReferenceWithRootDirInParent",
45+
subScenario: "reports no error when tsbuildinfo differ",
46+
fs: () => projFs,
47+
commandLineArgs: ["--b", "/src/src/main/tsconfig.main.json", "--verbose"],
48+
modifyFs: fs => {
49+
fs.renameSync("/src/src/main/tsconfig.json", "/src/src/main/tsconfig.main.json");
50+
fs.renameSync("/src/src/other/tsconfig.json", "/src/src/other/tsconfig.other.json");
51+
fs.writeFileSync("/src/src/main/tsconfig.main.json", JSON.stringify({
52+
compilerOptions: { composite: true, outDir: "../../dist/" },
53+
references: [{ path: "../other/tsconfig.other.json" }]
54+
}));
55+
fs.writeFileSync("/src/src/other/tsconfig.other.json", JSON.stringify({
56+
compilerOptions: { composite: true, outDir: "../../dist/" },
57+
}));
58+
},
11959
});
12060
});
12161
}
Lines changed: 107 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,107 @@
1+
//// [/lib/initial-buildOutput.txt]
2+
/lib/tsc --b /src/src/main /src/src/other
3+
exitCode:: ExitStatus.Success
4+
5+
6+
//// [/src/dist/main/a.d.ts]
7+
export {};
8+
9+
10+
//// [/src/dist/main/a.js]
11+
"use strict";
12+
exports.__esModule = true;
13+
var b_1 = require("./b");
14+
var a = b_1.b;
15+
16+
17+
//// [/src/dist/main/b.d.ts]
18+
export declare const b = 0;
19+
20+
21+
//// [/src/dist/main/b.js]
22+
"use strict";
23+
exports.__esModule = true;
24+
exports.b = 0;
25+
26+
27+
//// [/src/dist/main/tsconfig.tsbuildinfo]
28+
{
29+
"program": {
30+
"fileInfos": {
31+
"../../../lib/lib.d.ts": {
32+
"version": "3858781397-/// <reference no-default-lib=\"true\"/>\ninterface Boolean {}\ninterface Function {}\ninterface CallableFunction {}\ninterface NewableFunction {}\ninterface IArguments {}\ninterface Number { toExponential: any; }\ninterface Object {}\ninterface RegExp {}\ninterface String { charAt: any; }\ninterface Array<T> { length: number; [n: number]: T; }\ninterface ReadonlyArray<T> {}\ndeclare const console: { log(msg: any): void; };",
33+
"signature": "3858781397-/// <reference no-default-lib=\"true\"/>\ninterface Boolean {}\ninterface Function {}\ninterface CallableFunction {}\ninterface NewableFunction {}\ninterface IArguments {}\ninterface Number { toExponential: any; }\ninterface Object {}\ninterface RegExp {}\ninterface String { charAt: any; }\ninterface Array<T> { length: number; [n: number]: T; }\ninterface ReadonlyArray<T> {}\ndeclare const console: { log(msg: any): void; };"
34+
},
35+
"../../src/main/b.ts": {
36+
"version": "-11678562673-export const b = 0;\r\n",
37+
"signature": "-3829176033-export declare const b = 0;\r\n"
38+
},
39+
"../../src/main/a.ts": {
40+
"version": "-17071184049-import { b } from './b';\r\nconst a = b;",
41+
"signature": "-4882119183-export {};\r\n"
42+
}
43+
},
44+
"options": {
45+
"composite": true,
46+
"declaration": true,
47+
"rootDir": "../../src",
48+
"outDir": "..",
49+
"skipDefaultLibCheck": true,
50+
"configFilePath": "../../src/main/tsconfig.json"
51+
},
52+
"referencedMap": {
53+
"../../src/main/a.ts": [
54+
"../../src/main/b.ts"
55+
]
56+
},
57+
"exportedModulesMap": {},
58+
"semanticDiagnosticsPerFile": [
59+
"../../../lib/lib.d.ts",
60+
"../../src/main/a.ts",
61+
"../../src/main/b.ts"
62+
]
63+
},
64+
"version": "FakeTSVersion"
65+
}
66+
67+
//// [/src/dist/other/other.d.ts]
68+
export declare const Other = 0;
69+
70+
71+
//// [/src/dist/other/other.js]
72+
"use strict";
73+
exports.__esModule = true;
74+
exports.Other = 0;
75+
76+
77+
//// [/src/dist/other/tsconfig.tsbuildinfo]
78+
{
79+
"program": {
80+
"fileInfos": {
81+
"../../../lib/lib.d.ts": {
82+
"version": "3858781397-/// <reference no-default-lib=\"true\"/>\ninterface Boolean {}\ninterface Function {}\ninterface CallableFunction {}\ninterface NewableFunction {}\ninterface IArguments {}\ninterface Number { toExponential: any; }\ninterface Object {}\ninterface RegExp {}\ninterface String { charAt: any; }\ninterface Array<T> { length: number; [n: number]: T; }\ninterface ReadonlyArray<T> {}\ndeclare const console: { log(msg: any): void; };",
83+
"signature": "3858781397-/// <reference no-default-lib=\"true\"/>\ninterface Boolean {}\ninterface Function {}\ninterface CallableFunction {}\ninterface NewableFunction {}\ninterface IArguments {}\ninterface Number { toExponential: any; }\ninterface Object {}\ninterface RegExp {}\ninterface String { charAt: any; }\ninterface Array<T> { length: number; [n: number]: T; }\ninterface ReadonlyArray<T> {}\ndeclare const console: { log(msg: any): void; };"
84+
},
85+
"../../src/other/other.ts": {
86+
"version": "-2951227185-export const Other = 0;\r\n",
87+
"signature": "-7996259489-export declare const Other = 0;\r\n"
88+
}
89+
},
90+
"options": {
91+
"composite": true,
92+
"declaration": true,
93+
"rootDir": "../../src",
94+
"outDir": "..",
95+
"skipDefaultLibCheck": true,
96+
"configFilePath": "../../src/other/tsconfig.json"
97+
},
98+
"referencedMap": {},
99+
"exportedModulesMap": {},
100+
"semanticDiagnosticsPerFile": [
101+
"../../../lib/lib.d.ts",
102+
"../../src/other/other.ts"
103+
]
104+
},
105+
"version": "FakeTSVersion"
106+
}
107+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
//// [/lib/initial-buildOutput.txt]
2+
/lib/tsc --b /src/src/main --verbose
3+
12:00:00 AM - Projects in this build:
4+
* src/src/other/tsconfig.json
5+
* src/src/main/tsconfig.json
6+
7+
12:00:00 AM - Project 'src/src/other/tsconfig.json' is out of date because output file 'src/dist/other.js' does not exist
8+
9+
12:00:00 AM - Building project '/src/src/other/tsconfig.json'...
10+
11+
12:00:00 AM - Project 'src/src/main/tsconfig.json' is out of date because output file 'src/dist/a.js' does not exist
12+
13+
12:00:00 AM - Building project '/src/src/main/tsconfig.json'...
14+
15+
src/src/main/tsconfig.json(4,5): error TS6377: Cannot write file '/src/dist/tsconfig.tsbuildinfo' because it will overwrite '.tsbuildinfo' file generated by referenced project '/src/src/other'
16+
exitCode:: ExitStatus.DiagnosticsPresent_OutputsGenerated
17+
18+
19+
//// [/src/dist/other.d.ts]
20+
export declare const Other = 0;
21+
22+
23+
//// [/src/dist/other.js]
24+
"use strict";
25+
exports.__esModule = true;
26+
exports.Other = 0;
27+
28+
29+
//// [/src/dist/tsconfig.tsbuildinfo]
30+
{
31+
"program": {
32+
"fileInfos": {
33+
"../../lib/lib.d.ts": {
34+
"version": "3858781397-/// <reference no-default-lib=\"true\"/>\ninterface Boolean {}\ninterface Function {}\ninterface CallableFunction {}\ninterface NewableFunction {}\ninterface IArguments {}\ninterface Number { toExponential: any; }\ninterface Object {}\ninterface RegExp {}\ninterface String { charAt: any; }\ninterface Array<T> { length: number; [n: number]: T; }\ninterface ReadonlyArray<T> {}\ndeclare const console: { log(msg: any): void; };",
35+
"signature": "3858781397-/// <reference no-default-lib=\"true\"/>\ninterface Boolean {}\ninterface Function {}\ninterface CallableFunction {}\ninterface NewableFunction {}\ninterface IArguments {}\ninterface Number { toExponential: any; }\ninterface Object {}\ninterface RegExp {}\ninterface String { charAt: any; }\ninterface Array<T> { length: number; [n: number]: T; }\ninterface ReadonlyArray<T> {}\ndeclare const console: { log(msg: any): void; };"
36+
},
37+
"../src/other/other.ts": {
38+
"version": "-2951227185-export const Other = 0;\r\n",
39+
"signature": "-7996259489-export declare const Other = 0;\r\n"
40+
}
41+
},
42+
"options": {
43+
"composite": true,
44+
"declaration": true,
45+
"outDir": "./",
46+
"skipDefaultLibCheck": true,
47+
"configFilePath": "../src/other/tsconfig.json"
48+
},
49+
"referencedMap": {},
50+
"exportedModulesMap": {},
51+
"semanticDiagnosticsPerFile": [
52+
"../../lib/lib.d.ts",
53+
"../src/other/other.ts"
54+
]
55+
},
56+
"version": "FakeTSVersion"
57+
}
58+
59+
//// [/src/tsconfig.base.json]
60+
{
61+
"compilerOptions": {
62+
"composite": true,
63+
"declaration": true,
64+
65+
"outDir": "./dist/",
66+
"skipDefaultLibCheck": true
67+
},
68+
"exclude": [
69+
"node_modules"
70+
]
71+
}
72+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
//// [/lib/initial-buildOutput.txt]
2+
/lib/tsc --b /src/src/main --verbose
3+
12:00:00 AM - Projects in this build:
4+
* src/src/other/tsconfig.json
5+
* src/src/main/tsconfig.json
6+
7+
12:00:00 AM - Project 'src/src/other/tsconfig.json' is out of date because output file 'src/dist/other.js' does not exist
8+
9+
12:00:00 AM - Building project '/src/src/other/tsconfig.json'...
10+
11+
12:00:00 AM - Project 'src/src/main/tsconfig.json' is out of date because output file 'src/dist/a.js' does not exist
12+
13+
12:00:00 AM - Building project '/src/src/main/tsconfig.json'...
14+
15+
src/src/main/tsconfig.json(1,76): error TS6377: Cannot write file '/src/dist/tsconfig.tsbuildinfo' because it will overwrite '.tsbuildinfo' file generated by referenced project '/src/src/other'
16+
exitCode:: ExitStatus.DiagnosticsPresent_OutputsGenerated
17+
18+
19+
//// [/src/dist/other.d.ts]
20+
export declare const Other = 0;
21+
22+
23+
//// [/src/dist/other.js]
24+
"use strict";
25+
exports.__esModule = true;
26+
exports.Other = 0;
27+
28+
29+
//// [/src/dist/tsconfig.tsbuildinfo]
30+
{
31+
"program": {
32+
"fileInfos": {
33+
"../../lib/lib.d.ts": {
34+
"version": "3858781397-/// <reference no-default-lib=\"true\"/>\ninterface Boolean {}\ninterface Function {}\ninterface CallableFunction {}\ninterface NewableFunction {}\ninterface IArguments {}\ninterface Number { toExponential: any; }\ninterface Object {}\ninterface RegExp {}\ninterface String { charAt: any; }\ninterface Array<T> { length: number; [n: number]: T; }\ninterface ReadonlyArray<T> {}\ndeclare const console: { log(msg: any): void; };",
35+
"signature": "3858781397-/// <reference no-default-lib=\"true\"/>\ninterface Boolean {}\ninterface Function {}\ninterface CallableFunction {}\ninterface NewableFunction {}\ninterface IArguments {}\ninterface Number { toExponential: any; }\ninterface Object {}\ninterface RegExp {}\ninterface String { charAt: any; }\ninterface Array<T> { length: number; [n: number]: T; }\ninterface ReadonlyArray<T> {}\ndeclare const console: { log(msg: any): void; };"
36+
},
37+
"../src/other/other.ts": {
38+
"version": "-2951227185-export const Other = 0;\r\n",
39+
"signature": "-7996259489-export declare const Other = 0;\r\n"
40+
}
41+
},
42+
"options": {
43+
"composite": true,
44+
"outDir": "./",
45+
"configFilePath": "../src/other/tsconfig.json"
46+
},
47+
"referencedMap": {},
48+
"exportedModulesMap": {},
49+
"semanticDiagnosticsPerFile": [
50+
"../../lib/lib.d.ts",
51+
"../src/other/other.ts"
52+
]
53+
},
54+
"version": "FakeTSVersion"
55+
}
56+
57+
//// [/src/src/main/tsconfig.json]
58+
{"compilerOptions":{"composite":true,"outDir":"../../dist/"},"references":[{"path":"../other"}]}
59+
60+
//// [/src/src/other/tsconfig.json]
61+
{"compilerOptions":{"composite":true,"outDir":"../../dist/"}}
62+

0 commit comments

Comments
 (0)