@@ -2,6 +2,8 @@ package execute_test
2
2
3
3
import (
4
4
"testing"
5
+
6
+ "github.com/microsoft/typescript-go/internal/testutil/stringtestutil"
5
7
)
6
8
7
9
func TestTscCommandline (t * testing.T ) {
@@ -60,32 +62,56 @@ func TestTscCommandline(t *testing.T) {
60
62
{
61
63
subScenario : "Project is empty string" ,
62
64
sys : newTestSys (FileMap {
63
- "/home/src/workspaces/project/first.ts" : `export const a = 1` ,
64
- "/home/src/workspaces/project/tsconfig.json" : `{ "compilerOptions": { "strict": true, "noEmit": true } }` ,
65
+ "/home/src/workspaces/project/first.ts" : `export const a = 1` ,
66
+ "/home/src/workspaces/project/tsconfig.json" : stringtestutil .Dedent (`
67
+ {
68
+ "compilerOptions": {
69
+ "strict": true,
70
+ "noEmit": true
71
+ }
72
+ }` ),
65
73
}, "" ),
66
74
commandLineArgs : []string {},
67
75
},
68
76
{
69
77
subScenario : "Parse -p" ,
70
78
sys : newTestSys (FileMap {
71
- "/home/src/workspaces/project/first.ts" : `export const a = 1` ,
72
- "/home/src/workspaces/project/tsconfig.json" : `{ "compilerOptions": { "strict": true, "noEmit": true } }` ,
79
+ "/home/src/workspaces/project/first.ts" : `export const a = 1` ,
80
+ "/home/src/workspaces/project/tsconfig.json" : stringtestutil .Dedent (`
81
+ {
82
+ "compilerOptions": {
83
+ "strict": true,
84
+ "noEmit": true
85
+ }
86
+ }` ),
73
87
}, "" ),
74
88
commandLineArgs : []string {"-p" , "." },
75
89
},
76
90
{
77
91
subScenario : "Parse -p with path to tsconfig file" ,
78
92
sys : newTestSys (FileMap {
79
- "/home/src/workspaces/project/first.ts" : `export const a = 1` ,
80
- "/home/src/workspaces/project/tsconfig.json" : `{ "compilerOptions": { "strict": true, "noEmit": true } }` ,
93
+ "/home/src/workspaces/project/first.ts" : `export const a = 1` ,
94
+ "/home/src/workspaces/project/tsconfig.json" : stringtestutil .Dedent (`
95
+ {
96
+ "compilerOptions": {
97
+ "strict": true,
98
+ "noEmit": true
99
+ }
100
+ }` ),
81
101
}, "" ),
82
102
commandLineArgs : []string {"-p" , "/home/src/workspaces/project/tsconfig.json" },
83
103
},
84
104
{
85
105
subScenario : "Parse -p with path to tsconfig folder" ,
86
106
sys : newTestSys (FileMap {
87
- "/home/src/workspaces/project/first.ts" : `export const a = 1` ,
88
- "/home/src/workspaces/project/tsconfig.json" : `{ "compilerOptions": { "strict": true, "noEmit": true } }` ,
107
+ "/home/src/workspaces/project/first.ts" : `export const a = 1` ,
108
+ "/home/src/workspaces/project/tsconfig.json" : stringtestutil .Dedent (`
109
+ {
110
+ "compilerOptions": {
111
+ "strict": true,
112
+ "noEmit": true
113
+ }
114
+ }` ),
89
115
}, "" ),
90
116
commandLineArgs : []string {"-p" , "/home/src/workspaces/project" },
91
117
},
@@ -97,8 +123,14 @@ func TestTscCommandline(t *testing.T) {
97
123
{
98
124
subScenario : "Parse watch interval option" ,
99
125
sys : newTestSys (FileMap {
100
- "/home/src/workspaces/project/first.ts" : `export const a = 1` ,
101
- "/home/src/workspaces/project/tsconfig.json" : `{ "compilerOptions": { "strict": true, "noEmit": true } }` ,
126
+ "/home/src/workspaces/project/first.ts" : `export const a = 1` ,
127
+ "/home/src/workspaces/project/tsconfig.json" : stringtestutil .Dedent (`
128
+ {
129
+ "compilerOptions": {
130
+ "strict": true,
131
+ "noEmit": true
132
+ }
133
+ }` ),
102
134
}, "" ),
103
135
commandLineArgs : []string {"-w" , "--watchInterval" , "1000" },
104
136
},
@@ -119,12 +151,13 @@ func TestNoEmit(t *testing.T) {
119
151
(& tscInput {
120
152
subScenario : "when project has strict true" ,
121
153
sys : newTestSys (FileMap {
122
- "/home/src/workspaces/project/tsconfig.json" : `{
123
- "compilerOptions": {
124
- "incremental": true,
125
- "strict": true,
126
- },
127
- }` ,
154
+ "/home/src/workspaces/project/tsconfig.json" : stringtestutil .Dedent (`
155
+ {
156
+ "compilerOptions": {
157
+ "incremental": true,
158
+ "strict": true
159
+ }
160
+ }` ),
128
161
"/home/src/workspaces/project/class1.ts" : `export class class1 {}` ,
129
162
}, "" ),
130
163
commandLineArgs : []string {"--noEmit" },
@@ -133,67 +166,72 @@ func TestNoEmit(t *testing.T) {
133
166
134
167
func TestExtends (t * testing.T ) {
135
168
t .Parallel ()
136
- extendsSysFiles := FileMap {
137
- "/home/src/projects/configs/first/tsconfig.json" : `{
138
- "extends": "../second/tsconfig.json",
139
- "include": ["${configDir}/src"],
140
- "compilerOptions": {
141
- "typeRoots": ["root1", "${configDir}/root2", "root3"],
142
- "types": [],
143
- },
144
- }` ,
145
- "/home/src/projects/configs/second/tsconfig.json" : `{
146
- "files": ["${configDir}/main.ts"],
147
- "compilerOptions": {
148
- "declarationDir": "${configDir}/decls",
149
- "paths": {
150
- "@myscope/*": ["${configDir}/types/*"],
151
- "other/*": ["other/*"],
152
- },
153
- "baseUrl": "${configDir}",
154
- },
155
- "watchOptions": {
156
- "excludeFiles": ["${configDir}/main.ts"],
157
- },
158
- }` ,
159
- "/home/src/projects/myproject/tsconfig.json" : `{
160
- "extends": "../configs/first/tsconfig.json",
161
- "compilerOptions": {
162
- "declaration": true,
163
- "outDir": "outDir",
164
- "traceResolution": true,
165
- },
166
- }` ,
167
-
168
- "/home/src/projects/myproject/main.ts" : `
169
- // some comment
170
- export const y = 10;
171
- import { x } from "@myscope/sometype";
172
- ` ,
173
- "/home/src/projects/myproject/src/secondary.ts" : `
174
- // some comment
175
- export const z = 10;
176
- import { k } from "other/sometype2";
177
- ` ,
178
- "/home/src/projects/myproject/types/sometype.ts" : `
179
- export const x = 10;
180
- ` ,
181
- "/home/src/projects/myproject/root2/other/sometype2/index.d.ts" : `
182
- export const k = 10;
183
- ` ,
169
+ extendsSys := func () * testSys {
170
+ return newTestSys (FileMap {
171
+ "/home/src/projects/configs/first/tsconfig.json" : stringtestutil .Dedent (`
172
+ {
173
+ "extends": "../second/tsconfig.json",
174
+ "include": ["${configDir}/src"],
175
+ "compilerOptions": {
176
+ "typeRoots": ["root1", "${configDir}/root2", "root3"],
177
+ "types": [],
178
+ }
179
+ }` ),
180
+ "/home/src/projects/configs/second/tsconfig.json" : stringtestutil .Dedent (`
181
+ {
182
+ "files": ["${configDir}/main.ts"],
183
+ "compilerOptions": {
184
+ "declarationDir": "${configDir}/decls",
185
+ "paths": {
186
+ "@myscope/*": ["${configDir}/types/*"],
187
+ "other/*": ["other/*"],
188
+ },
189
+ "baseUrl": "${configDir}",
190
+ },
191
+ "watchOptions": {
192
+ "excludeFiles": ["${configDir}/main.ts"],
193
+ },
194
+ }` ),
195
+ "/home/src/projects/myproject/tsconfig.json" : stringtestutil .Dedent (`
196
+ {
197
+ "extends": "../configs/first/tsconfig.json",
198
+ "compilerOptions": {
199
+ "declaration": true,
200
+ "outDir": "outDir",
201
+ "traceResolution": true,
202
+ },
203
+ }` ),
204
+ "/home/src/projects/myproject/main.ts" : stringtestutil .Dedent (`
205
+ // some comment
206
+ export const y = 10;
207
+ import { x } from "@myscope/sometype";
208
+ ` ),
209
+ "/home/src/projects/myproject/src/secondary.ts" : stringtestutil .Dedent (`
210
+ // some comment
211
+ export const z = 10;
212
+ import { k } from "other/sometype2";
213
+ ` ),
214
+ "/home/src/projects/myproject/types/sometype.ts" : stringtestutil .Dedent (`
215
+ // some comment
216
+ export const x = 10;
217
+ ` ),
218
+ "/home/src/projects/myproject/root2/other/sometype2/index.d.ts" : stringtestutil .Dedent (`
219
+ export const k = 10;
220
+ ` ),
221
+ }, "/home/src/projects/myproject" )
184
222
}
185
223
186
224
cases := []tscInput {{
187
225
subScenario : "configDir template" ,
188
- sys : newTestSys ( extendsSysFiles , "/home/src/projects/myproject" ),
226
+ sys : extendsSys ( ),
189
227
commandLineArgs : []string {"--explainFiles" },
190
228
}, {
191
229
subScenario : "configDir template showConfig" ,
192
- sys : newTestSys ( extendsSysFiles , "/home/src/projects/myproject" ),
230
+ sys : extendsSys ( ),
193
231
commandLineArgs : []string {"--showConfig" },
194
232
}, {
195
233
subScenario : "configDir template with commandline" ,
196
- sys : newTestSys ( extendsSysFiles , "/home/src/projects/myproject" ),
234
+ sys : extendsSys ( ),
197
235
commandLineArgs : []string {"--explainFiles" , "--outDir" , "${configDir}/outDir" },
198
236
}}
199
237
@@ -206,20 +244,19 @@ func TestTypeAcquisition(t *testing.T) {
206
244
t .Parallel ()
207
245
(& tscInput {
208
246
subScenario : "parse tsconfig with typeAcquisition" ,
209
- sys : newTestSys (FileMap {"/home/src/workspaces/project/tsconfig.json" : `{
210
- "compilerOptions": {
211
- "composite": true,
212
- "noEmit": true,
213
- },
214
- "typeAcquisition": {
215
- "enable": true,
216
- "include": ["0.d.ts", "1.d.ts"],
217
- "exclude": ["0.js", "1.js"],
218
- "disableFilenameBasedTypeAcquisition": true,
219
- },
220
- }` },
221
- "/home/src/workspaces/project" ,
222
- ),
247
+ sys : newTestSys (FileMap {"/home/src/workspaces/project/tsconfig.json" : stringtestutil .Dedent (`
248
+ {
249
+ "compilerOptions": {
250
+ "composite": true,
251
+ "noEmit": true,
252
+ },
253
+ "typeAcquisition": {
254
+ "enable": true,
255
+ "include": ["0.d.ts", "1.d.ts"],
256
+ "exclude": ["0.js", "1.js"],
257
+ "disableFilenameBasedTypeAcquisition": true,
258
+ },
259
+ }` )}, "/home/src/workspaces/project" ),
223
260
commandLineArgs : []string {},
224
261
}).run (t , "typeAcquisition" )
225
262
}
0 commit comments