Skip to content

Commit 6769625

Browse files
committed
tests part1
1 parent 896aec3 commit 6769625

File tree

64 files changed

+21058
-181
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

64 files changed

+21058
-181
lines changed

internal/execute/tsc_test.go

Lines changed: 172 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -137,95 +137,202 @@ func TestTscCommandline(t *testing.T) {
137137
}
138138
}
139139

140-
func TestNoEmit(t *testing.T) {
140+
func TestTscComposite(t *testing.T) {
141141
t.Parallel()
142-
(&tscInput{
143-
subScenario: "when project has strict true",
144-
files: FileMap{
145-
"/home/src/workspaces/project/tsconfig.json": stringtestutil.Dedent(`
146-
{
147-
"compilerOptions": {
148-
"incremental": true,
149-
"strict": true
150-
}
151-
}`),
152-
"/home/src/workspaces/project/class1.ts": `export class class1 {}`,
142+
testCases := []*tscInput{
143+
{
144+
subScenario: "when setting composite false on command line",
145+
files: FileMap{
146+
"/home/src/workspaces/project/src/main.ts": "export const x = 10;",
147+
"/home/src/workspaces/project/tsconfig.json": stringtestutil.Dedent(`
148+
{
149+
"compilerOptions": {
150+
"target": "es5",
151+
"module": "commonjs",
152+
"composite": true,
153+
},
154+
"include": [
155+
"src/**/*.ts",
156+
],
157+
}`),
158+
},
159+
commandLineArgs: []string{"--composite", "false"},
153160
},
154-
commandLineArgs: []string{"--noEmit"},
155-
}).run(t, "noEmit")
156-
}
157-
158-
func TestExtends(t *testing.T) {
159-
t.Parallel()
160-
extendsSysScenario := func(subScenario string, commandlineArgs []string) *tscInput {
161-
return &tscInput{
162-
subScenario: subScenario,
163-
commandLineArgs: commandlineArgs,
161+
{
162+
// !!! sheetal null is not reflected in final options
163+
subScenario: "when setting composite null on command line",
164164
files: FileMap{
165-
"/home/src/projects/configs/first/tsconfig.json": stringtestutil.Dedent(`
165+
"/home/src/workspaces/project/src/main.ts": "export const x = 10;",
166+
"/home/src/workspaces/project/tsconfig.json": stringtestutil.Dedent(`
166167
{
167-
"extends": "../second/tsconfig.json",
168-
"include": ["${configDir}/src"],
169168
"compilerOptions": {
170-
"typeRoots": ["root1", "${configDir}/root2", "root3"],
171-
"types": [],
172-
}
169+
"target": "es5",
170+
"module": "commonjs",
171+
"composite": true,
172+
},
173+
"include": [
174+
"src/**/*.ts",
175+
],
173176
}`),
174-
"/home/src/projects/configs/second/tsconfig.json": stringtestutil.Dedent(`
177+
},
178+
commandLineArgs: []string{"--composite", "null"},
179+
},
180+
{
181+
subScenario: "when setting composite false on command line but has tsbuild info in config",
182+
files: FileMap{
183+
"/home/src/workspaces/project/src/main.ts": "export const x = 10;",
184+
"/home/src/workspaces/project/tsconfig.json": stringtestutil.Dedent(`
175185
{
176-
"files": ["${configDir}/main.ts"],
177186
"compilerOptions": {
178-
"declarationDir": "${configDir}/decls",
179-
"paths": {
180-
"@myscope/*": ["${configDir}/types/*"],
181-
"other/*": ["other/*"],
182-
},
183-
"baseUrl": "${configDir}",
187+
"target": "es5",
188+
"module": "commonjs",
189+
"composite": true,
190+
"tsBuildInfoFile": "tsconfig.json.tsbuildinfo",
184191
},
185-
"watchOptions": {
186-
"excludeFiles": ["${configDir}/main.ts"],
192+
"include": [
193+
"src/**/*.ts",
194+
],
195+
}`),
196+
},
197+
commandLineArgs: []string{"--composite", "false"},
198+
},
199+
{
200+
subScenario: "when setting composite false on command line but has tsbuild info in config",
201+
files: FileMap{
202+
"/home/src/workspaces/project/src/main.ts": "export const x = 10;",
203+
"/home/src/workspaces/project/tsconfig.json": stringtestutil.Dedent(`
204+
{
205+
"compilerOptions": {
206+
"target": "es5",
207+
"module": "commonjs",
208+
"composite": true,
209+
"tsBuildInfoFile": "tsconfig.json.tsbuildinfo",
187210
},
211+
"include": [
212+
"src/**/*.ts",
213+
],
188214
}`),
189-
"/home/src/projects/myproject/tsconfig.json": stringtestutil.Dedent(`
215+
},
216+
commandLineArgs: []string{"--composite", "false"},
217+
},
218+
{
219+
subScenario: "when setting composite false and tsbuildinfo as null on command line but has tsbuild info in config",
220+
files: FileMap{
221+
"/home/src/workspaces/project/src/main.ts": "export const x = 10;",
222+
"/home/src/workspaces/project/tsconfig.json": stringtestutil.Dedent(`
190223
{
191-
"extends": "../configs/first/tsconfig.json",
192224
"compilerOptions": {
193-
"declaration": true,
194-
"outDir": "outDir",
195-
"traceResolution": true,
225+
"target": "es5",
226+
"module": "commonjs",
227+
"composite": true,
228+
"tsBuildInfoFile": "tsconfig.json.tsbuildinfo",
196229
},
230+
"include": [
231+
"src/**/*.ts",
232+
],
197233
}`),
198-
"/home/src/projects/myproject/main.ts": stringtestutil.Dedent(`
199-
// some comment
200-
export const y = 10;
201-
import { x } from "@myscope/sometype";
234+
},
235+
commandLineArgs: []string{"--composite", "false", "--tsBuildInfoFile", "null"},
236+
},
237+
{
238+
subScenario: "converting to modules",
239+
files: FileMap{
240+
"/home/src/workspaces/project/src/main.ts": "const x = 10;",
241+
"/home/src/workspaces/project/tsconfig.json": stringtestutil.Dedent(`
242+
{
243+
"compilerOptions": {
244+
"module": "none",
245+
"composite": true,
246+
},
247+
}`),
248+
},
249+
edits: []*tscEdit{
250+
{
251+
caption: "convert to modules",
252+
edit: func(sys *testSys) {
253+
sys.replaceFileText("/home/src/workspaces/project/tsconfig.json", "none", "es2015")
254+
},
255+
},
256+
},
257+
},
258+
{
259+
subScenario: "synthetic jsx import of ESM module from CJS module no crash no jsx element",
260+
files: FileMap{
261+
"/home/src/projects/project/src/main.ts": "export default 42;",
262+
"/home/src/projects/project/tsconfig.json": stringtestutil.Dedent(`
263+
{
264+
"compilerOptions": {
265+
"composite": true,
266+
"module": "Node16",
267+
"jsx": "react-jsx",
268+
"jsxImportSource": "solid-js",
269+
},
270+
}`),
271+
"/home/src/projects/project/node_modules/solid-js/package.json": stringtestutil.Dedent(`
272+
{
273+
"name": "solid-js",
274+
"type": "module",
275+
}
202276
`),
203-
"/home/src/projects/myproject/src/secondary.ts": stringtestutil.Dedent(`
204-
// some comment
205-
export const z = 10;
206-
import { k } from "other/sometype2";
277+
// !!! sheetal this was esm in strada but commonjs here
278+
"/home/src/projects/project/node_modules/solid-js/jsx-runtime.d.ts": stringtestutil.Dedent(`
279+
export namespace JSX {
280+
type IntrinsicElements = { div: {}; };
281+
}
207282
`),
208-
"/home/src/projects/myproject/types/sometype.ts": stringtestutil.Dedent(`
209-
// some comment
210-
export const x = 10;
283+
},
284+
cwd: "/home/src/projects/project",
285+
},
286+
{
287+
subScenario: "synthetic jsx import of ESM module from CJS module error on jsx element",
288+
files: FileMap{
289+
"/home/src/projects/project/src/main.tsx": "export default <div/>;",
290+
"/home/src/projects/project/tsconfig.json": stringtestutil.Dedent(`
291+
{
292+
"compilerOptions": {
293+
"composite": true,
294+
"module": "Node16",
295+
"jsx": "react-jsx",
296+
"jsxImportSource": "solid-js",
297+
},
298+
}`),
299+
"/home/src/projects/project/node_modules/solid-js/package.json": stringtestutil.Dedent(`
300+
{
301+
"name": "solid-js",
302+
"type": "module",
303+
}
211304
`),
212-
"/home/src/projects/myproject/root2/other/sometype2/index.d.ts": stringtestutil.Dedent(`
213-
export const k = 10;
305+
"/home/src/projects/project/node_modules/solid-js/jsx-runtime.d.ts": stringtestutil.Dedent(`
306+
export namespace JSX {
307+
type IntrinsicElements = { div: {}; };
308+
}
214309
`),
215310
},
216-
cwd: "/home/src/projects/myproject",
217-
}
311+
cwd: "/home/src/projects/project",
312+
},
218313
}
219314

220-
cases := []*tscInput{
221-
extendsSysScenario("configDir template", []string{"--explainFiles"}),
222-
extendsSysScenario("configDir template showConfig", []string{"--showConfig"}),
223-
extendsSysScenario("configDir template with commandline", []string{"--explainFiles", "--outDir", "${configDir}/outDir"}),
315+
for _, testCase := range testCases {
316+
testCase.run(t, "composite")
224317
}
318+
}
225319

226-
for _, c := range cases {
227-
c.run(t, "extends")
228-
}
320+
func TestNoEmit(t *testing.T) {
321+
t.Parallel()
322+
(&tscInput{
323+
subScenario: "when project has strict true",
324+
files: FileMap{
325+
"/home/src/workspaces/project/tsconfig.json": stringtestutil.Dedent(`
326+
{
327+
"compilerOptions": {
328+
"incremental": true,
329+
"strict": true
330+
}
331+
}`),
332+
"/home/src/workspaces/project/class1.ts": `export class class1 {}`,
333+
},
334+
commandLineArgs: []string{"--noEmit"},
335+
}).run(t, "noEmit")
229336
}
230337

231338
func TestTypeAcquisition(t *testing.T) {

0 commit comments

Comments
 (0)