Skip to content

Commit 582d91c

Browse files
committed
tsc -b demo
1 parent ef56a32 commit 582d91c

File tree

4 files changed

+1575
-0
lines changed

4 files changed

+1575
-0
lines changed
Lines changed: 189 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,189 @@
1+
package execute_test
2+
3+
import (
4+
"testing"
5+
6+
"github.com/microsoft/typescript-go/internal/testutil/stringtestutil"
7+
)
8+
9+
func TestBuildDemoProject(t *testing.T) {
10+
t.Parallel()
11+
testCases := []*tscInput{
12+
{
13+
subScenario: "in master branch with everything setup correctly and reports no error",
14+
files: getBuildDemoFileMap(demoBranchMain),
15+
cwd: "/user/username/projects/demo",
16+
commandLineArgs: []string{"--b", "--verbose"},
17+
edits: noChangeOnlyEdit,
18+
},
19+
{
20+
subScenario: "in circular branch reports the error about it by stopping build",
21+
files: getBuildDemoFileMap(demoBranchCircularRef),
22+
cwd: "/user/username/projects/demo",
23+
commandLineArgs: []string{"--b", "--verbose"},
24+
},
25+
{
26+
// !!! sheetal - this has missing errors from strada about files not in rootDir (3) and value is declared but not used (1)
27+
subScenario: "in bad-ref branch reports the error about files not in rootDir at the import location",
28+
files: getBuildDemoFileMap(demoBranchBadRef),
29+
cwd: "/user/username/projects/demo",
30+
commandLineArgs: []string{"--b", "--verbose"},
31+
},
32+
}
33+
34+
for _, test := range testCases {
35+
test.run(t, "demo")
36+
}
37+
}
38+
39+
type demoBranch uint
40+
41+
const (
42+
demoBranchMain = iota
43+
demoBranchCircularRef
44+
demoBranchBadRef
45+
)
46+
47+
func getBuildDemoFileMap(demoType demoBranch) FileMap {
48+
files := FileMap{
49+
"/user/username/projects/demo/animals/animal.ts": stringtestutil.Dedent(`
50+
export type Size = "small" | "medium" | "large";
51+
export default interface Animal {
52+
size: Size;
53+
}
54+
`),
55+
"/user/username/projects/demo/animals/dog.ts": stringtestutil.Dedent(`
56+
import Animal from '.';
57+
import { makeRandomName } from '../core/utilities';
58+
59+
export interface Dog extends Animal {
60+
woof(): void;
61+
name: string;
62+
}
63+
64+
export function createDog(): Dog {
65+
return ({
66+
size: "medium",
67+
woof: function(this: Dog) {
68+
console.log(` + "`" + `${ this.name } says "Woof"!` + "`" + `);
69+
},
70+
name: makeRandomName()
71+
});
72+
}
73+
`),
74+
"/user/username/projects/demo/animals/index.ts": stringtestutil.Dedent(`
75+
import Animal from './animal';
76+
77+
export default Animal;
78+
import { createDog, Dog } from './dog';
79+
export { createDog, Dog };
80+
`),
81+
"/user/username/projects/demo/animals/tsconfig.json": stringtestutil.Dedent(`
82+
{
83+
"extends": "../tsconfig-base.json",
84+
"compilerOptions": {
85+
"outDir": "../lib/animals",
86+
"rootDir": "."
87+
},
88+
"references": [
89+
{ "path": "../core" }
90+
]
91+
}
92+
`),
93+
"/user/username/projects/demo/core/utilities.ts": stringtestutil.Dedent(`
94+
95+
export function makeRandomName() {
96+
return "Bob!?! ";
97+
}
98+
99+
export function lastElementOf<T>(arr: T[]): T | undefined {
100+
if (arr.length === 0) return undefined;
101+
return arr[arr.length - 1];
102+
}
103+
`),
104+
"/user/username/projects/demo/core/tsconfig.json": stringtestutil.Dedent(`
105+
{
106+
"extends": "../tsconfig-base.json",
107+
"compilerOptions": {
108+
"outDir": "../lib/core",
109+
"rootDir": "."
110+
},
111+
}
112+
`),
113+
"/user/username/projects/demo/zoo/zoo.ts": stringtestutil.Dedent(`
114+
import { Dog, createDog } from '../animals/index';
115+
116+
export function createZoo(): Array<Dog> {
117+
return [
118+
createDog()
119+
];
120+
}
121+
`),
122+
"/user/username/projects/demo/zoo/tsconfig.json": stringtestutil.Dedent(`
123+
{
124+
"extends": "../tsconfig-base.json",
125+
"compilerOptions": {
126+
"outDir": "../lib/zoo",
127+
"rootDir": "."
128+
},
129+
"references": [
130+
{
131+
"path": "../animals"
132+
}
133+
]
134+
}
135+
`),
136+
"/user/username/projects/demo/tsconfig-base.json": stringtestutil.Dedent(`
137+
{
138+
"compilerOptions": {
139+
"declaration": true,
140+
"target": "es5",
141+
"module": "commonjs",
142+
"strict": true,
143+
"noUnusedLocals": true,
144+
"noUnusedParameters": true,
145+
"noImplicitReturns": true,
146+
"noFallthroughCasesInSwitch": true,
147+
"composite": true,
148+
},
149+
}
150+
`),
151+
"/user/username/projects/demo/tsconfig.json": stringtestutil.Dedent(`
152+
{
153+
"files": [],
154+
"references": [
155+
{
156+
"path": "./core"
157+
},
158+
{
159+
"path": "./animals",
160+
},
161+
{
162+
"path": "./zoo",
163+
},
164+
],
165+
}
166+
`),
167+
}
168+
switch demoType {
169+
case demoBranchCircularRef:
170+
files["/user/username/projects/demo/core/tsconfig.json"] = stringtestutil.Dedent(`
171+
{
172+
"extends": "../tsconfig-base.json",
173+
"compilerOptions": {
174+
"outDir": "../lib/core",
175+
"rootDir": "."
176+
},
177+
"references": [
178+
{
179+
"path": "../zoo",
180+
}
181+
]
182+
}
183+
`)
184+
case demoBranchBadRef:
185+
files["/user/username/projects/demo/core/utilities.ts"] = `import * as A from '../animals'
186+
` + files["/user/username/projects/demo/core/utilities.ts"].(string)
187+
}
188+
return files
189+
}

0 commit comments

Comments
 (0)