Skip to content

Commit e97ee3c

Browse files
committed
More tests
1 parent 148c995 commit e97ee3c

5 files changed

+339
-0
lines changed

internal/execute/tscprojectreferences_test.go

Lines changed: 118 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,124 @@ func TestProjectReferences(t *testing.T) {
7474
}, "/home/src/workspaces/solution"),
7575
commandLineArgs: []string{"--p", "project"},
7676
},
77+
{
78+
// !!! sheetal verifyProjectReferences - checks this
79+
subScenario: "when project contains invalid project reference",
80+
sys: newTestSys(FileMap{
81+
"/home/src/workspaces/solution/project/index.ts": `export const x = 10;`,
82+
"/home/src/workspaces/solution/project/tsconfig.json": `{
83+
"references": [
84+
{ "path": "../utils" },
85+
],
86+
}`,
87+
}, "/home/src/workspaces/solution"),
88+
commandLineArgs: []string{"--p", "project"},
89+
},
90+
{
91+
subScenario: "default import interop uses referenced project settings",
92+
sys: newTestSys(FileMap{
93+
"/home/src/workspaces/project/node_modules/ambiguous-package/package.json": `{ "name": "ambiguous-package" }`,
94+
"/home/src/workspaces/project/node_modules/ambiguous-package/index.d.ts": "export declare const ambiguous: number;",
95+
"/home/src/workspaces/project/node_modules/esm-package/package.json": `{ "name": "esm-package", "type": "module" }`,
96+
"/home/src/workspaces/project/node_modules/esm-package/index.d.ts": "export declare const esm: number;",
97+
"/home/src/workspaces/project/lib/tsconfig.json": `{
98+
"compilerOptions": {
99+
"composite": true,
100+
"declaration": true,
101+
"rootDir": "src",
102+
"outDir": "dist",
103+
"module": "esnext",
104+
"moduleResolution": "bundler",
105+
},
106+
"include": ["src"],
107+
}`,
108+
"/home/src/workspaces/project/lib/src/a.ts": "export const a = 0;",
109+
"/home/src/workspaces/project/lib/dist/a.d.ts": "export declare const a = 0;",
110+
"/home/src/workspaces/project/app/tsconfig.json": `{
111+
"compilerOptions": {
112+
"module": "esnext",
113+
"moduleResolution": "bundler",
114+
"rootDir": "src",
115+
"outDir": "dist",
116+
},
117+
"include": ["src"],
118+
"references": [
119+
{ "path": "../lib" },
120+
],
121+
}`,
122+
"/home/src/workspaces/project/app/src/local.ts": "export const local = 0;",
123+
"/home/src/workspaces/project/app/src/index.ts": `
124+
import local from "./local"; // Error
125+
import esm from "esm-package"; // Error
126+
import referencedSource from "../../lib/src/a"; // Error
127+
import referencedDeclaration from "../../lib/dist/a"; // Error
128+
import ambiguous from "ambiguous-package"; // Ok`,
129+
}, "/home/src/workspaces/project"),
130+
commandLineArgs: []string{"--p", "app", "--pretty", "false"},
131+
},
132+
{
133+
subScenario: "referencing ambient const enum from referenced project with preserveConstEnums",
134+
sys: newTestSys(FileMap{
135+
"/home/src/workspaces/solution/utils/index.ts": "export const enum E { A = 1 }",
136+
"/home/src/workspaces/solution/utils/index.d.ts": "export declare const enum E { A = 1 }",
137+
"/home/src/workspaces/solution/utils/tsconfig.json": `{
138+
"compilerOptions": {
139+
"composite": true,
140+
"declaration": true,
141+
"preserveConstEnums": true,
142+
},
143+
}`,
144+
"/home/src/workspaces/solution/project/index.ts": `import { E } from "../utils"; E.A;`,
145+
"/home/src/workspaces/solution/project/tsconfig.json": `{
146+
"compilerOptions": {
147+
"isolatedModules": true,
148+
},
149+
"references": [
150+
{ "path": "../utils" },
151+
],
152+
}`,
153+
}, "/home/src/workspaces/solution"),
154+
commandLineArgs: []string{"--p", "project"},
155+
},
156+
{
157+
subScenario: "importing const enum from referenced project with preserveConstEnums and verbatimModuleSyntax",
158+
sys: newTestSys(FileMap{
159+
"/home/src/workspaces/solution/preserve/index.ts": "export const enum E { A = 1 }",
160+
"/home/src/workspaces/solution/preserve/index.d.ts": "export declare const enum E { A = 1 }",
161+
"/home/src/workspaces/solution/preserve/tsconfig.json": `{
162+
"compilerOptions": {
163+
"composite": true,
164+
"declaration": true,
165+
"preserveConstEnums": true,
166+
},
167+
}`,
168+
"/home/src/workspaces/solution/no-preserve/index.ts": "export const enum E { A = 1 }",
169+
"/home/src/workspaces/solution/no-preserve/index.d.ts": "export declare const enum F { A = 1 }",
170+
"/home/src/workspaces/solution/no-preserve/tsconfig.json": `{
171+
"compilerOptions": {
172+
"composite": true,
173+
"declaration": true,
174+
"preserveConstEnums": false,
175+
},
176+
}`,
177+
"/home/src/workspaces/solution/project/index.ts": `
178+
import { E } from "../preserve";
179+
import { F } from "../no-preserve";
180+
E.A;
181+
F.A;`,
182+
"/home/src/workspaces/solution/project/tsconfig.json": `{
183+
"compilerOptions": {
184+
"module": "preserve",
185+
"verbatimModuleSyntax": true,
186+
},
187+
"references": [
188+
{ "path": "../preserve" },
189+
{ "path": "../no-preserve" },
190+
],
191+
}`,
192+
}, "/home/src/workspaces/solution"),
193+
commandLineArgs: []string{"--p", "project", "--pretty", "false"},
194+
},
77195
}
78196

