Skip to content

Commit 263d4f8

Browse files
committed
tsc noEmitOnError
1 parent 5b885d5 commit 263d4f8

27 files changed

+6652
-0
lines changed
Lines changed: 191 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,191 @@
1+
package execute_test
2+
3+
import (
4+
"fmt"
5+
"slices"
6+
"testing"
7+
8+
"github.com/microsoft/typescript-go/internal/testutil/stringtestutil"
9+
)
10+
11+
type tscNoEmitOnErrorScenario struct {
12+
subScenario string
13+
mainErrorContent string
14+
fixedErrorContent string
15+
}
16+
17+
func TestTscNoEmitOnError(t *testing.T) {
18+
t.Parallel()
19+
scenarios := []*tscNoEmitOnErrorScenario{
20+
{
21+
subScenario: "syntax errors",
22+
mainErrorContent: stringtestutil.Dedent(`
23+
import { A } from "../shared/types/db";
24+
const a = {
25+
lastName: 'sdsd'
26+
;
27+
`),
28+
fixedErrorContent: stringtestutil.Dedent(`
29+
import { A } from "../shared/types/db";
30+
const a = {
31+
lastName: 'sdsd'
32+
};`),
33+
},
34+
{
35+
subScenario: "semantic errors",
36+
mainErrorContent: stringtestutil.Dedent(`
37+
import { A } from "../shared/types/db";
38+
const a: string = 10;`),
39+
fixedErrorContent: stringtestutil.Dedent(`
40+
import { A } from "../shared/types/db";
41+
const a: string = "hello";`),
42+
},
43+
{
44+
subScenario: "dts errors",
45+
mainErrorContent: stringtestutil.Dedent(`
46+
import { A } from "../shared/types/db";
47+
export const a = class { private p = 10; };
48+
`),
49+
fixedErrorContent: stringtestutil.Dedent(`
50+
import { A } from "../shared/types/db";
51+
export const a = class { p = 10; };
52+
`),
53+
},
54+
}
55+
testCases := slices.Concat(
56+
getTscNoEmitOnErrorTestCases(scenarios, []string{}),
57+
getTscNoEmitOnErrorTestCases(scenarios, []string{"-b", "-v"}),
58+
[]*tscInput{
59+
{
60+
subScenario: `when declarationMap changes`,
61+
files: FileMap{
62+
"/home/src/workspaces/project/tsconfig.json": stringtestutil.Dedent(`
63+
{
64+
"compilerOptions": {
65+
"noEmitOnError": true,
66+
"declaration": true,
67+
"composite": true,
68+
},
69+
}`),
70+
"/home/src/workspaces/project/a.ts": "const x = 10;",
71+
"/home/src/workspaces/project/b.ts": "const y = 10;",
72+
},
73+
edits: []*tscEdit{
74+
{
75+
caption: "error and enable declarationMap",
76+
edit: func(sys *testSys) {
77+
sys.replaceFileText("/home/src/workspaces/project/a.ts", "x", "x: 20")
78+
},
79+
commandLineArgs: []string{"--declarationMap"},
80+
},
81+
{
82+
caption: "fix error declarationMap",
83+
edit: func(sys *testSys) {
84+
sys.replaceFileText("/home/src/workspaces/project/a.ts", "x: 20", "x")
85+
},
86+
commandLineArgs: []string{"--declarationMap"},
87+
},
88+
},
89+
},
90+
{
91+
subScenario: "file deleted before fixing error with noEmitOnError",
92+
files: FileMap{
93+
"/home/src/workspaces/project/tsconfig.json": stringtestutil.Dedent(`
94+
{
95+
"compilerOptions": {
96+
"outDir": "outDir",
97+
"noEmitOnError": true,
98+
},
99+
}`),
100+
"/home/src/workspaces/project/file1.ts": `export const x: 30 = "hello";`,
101+
"/home/src/workspaces/project/file2.ts": `export class D { }`,
102+
},
103+
commandLineArgs: []string{"-i"},
104+
edits: []*tscEdit{
105+
{
106+
caption: "delete file without error",
107+
edit: func(sys *testSys) {
108+
sys.removeNoError("/home/src/workspaces/project/file2.ts")
109+
},
110+
},
111+
},
112+
},
113+
},
114+
)
115+
116+
for _, test := range testCases {
117+
test.run(t, "noEmitOnError")
118+
}
119+
}
120+
121+
func getTscNoEmitOnErrorFileMap(scenario *tscNoEmitOnErrorScenario, declaration bool, incremental bool) FileMap {
122+
return FileMap{
123+
"/user/username/projects/noEmitOnError/tsconfig.json": stringtestutil.Dedent(fmt.Sprintf(`
124+
{
125+
"compilerOptions": {
126+
"outDir": "./dev-build",
127+
"declaration": %t,
128+
"incremental": %t,
129+
"noEmitOnError": true,
130+
},
131+
}`, declaration, incremental)),
132+
"/user/username/projects/noEmitOnError/shared/types/db.ts": stringtestutil.Dedent(`
133+
export interface A {
134+
name: string;
135+
}
136+
`),
137+
"/user/username/projects/noEmitOnError/src/main.ts": scenario.mainErrorContent,
138+
"/user/username/projects/noEmitOnError/src/other.ts": stringtestutil.Dedent(`
139+
console.log("hi");
140+
export { }
141+
`),
142+
}
143+
}
144+
145+
func getTscNoEmitOnErrorTestCases(scenarios []*tscNoEmitOnErrorScenario, commandLineArgs []string) []*tscInput {
146+
testCases := make([]*tscInput, 0, len(scenarios)*4)
147+
for _, scenario := range scenarios {
148+
edits := []*tscEdit{
149+
noChange,
150+
{
151+
caption: "Fix error",
152+
edit: func(sys *testSys) {
153+
sys.writeFileNoError("/user/username/projects/noEmitOnError/src/main.ts", scenario.fixedErrorContent, false)
154+
},
155+
},
156+
noChange,
157+
}
158+
testCases = append(
159+
testCases,
160+
&tscInput{
161+
subScenario: scenario.subScenario,
162+
files: getTscNoEmitOnErrorFileMap(scenario, false, false),
163+
cwd: "/user/username/projects/noEmitOnError",
164+
commandLineArgs: commandLineArgs,
165+
edits: edits,
166+
},
167+
&tscInput{
168+
subScenario: scenario.subScenario + " with declaration",
169+
files: getTscNoEmitOnErrorFileMap(scenario, true, false),
170+
cwd: "/user/username/projects/noEmitOnError",
171+
commandLineArgs: commandLineArgs,
172+
edits: edits,
173+
},
174+
&tscInput{
175+
subScenario: scenario.subScenario + " with incremental",
176+
files: getTscNoEmitOnErrorFileMap(scenario, false, true),
177+
cwd: "/user/username/projects/noEmitOnError",
178+
commandLineArgs: commandLineArgs,
179+
edits: edits,
180+
},
181+
&tscInput{
182+
subScenario: scenario.subScenario + " with declaration with incremental",
183+
files: getTscNoEmitOnErrorFileMap(scenario, true, true),
184+
cwd: "/user/username/projects/noEmitOnError",
185+
commandLineArgs: commandLineArgs,
186+
edits: edits,
187+
},
188+
)
189+
}
190+
return testCases
191+
}

0 commit comments

Comments
 (0)