Skip to content

Commit 1508396

Browse files
committed
tsc -b solution tests
1 parent 5e01a4f commit 1508396

5 files changed

+1012
-0
lines changed

internal/execute/tscbuild_test.go

Lines changed: 164 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -268,6 +268,170 @@ func TestBuildConfigFileErrors(t *testing.T) {
268268
}
269269
}
270270

271+
func TestBuildSolutionProject(t *testing.T) {
272+
t.Parallel()
273+
testCases := []*tscInput{
274+
{
275+
subScenario: "verify that subsequent builds after initial build doesnt build anything",
276+
files: FileMap{
277+
"/home/src/workspaces/solution/src/folder/index.ts": `export const x = 10;`,
278+
"/home/src/workspaces/solution/src/folder/tsconfig.json": stringtestutil.Dedent(`
279+
{
280+
"files": ["index.ts"],
281+
"compilerOptions": {
282+
"composite": true
283+
}
284+
}
285+
`),
286+
"/home/src/workspaces/solution/src/folder2/index.ts": `export const x = 10;`,
287+
"/home/src/workspaces/solution/src/folder2/tsconfig.json": stringtestutil.Dedent(`
288+
{
289+
"files": ["index.ts"],
290+
"compilerOptions": {
291+
"composite": true
292+
}
293+
}
294+
`),
295+
"/home/src/workspaces/solution/src/tsconfig.json": stringtestutil.Dedent(`
296+
{
297+
"files": [],
298+
"compilerOptions": {
299+
"composite": true
300+
},
301+
"references": [
302+
{ "path": "./folder" },
303+
{ "path": "./folder2" },
304+
]
305+
}`),
306+
"/home/src/workspaces/solution/tests/index.ts": `export const x = 10;`,
307+
"/home/src/workspaces/solution/tests/tsconfig.json": stringtestutil.Dedent(`
308+
{
309+
"files": ["index.ts"],
310+
"compilerOptions": {
311+
"composite": true
312+
},
313+
"references": [
314+
{ "path": "../src" }
315+
]
316+
}
317+
`),
318+
"/home/src/workspaces/solution/tsconfig.json": stringtestutil.Dedent(`
319+
{
320+
"files": [],
321+
"compilerOptions": {
322+
"composite": true
323+
},
324+
"references": [
325+
{ "path": "./src" },
326+
{ "path": "./tests" }
327+
]
328+
}
329+
`),
330+
},
331+
cwd: "/home/src/workspaces/solution",
332+
commandLineArgs: []string{"--b", "--v"},
333+
edits: noChangeOnlyEdit,
334+
},
335+
{
336+
subScenario: "when solution is referenced indirectly",
337+
files: FileMap{
338+
"/home/src/workspaces/solution/project1/tsconfig.json": stringtestutil.Dedent(`
339+
{
340+
"compilerOptions": { "composite": true },
341+
"references": []
342+
}
343+
`),
344+
"/home/src/workspaces/solution/project2/tsconfig.json": stringtestutil.Dedent(`
345+
{
346+
"compilerOptions": { "composite": true },
347+
"references": []
348+
}
349+
`),
350+
"/home/src/workspaces/solution/project2/src/b.ts": "export const b = 10;",
351+
"/home/src/workspaces/solution/project3/tsconfig.json": stringtestutil.Dedent(`
352+
{
353+
"compilerOptions": { "composite": true },
354+
"references": [
355+
{ "path": "../project1" },
356+
{ "path": "../project2" }
357+
]
358+
}
359+
`),
360+
"/home/src/workspaces/solution/project3/src/c.ts": "export const c = 10;",
361+
"/home/src/workspaces/solution/project4/tsconfig.json": stringtestutil.Dedent(`
362+
{
363+
"compilerOptions": { "composite": true },
364+
"references": [{ "path": "../project3" }]
365+
}
366+
`),
367+
"/home/src/workspaces/solution/project4/src/d.ts": "export const d = 10;",
368+
},
369+
cwd: "/home/src/workspaces/solution",
370+
commandLineArgs: []string{"--b", "project4", "--verbose", "--explainFiles"},
371+
edits: []*tscEdit{
372+
{
373+
caption: "modify project3 file",
374+
edit: func(sys *testSys) {
375+
sys.replaceFileText("/home/src/workspaces/solution/project3/src/c.ts", "c = ", "cc = ")
376+
},
377+
},
378+
},
379+
},
380+
{
381+
subScenario: "has empty files diagnostic when files is empty and no references are provided",
382+
files: FileMap{
383+
"/home/src/workspaces/solution/no-references/tsconfig.json": stringtestutil.Dedent(`
384+
{
385+
"references": [],
386+
"files": [],
387+
"compilerOptions": {
388+
"composite": true,
389+
"declaration": true,
390+
"forceConsistentCasingInFileNames": true,
391+
"skipDefaultLibCheck": true,
392+
},
393+
}`),
394+
},
395+
cwd: "/home/src/workspaces/solution",
396+
commandLineArgs: []string{"--b", "no-references"},
397+
},
398+
{
399+
subScenario: "does not have empty files diagnostic when files is empty and references are provided",
400+
files: FileMap{
401+
"/home/src/workspaces/solution/core/index.ts": "export function multiply(a: number, b: number) { return a * b; }",
402+
"/home/src/workspaces/solution/core/tsconfig.json": stringtestutil.Dedent(`
403+
{
404+
"compilerOptions": {
405+
"composite": true,
406+
"declaration": true,
407+
"declarationMap": true,
408+
"skipDefaultLibCheck": true,
409+
},
410+
}`),
411+
"/home/src/workspaces/solution/with-references/tsconfig.json": stringtestutil.Dedent(`
412+
{
413+
"references": [
414+
{ "path": "../core" },
415+
],
416+
"files": [],
417+
"compilerOptions": {
418+
"composite": true,
419+
"declaration": true,
420+
"forceConsistentCasingInFileNames": true,
421+
"skipDefaultLibCheck": true,
422+
},
423+
}`),
424+
},
425+
cwd: "/home/src/workspaces/solution",
426+
commandLineArgs: []string{"--b", "with-references"},
427+
},
428+
}
429+
430+
for _, test := range testCases {
431+
test.run(t, "solution")
432+
}
433+
}
434+
271435
func getBuildCommandLineDifferentOptionsMap(optionName string) FileMap {
272436
return FileMap{
273437
"/home/src/workspaces/project/tsconfig.json": stringtestutil.Dedent(fmt.Sprintf(`
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,123 @@
1+
currentDirectory::/home/src/workspaces/solution
2+
useCaseSensitiveFileNames::true
3+
Input::
4+
//// [/home/src/workspaces/solution/core/index.ts] *new*
5+
export function multiply(a: number, b: number) { return a * b; }
6+
//// [/home/src/workspaces/solution/core/tsconfig.json] *new*
7+
{
8+
"compilerOptions": {
9+
"composite": true,
10+
"declaration": true,
11+
"declarationMap": true,
12+
"skipDefaultLibCheck": true,
13+
},
14+
}
15+
//// [/home/src/workspaces/solution/with-references/tsconfig.json] *new*
16+
{
17+
"references": [
18+
{ "path": "../core" },
19+
],
20+
"files": [],
21+
"compilerOptions": {
22+
"composite": true,
23+
"declaration": true,
24+
"forceConsistentCasingInFileNames": true,
25+
"skipDefaultLibCheck": true,
26+
},
27+
}
28+
29+
tsgo --b with-references
30+
ExitStatus:: Success
31+
Output::
32+
//// [/home/src/tslibs/TS/Lib/lib.d.ts] *Lib*
33+
/// <reference no-default-lib="true"/>
34+
interface Boolean {}
35+
interface Function {}
36+
interface CallableFunction {}
37+
interface NewableFunction {}
38+
interface IArguments {}
39+
interface Number { toExponential: any; }
40+
interface Object {}
41+
interface RegExp {}
42+
interface String { charAt: any; }
43+
interface Array<T> { length: number; [n: number]: T; }
44+
interface ReadonlyArray<T> {}
45+
interface SymbolConstructor {
46+
(desc?: string | number): symbol;
47+
for(name: string): symbol;
48+
readonly toStringTag: symbol;
49+
}
50+
declare var Symbol: SymbolConstructor;
51+
interface Symbol {
52+
readonly [Symbol.toStringTag]: string;
53+
}
54+
declare const console: { log(msg: any): void; };
55+
//// [/home/src/workspaces/solution/core/index.d.ts] *new*
56+
export declare function multiply(a: number, b: number): number;
57+
//# sourceMappingURL=index.d.ts.map
58+
//// [/home/src/workspaces/solution/core/index.d.ts.map] *new*
59+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["index.ts"],"names":[],"mappings":"AAAA,wBAAgB,QAAQ,CAAC,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,MAAM,UAAmB"}
60+
//// [/home/src/workspaces/solution/core/index.js] *new*
61+
"use strict";
62+
Object.defineProperty(exports, "__esModule", { value: true });
63+
exports.multiply = multiply;
64+
function multiply(a, b) { return a * b; }
65+
66+
//// [/home/src/workspaces/solution/core/tsconfig.tsbuildinfo] *new*
67+
{"version":"FakeTSVersion","root":[2],"fileNames":["lib.d.ts","./index.ts"],"fileInfos":[{"version":"8859c12c614ce56ba9a18e58384a198f-/// <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> {}\ninterface SymbolConstructor {\n (desc?: string | number): symbol;\n for(name: string): symbol;\n readonly toStringTag: symbol;\n}\ndeclare var Symbol: SymbolConstructor;\ninterface Symbol {\n readonly [Symbol.toStringTag]: string;\n}\ndeclare const console: { log(msg: any): void; };","affectsGlobalScope":true,"impliedNodeFormat":1},{"version":"3e196dbeb0efd6f81808db37973c4e6d-export function multiply(a: number, b: number) { return a * b; }","signature":"0d04cb6a9ce77a203776db1857b08505-export declare function multiply(a: number, b: number): number;\n","impliedNodeFormat":1}],"options":{"composite":true,"declaration":true,"declarationMap":true,"skipDefaultLibCheck":true},"latestChangedDtsFile":"./index.d.ts"}
68+
//// [/home/src/workspaces/solution/core/tsconfig.tsbuildinfo.readable.baseline.txt] *new*
69+
{
70+
"version": "FakeTSVersion",
71+
"root": [
72+
{
73+
"files": [
74+
"./index.ts"
75+
],
76+
"original": 2
77+
}
78+
],
79+
"fileNames": [
80+
"lib.d.ts",
81+
"./index.ts"
82+
],
83+
"fileInfos": [
84+
{
85+
"fileName": "lib.d.ts",
86+
"version": "8859c12c614ce56ba9a18e58384a198f-/// <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> {}\ninterface SymbolConstructor {\n (desc?: string | number): symbol;\n for(name: string): symbol;\n readonly toStringTag: symbol;\n}\ndeclare var Symbol: SymbolConstructor;\ninterface Symbol {\n readonly [Symbol.toStringTag]: string;\n}\ndeclare const console: { log(msg: any): void; };",
87+
"signature": "8859c12c614ce56ba9a18e58384a198f-/// <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> {}\ninterface SymbolConstructor {\n (desc?: string | number): symbol;\n for(name: string): symbol;\n readonly toStringTag: symbol;\n}\ndeclare var Symbol: SymbolConstructor;\ninterface Symbol {\n readonly [Symbol.toStringTag]: string;\n}\ndeclare const console: { log(msg: any): void; };",
88+
"affectsGlobalScope": true,
89+
"impliedNodeFormat": "CommonJS",
90+
"original": {
91+
"version": "8859c12c614ce56ba9a18e58384a198f-/// <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> {}\ninterface SymbolConstructor {\n (desc?: string | number): symbol;\n for(name: string): symbol;\n readonly toStringTag: symbol;\n}\ndeclare var Symbol: SymbolConstructor;\ninterface Symbol {\n readonly [Symbol.toStringTag]: string;\n}\ndeclare const console: { log(msg: any): void; };",
92+
"affectsGlobalScope": true,
93+
"impliedNodeFormat": 1
94+
}
95+
},
96+
{
97+
"fileName": "./index.ts",
98+
"version": "3e196dbeb0efd6f81808db37973c4e6d-export function multiply(a: number, b: number) { return a * b; }",
99+
"signature": "0d04cb6a9ce77a203776db1857b08505-export declare function multiply(a: number, b: number): number;\n",
100+
"impliedNodeFormat": "CommonJS",
101+
"original": {
102+
"version": "3e196dbeb0efd6f81808db37973c4e6d-export function multiply(a: number, b: number) { return a * b; }",
103+
"signature": "0d04cb6a9ce77a203776db1857b08505-export declare function multiply(a: number, b: number): number;\n",
104+
"impliedNodeFormat": 1
105+
}
106+
}
107+
],
108+
"options": {
109+
"composite": true,
110+
"declaration": true,
111+
"declarationMap": true,
112+
"skipDefaultLibCheck": true
113+
},
114+
"latestChangedDtsFile": "./index.d.ts",
115+
"size": 1242
116+
}
117+
118+
core/tsconfig.json::
119+
SemanticDiagnostics::
120+
*refresh* /home/src/tslibs/TS/Lib/lib.d.ts
121+
*refresh* /home/src/workspaces/solution/core/index.ts
122+
Signatures::
123+
(stored at emit) /home/src/workspaces/solution/core/index.ts
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
currentDirectory::/home/src/workspaces/solution
2+
useCaseSensitiveFileNames::true
3+
Input::
4+
//// [/home/src/workspaces/solution/no-references/tsconfig.json] *new*
5+
{
6+
"references": [],
7+
"files": [],
8+
"compilerOptions": {
9+
"composite": true,
10+
"declaration": true,
11+
"forceConsistentCasingInFileNames": true,
12+
"skipDefaultLibCheck": true,
13+
},
14+
}
15+
16+
tsgo --b no-references
17+
ExitStatus:: DiagnosticsPresent_OutputsSkipped
18+
Output::
19+
no-references/tsconfig.json:3:14 - error TS18002: The 'files' list in config file '/home/src/workspaces/solution/no-references/tsconfig.json' is empty.
20+
21+
3 "files": [],
22+
   ~~
23+
24+
25+
Found 1 error in no-references/tsconfig.json:3
26+
27+

0 commit comments

Comments
 (0)