79197
for _, c := range cases {
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
2+
currentDirectory::/home/src/workspaces/project
3+
useCaseSensitiveFileNames::true
4+
Input::--p app --pretty false
5+
//// [/home/src/workspaces/project/app/src/index.ts] new file
6+
7+
import local from "./local"; // Error
8+
import esm from "esm-package"; // Error
9+
import referencedSource from "../../lib/src/a"; // Error
10+
import referencedDeclaration from "../../lib/dist/a"; // Error
11+
import ambiguous from "ambiguous-package"; // Ok
12+
//// [/home/src/workspaces/project/app/src/local.ts] new file
13+
export const local = 0;
14+
//// [/home/src/workspaces/project/app/tsconfig.json] new file
15+
{
16+
"compilerOptions": {
17+
"module": "esnext",
18+
"moduleResolution": "bundler",
19+
"rootDir": "src",
20+
"outDir": "dist",
21+
},
22+
"include": ["src"],
23+
"references": [
24+
{ "path": "../lib" },
25+
],
26+
}
27+
//// [/home/src/workspaces/project/lib/dist/a.d.ts] new file
28+
export declare const a = 0;
29+
//// [/home/src/workspaces/project/lib/src/a.ts] new file
30+
export const a = 0;
31+
//// [/home/src/workspaces/project/lib/tsconfig.json] new file
32+
{
33+
"compilerOptions": {
34+
"composite": true,
35+
"declaration": true,
36+
"rootDir": "src",
37+
"outDir": "dist",
38+
"module": "esnext",
39+
"moduleResolution": "bundler",
40+
},
41+
"include": ["src"],
42+
}
43+
//// [/home/src/workspaces/project/node_modules/ambiguous-package/index.d.ts] new file
44+
export declare const ambiguous: number;
45+
//// [/home/src/workspaces/project/node_modules/ambiguous-package/package.json] new file
46+
{ "name": "ambiguous-package" }
47+
//// [/home/src/workspaces/project/node_modules/esm-package/index.d.ts] new file
48+
export declare const esm: number;
49+
//// [/home/src/workspaces/project/node_modules/esm-package/package.json] new file
50+
{ "name": "esm-package", "type": "module" }
51+
52+
ExitStatus:: 2
53+
54+
CompilerOptions::{
55+
"project": "/home/src/workspaces/project/app",
56+
"pretty": false
57+
}
58+
Output::
59+
app/src/index.ts(2,13): error TS2613: Module '"/home/src/workspaces/project/app/src/local"' has no default export. Did you mean to use 'import { local } from "/home/src/workspaces/project/app/src/local"' instead?
60+
61+
app/src/index.ts(3,13): error TS2613: Module '"/home/src/workspaces/project/node_modules/esm-package/index"' has no default export. Did you mean to use 'import { esm } from "/home/src/workspaces/project/node_modules/esm-package/index"' instead?
62+
//// [/home/src/workspaces/project/app/dist/index.js] new file
63+
export {};
64+
65+
//// [/home/src/workspaces/project/app/dist/local.js] new file
66+
export const local = 0;
67+
68+
//// [/home/src/workspaces/project/app/src/index.ts] no change
69+
//// [/home/src/workspaces/project/app/src/local.ts] no change
70+
//// [/home/src/workspaces/project/app/tsconfig.json] no change
71+
//// [/home/src/workspaces/project/lib/dist/a.d.ts] no change
72+
//// [/home/src/workspaces/project/lib/src/a.ts] no change
73+
//// [/home/src/workspaces/project/lib/tsconfig.json] no change
74+
//// [/home/src/workspaces/project/node_modules/ambiguous-package/index.d.ts] no change
75+
//// [/home/src/workspaces/project/node_modules/ambiguous-package/package.json] no change
76+
//// [/home/src/workspaces/project/node_modules/esm-package/index.d.ts] no change
77+
//// [/home/src/workspaces/project/node_modules/esm-package/package.json] no change
78+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
2+
currentDirectory::/home/src/workspaces/solution
3+
useCaseSensitiveFileNames::true
4+
Input::--p project --pretty false
5+
//// [/home/src/workspaces/solution/no-preserve/index.d.ts] new file
6+
export declare const enum F { A = 1 }
7+
//// [/home/src/workspaces/solution/no-preserve/index.ts] new file
8+
export const enum E { A = 1 }
9+
//// [/home/src/workspaces/solution/no-preserve/tsconfig.json] new file
10+
{
11+
"compilerOptions": {
12+
"composite": true,
13+
"declaration": true,
14+
"preserveConstEnums": false,
15+
},
16+
}
17+
//// [/home/src/workspaces/solution/preserve/index.d.ts] new file
18+
export declare const enum E { A = 1 }
19+
//// [/home/src/workspaces/solution/preserve/index.ts] new file
20+
export const enum E { A = 1 }
21+
//// [/home/src/workspaces/solution/preserve/tsconfig.json] new file
22+
{
23+
"compilerOptions": {
24+
"composite": true,
25+
"declaration": true,
26+
"preserveConstEnums": true,
27+
},
28+
}
29+
//// [/home/src/workspaces/solution/project/index.ts] new file
30+
31+
import { E } from "../preserve";
32+
import { F } from "../no-preserve";
33+
E.A;
34+
F.A;
35+
//// [/home/src/workspaces/solution/project/tsconfig.json] new file
36+
{
37+
"compilerOptions": {
38+
"module": "preserve",
39+
"verbatimModuleSyntax": true,
40+
},
41+
"references": [
42+
{ "path": "../preserve" },
43+
{ "path": "../no-preserve" },
44+
],
45+
}
46+
47+
ExitStatus:: 2
48+
49+
CompilerOptions::{
50+
"project": "/home/src/workspaces/solution/project",
51+
"pretty": false
52+
}
53+
Output::
54+
project/index.ts(3,14): error TS2748: Cannot access ambient const enums when 'verbatimModuleSyntax' is enabled.
55+
//// [/home/src/workspaces/solution/no-preserve/index.d.ts] no change
56+
//// [/home/src/workspaces/solution/no-preserve/index.ts] no change
57+
//// [/home/src/workspaces/solution/no-preserve/tsconfig.json] no change
58+
//// [/home/src/workspaces/solution/preserve/index.d.ts] no change
59+
//// [/home/src/workspaces/solution/preserve/index.ts] no change
60+
//// [/home/src/workspaces/solution/preserve/tsconfig.json] no change
61+
//// [/home/src/workspaces/solution/project/index.js] new file
62+
import { E } from "../preserve";
63+
import { F } from "../no-preserve";
64+
E.A;
65+
F.A;
66+
67+
//// [/home/src/workspaces/solution/project/index.ts] no change
68+
//// [/home/src/workspaces/solution/project/tsconfig.json] no change
69+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
2+
currentDirectory::/home/src/workspaces/solution
3+
useCaseSensitiveFileNames::true
4+
Input::--p project
5+
//// [/home/src/workspaces/solution/project/index.ts] new file
6+
import { E } from "../utils"; E.A;
7+
//// [/home/src/workspaces/solution/project/tsconfig.json] new file
8+
{
9+
"compilerOptions": {
10+
"isolatedModules": true,
11+
},
12+
"references": [
13+
{ "path": "../utils" },
14+
],
15+
}
16+
//// [/home/src/workspaces/solution/utils/index.d.ts] new file
17+
export declare const enum E { A = 1 }
18+
//// [/home/src/workspaces/solution/utils/index.ts] new file
19+
export const enum E { A = 1 }
20+
//// [/home/src/workspaces/solution/utils/tsconfig.json] new file
21+
{
22+
"compilerOptions": {
23+
"composite": true,
24+
"declaration": true,
25+
"preserveConstEnums": true,
26+
},
27+
}
28+
29+
ExitStatus:: 0
30+
31+
CompilerOptions::{
32+
"project": "/home/src/workspaces/solution/project"
33+
}
34+
Output::
35+
//// [/home/src/workspaces/solution/project/index.js] new file
36+
"use strict";
37+
Object.defineProperty(exports, "__esModule", { value: true });
38+
const utils_1 = require("../utils");
39+
utils_1.E.A;
40+
41+
//// [/home/src/workspaces/solution/project/index.ts] no change
42+
//// [/home/src/workspaces/solution/project/tsconfig.json] no change
43+
//// [/home/src/workspaces/solution/utils/index.d.ts] no change
44+
//// [/home/src/workspaces/solution/utils/index.ts] no change
45+
//// [/home/src/workspaces/solution/utils/tsconfig.json] no change
46+
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
2+
currentDirectory::/home/src/workspaces/solution
3+
useCaseSensitiveFileNames::true
4+
Input::--p project
5+
//// [/home/src/workspaces/solution/project/index.ts] new file
6+
export const x = 10;
7+
//// [/home/src/workspaces/solution/project/tsconfig.json] new file
8+
{
9+
"references": [
10+
{ "path": "../utils" },
11+
],
12+
}
13+
14+
ExitStatus:: 0
15+
16+
CompilerOptions::{
17+
"project": "/home/src/workspaces/solution/project"
18+
}
19+
Output::
20+
//// [/home/src/workspaces/solution/project/index.js] new file
21+
"use strict";
22+
Object.defineProperty(exports, "__esModule", { value: true });
23+
exports.x = void 0;
24+
exports.x = 10;
25+
26+
//// [/home/src/workspaces/solution/project/index.ts] no change
27+
//// [/home/src/workspaces/solution/project/tsconfig.json] no change
28+

0 commit comments

Comments
 (0)