Skip to content

Commit 93d68b3

Browse files
committed
tsc --b commandline tests
1 parent 2822725 commit 93d68b3

9 files changed

+10545
-6
lines changed

internal/execute/tscbuild_test.go

Lines changed: 246 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,260 @@
11
package execute_test
22

33
import (
4+
"fmt"
5+
"slices"
6+
"strings"
47
"testing"
8+
9+
"github.com/microsoft/typescript-go/internal/core"
10+
"github.com/microsoft/typescript-go/internal/testutil/stringtestutil"
511
)
612

713
func TestBuildCommandLine(t *testing.T) {
814
t.Parallel()
9-
testCases := []*tscInput{
10-
{
11-
subScenario: "help",
12-
files: FileMap{},
13-
commandLineArgs: []string{"--build", "--help"},
15+
testCases := slices.Concat(
16+
[]*tscInput{
17+
{
18+
subScenario: "help",
19+
files: FileMap{},
20+
commandLineArgs: []string{"--build", "--help"},
21+
},
22+
{
23+
subScenario: "different options",
24+
files: getBuildCommandLineDifferentOptionsMap("composite"),
25+
commandLineArgs: []string{"--build", "--verbose"},
26+
edits: []*tscEdit{
27+
{
28+
caption: "with sourceMap",
29+
commandLineArgs: []string{"--build", "--verbose", "--sourceMap"},
30+
},
31+
{
32+
caption: "should re-emit only js so they dont contain sourcemap",
33+
},
34+
{
35+
caption: "with declaration should not emit anything",
36+
commandLineArgs: []string{"--build", "--verbose", "--declaration"},
37+
},
38+
noChange,
39+
{
40+
caption: "with declaration and declarationMap",
41+
commandLineArgs: []string{"--build", "--verbose", "--declaration", "--declarationMap"},
42+
},
43+
{
44+
caption: "should re-emit only dts so they dont contain sourcemap",
45+
},
46+
{
47+
caption: "with emitDeclarationOnly should not emit anything",
48+
commandLineArgs: []string{"--build", "--verbose", "--emitDeclarationOnly"},
49+
},
50+
noChange,
51+
{
52+
caption: "local change",
53+
edit: func(sys *testSys) {
54+
sys.replaceFileText("/home/src/workspaces/project/a.ts", "Local = 1", "Local = 10")
55+
},
56+
},
57+
{
58+
caption: "with declaration should not emit anything",
59+
commandLineArgs: []string{"--build", "--verbose", "--declaration"},
60+
},
61+
{
62+
caption: "with inlineSourceMap",
63+
commandLineArgs: []string{"--build", "--verbose", "--inlineSourceMap"},
64+
},
65+
{
66+
caption: "with sourceMap",
67+
commandLineArgs: []string{"--build", "--verbose", "--sourceMap"},
68+
},
69+
},
70+
},
71+
{
72+
subScenario: "different options with incremental",
73+
files: getBuildCommandLineDifferentOptionsMap("incremental"),
74+
commandLineArgs: []string{"--build", "--verbose"},
75+
edits: []*tscEdit{
76+
{
77+
caption: "with sourceMap",
78+
commandLineArgs: []string{"--build", "--verbose", "--sourceMap"},
79+
},
80+
{
81+
caption: "should re-emit only js so they dont contain sourcemap",
82+
},
83+
{
84+
caption: "with declaration, emit Dts and should not emit js",
85+
commandLineArgs: []string{"--build", "--verbose", "--declaration"},
86+
},
87+
{
88+
caption: "with declaration and declarationMap",
89+
commandLineArgs: []string{"--build", "--verbose", "--declaration", "--declarationMap"},
90+
},
91+
noChange,
92+
{
93+
caption: "local change",
94+
edit: func(sys *testSys) {
95+
sys.replaceFileText("/home/src/workspaces/project/a.ts", "Local = 1", "Local = 10")
96+
},
97+
},
98+
{
99+
caption: "with declaration and declarationMap",
100+
commandLineArgs: []string{"--build", "--verbose", "--declaration", "--declarationMap"},
101+
},
102+
noChange,
103+
{
104+
caption: "with inlineSourceMap",
105+
commandLineArgs: []string{"--build", "--verbose", "--inlineSourceMap"},
106+
},
107+
{
108+
caption: "with sourceMap",
109+
commandLineArgs: []string{"--build", "--verbose", "--sourceMap"},
110+
},
111+
{
112+
caption: "emit js files",
113+
},
114+
{
115+
caption: "with declaration and declarationMap",
116+
commandLineArgs: []string{"--build", "--verbose", "--declaration", "--declarationMap"},
117+
},
118+
{
119+
caption: "with declaration and declarationMap, should not re-emit",
120+
commandLineArgs: []string{"--build", "--verbose", "--declaration", "--declarationMap"},
121+
},
122+
},
123+
},
14124
},
15-
}
125+
getBuildCommandLineEmitDeclarationOnlyTestCases([]string{"composite"}, ""),
126+
getBuildCommandLineEmitDeclarationOnlyTestCases([]string{"incremental", "declaration"}, " with declaration and incremental"),
127+
getBuildCommandLineEmitDeclarationOnlyTestCases([]string{"declaration"}, " with declaration"),
128+
)
16129

17130
for _, test := range testCases {
18131
test.run(t, "commandLine")
19132
}
20133
}
134+
135+
func getBuildCommandLineDifferentOptionsMap(optionName string) FileMap {
136+
return FileMap{
137+
"/home/src/workspaces/project/tsconfig.json": stringtestutil.Dedent(fmt.Sprintf(`
138+
{
139+
"compilerOptions": {
140+
"%s": true
141+
}
142+
}`, optionName)),
143+
"/home/src/workspaces/project/a.ts": `export const a = 10;const aLocal = 10;`,
144+
"/home/src/workspaces/project/b.ts": `export const b = 10;const bLocal = 10;`,
145+
"/home/src/workspaces/project/c.ts": `import { a } from "./a";export const c = a;`,
146+
"/home/src/workspaces/project/d.ts": `import { b } from "./b";export const d = b;`,
147+
}
148+
}
149+
150+
func getBuildCommandLineEmitDeclarationOnlyMap(options []string) FileMap {
151+
compilerOptionsStr := strings.Join(core.Map(options, func(opt string) string {
152+
return fmt.Sprintf(`"%s": true`, opt)
153+
}), ", ")
154+
return FileMap{
155+
"/home/src/workspaces/solution/project1/src/tsconfig.json": stringtestutil.Dedent(fmt.Sprintf(`
156+
{
157+
"compilerOptions": { %s }
158+
}`, compilerOptionsStr)),
159+
"/home/src/workspaces/solution/project1/src/a.ts": `export const a = 10;const aLocal = 10;`,
160+
"/home/src/workspaces/solution/project1/src/b.ts": `export const b = 10;const bLocal = 10;`,
161+
"/home/src/workspaces/solution/project1/src/c.ts": `import { a } from "./a";export const c = a;`,
162+
"/home/src/workspaces/solution/project1/src/d.ts": `import { b } from "./b";export const d = b;`,
163+
"/home/src/workspaces/solution/project2/src/tsconfig.json": stringtestutil.Dedent(fmt.Sprintf(`
164+
{
165+
"compilerOptions": { %s },
166+
"references": [{ "path": "../../project1/src" }]
167+
}`, compilerOptionsStr)),
168+
"/home/src/workspaces/solution/project2/src/e.ts": `export const e = 10;`,
169+
"/home/src/workspaces/solution/project2/src/f.ts": `import { a } from "../../project1/src/a"; export const f = a;`,
170+
"/home/src/workspaces/solution/project2/src/g.ts": `import { b } from "../../project1/src/b"; export const g = b;`,
171+
}
172+
}
173+
174+
func getBuildCommandLineEmitDeclarationOnlyTestCases(options []string, suffix string) []*tscInput {
175+
return []*tscInput{
176+
{
177+
subScenario: "emitDeclarationOnly on commandline" + suffix,
178+
files: getBuildCommandLineEmitDeclarationOnlyMap(options),
179+
cwd: "/home/src/workspaces/solution",
180+
commandLineArgs: []string{"--b", "project2/src", "--verbose", "--emitDeclarationOnly"},
181+
edits: []*tscEdit{
182+
noChange,
183+
{
184+
caption: "local change",
185+
edit: func(sys *testSys) {
186+
sys.appendFile("/home/src/workspaces/solution/project1/src/a.ts", "const aa = 10;")
187+
},
188+
},
189+
{
190+
caption: "non local change",
191+
edit: func(sys *testSys) {
192+
sys.appendFile("/home/src/workspaces/solution/project1/src/a.ts", "export const aaa = 10;")
193+
},
194+
},
195+
{
196+
caption: "emit js files",
197+
commandLineArgs: []string{"--b", "project2/src", "--verbose"},
198+
},
199+
noChange,
200+
{
201+
caption: "js emit with change without emitDeclarationOnly",
202+
edit: func(sys *testSys) {
203+
sys.appendFile("/home/src/workspaces/solution/project1/src/b.ts", "const alocal = 10;")
204+
},
205+
commandLineArgs: []string{"--b", "project2/src", "--verbose"},
206+
},
207+
{
208+
caption: "local change",
209+
edit: func(sys *testSys) {
210+
sys.appendFile("/home/src/workspaces/solution/project1/src/b.ts", "const aaaa = 10;")
211+
},
212+
},
213+
{
214+
caption: "non local change",
215+
edit: func(sys *testSys) {
216+
sys.appendFile("/home/src/workspaces/solution/project1/src/b.ts", "export const aaaaa = 10;")
217+
},
218+
},
219+
{
220+
caption: "js emit with change without emitDeclarationOnly",
221+
edit: func(sys *testSys) {
222+
sys.appendFile("/home/src/workspaces/solution/project1/src/b.ts", "export const a2 = 10;")
223+
},
224+
commandLineArgs: []string{"--b", "project2/src", "--verbose"},
225+
},
226+
},
227+
},
228+
{
229+
subScenario: "emitDeclarationOnly false on commandline" + suffix,
230+
files: getBuildCommandLineEmitDeclarationOnlyMap(slices.Concat(options, []string{"emitDeclarationOnly"})),
231+
cwd: "/home/src/workspaces/solution",
232+
commandLineArgs: []string{"--b", "project2/src", "--verbose"},
233+
edits: []*tscEdit{
234+
noChange,
235+
{
236+
caption: "change",
237+
edit: func(sys *testSys) {
238+
sys.appendFile("/home/src/workspaces/solution/project1/src/a.ts", "const aa = 10;")
239+
},
240+
},
241+
{
242+
caption: "emit js files",
243+
commandLineArgs: []string{"--b", "project2/src", "--verbose", "--emitDeclarationOnly", "false"},
244+
},
245+
noChange,
246+
{
247+
caption: "no change run with js emit",
248+
commandLineArgs: []string{"--b", "project2/src", "--verbose", "--emitDeclarationOnly", "false"},
249+
},
250+
{
251+
caption: "js emit with change",
252+
edit: func(sys *testSys) {
253+
sys.appendFile("/home/src/workspaces/solution/project1/src/b.ts", "const blocal = 10;")
254+
},
255+
commandLineArgs: []string{"--b", "project2/src", "--verbose", "--emitDeclarationOnly", "false"},
256+
},
257+
},
258+
},
259+
}
260+
}

0 commit comments

Comments
 (0)